OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
[x] Have you provided a full/minimal spec to reproduce the issue?
[x] Have you validated the input using an OpenAPI validator (example)?
[x] What's the version of OpenAPI Generator used?
[x] Have you search for related issues/PRs?
[x] What's the actual output vs expected output?
Description
When generating a C# api that includes a discriminator that is lowerCamelCase, the generator does not properly configure the JsonSubTypes converter in the resultant code. This causes deserialization to always return the base class and the sub class fields are lost.
openapi-generator version
v4.0.2 - this appears to be a regression as it works properly in v3.2.3. I am not sure about versions in between.
Take the example swagger spec and run the generator from the command line
Observe the resulting C#. You will see the in the CatalogEntry.cs file that [JsonConverter(typeof(JsonSubtypes), "EntryType")] has the wrong casing for EntryType. It should match the DataMember attribute (and the spec) by using lowerCamelCase.
If you were to use the library and it consumed a response such as:
Bug Report Checklist
Description
When generating a C# api that includes a discriminator that is lowerCamelCase, the generator does not properly configure the
JsonSubTypes
converter in the resultant code. This causes deserialization to always return the base class and the sub class fields are lost.openapi-generator version
v4.0.2 - this appears to be a regression as it works properly in v3.2.3. I am not sure about versions in between.
OpenAPI declaration file content or url
Example Swagger Spec
Command line used for generation
generate -g csharp -i /swagger.yaml -o /output --additional-properties 'packageGuid={67035b31-f8e5-41a4-9673-954035084f7d},netCoreProjectFile=true,targetFr amework=v5.0,packageName=DiscriminatorExample'
Steps to reproduce
CatalogEntry.cs
file that[JsonConverter(typeof(JsonSubtypes), "EntryType")]
has the wrong casing forEntryType
. It should match theDataMember
attribute (and the spec) by using lowerCamelCase.It would process into 2
CatalogEntry
instances instead of aSku
andPackage
instance, and theproductId
andname
fields would be lost respectively.Suggest a fix
Fix the discriminatorName to use the proper casing based on the spec.