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

[BUG] [c-sharp] Inconsistency in default values discriminator

Created by: tomelfring

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

Using the C# generator I found some inconsistencies in the default values for classes with a discriminator with a mapping.

When the discriminator propertyName is in camelCase, I notice the following:

  • JsonConverter uses a camelCase value
  • The property of the discriminator has a DataMemberAttribute with a camelCase name
  • In subclasses, the default value of the discriminator is default(string)

When the discriminator propertyname is in PascalCase, I notice the following:

  • JsonConverter uses a camelCase value
  • The property of the discriminator has a DataMemberAttribute with a PascalCase name
  • In subclasses, the default value of the discriminator is matching the spec

Expected:

  • The JsonConverter converterParameters and Datamember name to match
  • The subclasses having meaningful default values for discriminator parameters when mapping is provided in the spec
openapi-generator version

openapi-generator-cli-4.3.1.jar

OpenAPI declaration file content or url

Two files, one with camelCase, one with PascalCase: https://gist.github.com/thommy101/39b65b3a365a09d3738f26edc3e1682b

Command line used for generation

java -jar openapi-generator-cli-4.3.1.jar generate -i camelCase.yaml -g csharp -o camelCase java -jar openapi-generator-cli-4.3.1.jar generate -i pascalCase.yaml -g csharp -o pascalCase

Steps to reproduce
  • Execute above two command lines
  • Compare the camelCase and pascalCase variants of src/Org.OpenAPITools/Models/Animal.cs and src/Org.OpenAPITools/Models/Cat.cs
  • See the CamelCase variant of Animal having consistent JsonConverter-attribute on the class and DataMember-attribute on the property ClassName, but not having a default value for Cat's constructor parameter className (default(string))
  • See the PascalCase variant of Animal having inconsistent JsonConverter-attribute on the class and Datamember-attribute on the property ClassName, but having a correct default value for Cat's constructor parameter className ("Cat")
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/3308

https://github.com/OpenAPITools/openapi-generator/pull/5680: Related because forcing the JsonConverter attribute to camelCase and because of the comment:

Right now if this discriminator isn't camelCased it causes things to not deserialize properly when receiving them from an API (since the json is expected to come back camelcased)

Suggest a fix
Assignee
Assign to
Time tracking