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
  • #4343
Closed
Open
Issue created Oct 31, 2019 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG] [csharp-netcore] Generating invalid null default values for enum parameters in API

Created by: kimsey0

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

When using the csharp-netcore generator, OpenAPI Generator will generate code that uses null as the default value for enum parameters. null is not a valid value for enums in C#.

It should instead generate default operator applied to the enum type, e.g., default(MyEnum). This is the behavior when using the csharp generator. (The default literal could be used, but is only available from C# 7.1.)

openapi-generator version

Version 4.2.0. (Also recreated in 4.1.3, 4.1.0, 4.0.3, and 4.0.0.)

OpenAPI declaration file content or url

https://gist.github.com/kimsey0/fe44536ff332ded4cf1346dfc0449888

Command line used for generation

npx -p @openapitools/openapi-generator-cli@cli-4.2.0 openapi-generator generate -i ./nullenumbug.json -g csharp-netcore -o ./nullenumbug

Steps to reproduce
  1. Create a OpenAPI declaration file containing an endpoint with a parameter of type string with enum values.
  2. Run OpenAPI Generator with this file as input and using the csharp-netcore generator.
  3. Try to compile the output.
  4. Observe the compile errors of the type:

Error CS1750: A value of type '<null>' cannot be used as a default parameter because there are no standard conversions to type 'MyEnum' (39, 31)

Related issues/PRs
Suggest a fix
Assignee
Assign to
Time tracking