[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
andDatamember
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 andDataMember
-attribute on the propertyClassName
, but not having a default value for Cat's constructor parameterclassName
(default(string)
) - See the PascalCase variant of Animal having inconsistent
JsonConverter
-attribute on the class andDatamember
-attribute on the propertyClassName
, but having a correct default value for Cat's constructor parameterclassName
("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)