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
  • #5442
Closed
Open
Issue created Feb 25, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG] [csharp-netcore] Invalid expressions are generated using ??

Created by: vaindil

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

The csharp-netcore generator generates invalid C# if an enum is set as required in a definition. With the enum property name present in the "required" object inside the definition of ObjectCreateArgs, the C# below is generated as a constructor for ObjectCreateArgs:

public ObjectCreateArgs(ObjectType objectType = default(ObjectType))
{
    // to ensure "objectType" is required (not null)
    this.ObjectType = objectType ?? throw new ArgumentNullException("snip");;
}

This is invalid C# because objectType is not nullable, therefore the null coalescing operator can't be used with it.

openapi-generator version

4.2.3

OpenAPI declaration file content or url

Click here (rename extension to .json)

Command line used for generation
java -jar openapi-generator-cli.jar generate -i swagger.json -g csharp-netcore -o test-csharp
Steps to reproduce

Run the above command.

Suggest a fix

Enums are not nullable unless declared with ? like other types, so they should be treated as such.

Assignee
Assign to
Time tracking