Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #4450
Closed
Open
Issue created Nov 11, 2019 by Administrator@rootContributor0 of 6 checklist items completed0/6 checklist items

[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,

swagger.zip

[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.

Assignee
Assign to
Time tracking