[BUG] ELM: C# 8 nullable feature creates uncompilable (Maybe OneOf<PContactInfo>)
Created by: mattiasw2
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? No, it is the complete swagger.json -
Have you validated the input using an OpenAPI validator (example)? Yes -
What's the version of OpenAPI Generator used? 4.2.0 -
Have you search for related issues/PRs? Yes. -
What's the actual output vs expected output? -
[Optional] Bounty to sponsor the fix (example)
Description
As of C# 8, nullable references types have an anotation '?', and unless it is there, the reference cannot be null.
https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/nullable-reference-types
I have a plain DTO like this,
public class AccResponse
{
// ReSharper disable once NotNullMemberIsNotInitialized
[NotNull] [Required] public BaseResponse Common { get; set; } = new BaseResponse();
// public string Id { get; set; }
[Required] public string Name { get; set; } = "";
public bool AllowGuest { get; set; }
public PContactInfo? TechContactInfo { get; set; }
public PContactInfo? AdminContactInfo { get; set; }
public bool Blocked { get; set; }
public bool Disabled { get; set; }
public int MaximumAllowedNamedUsers { get; set; }
public string? CreateUserEmailMessage { get; set; }
public string? CreateUserEmailMessageSubject { get; set; }
}
and the problem is
public PContactInfo? TechContactInfo { get; set; }
It is actually exactly the same as
public PContactInfo TechContactInfo { get; set; }
in C# 7 and earlier, i.e. since there is no [Required], that field can be null.
openapi-generator version
4.2.0
OpenAPI declaration file content or url
Command line used for generation
java -jar openapi-generator-cli-4.2.0.jar generate -g elm -i swagger.json -o src/Swagger/
Steps to reproduce
Just generate and look at the code. There is a warning for another problem,
[main] INFO o.o.codegen.DefaultGenerator - Model ExcelFormattingBase not generated since it's a free-form object
but you can ignore that. I can simplify those objects.
Suggest a fix
Just make it be treated as if neither ? or [Required] is not there.