OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
We are observing an issue in relation to usage and implementation of JsonSubTypes apparatus which is included in the csharp-netcore generator (openapitools version 6.5.0).
When using this generator to create a polymorphic tree of objects (1 level deep) - we observe that the configured discriminator field is annotated on the base class and any derived type - even though the schema is configured correctly (as per OpenApi spec documentation [allOf section])
An example of the issue is shown below:
As can be seen the base class has the expected discriminator in place but the sub-type also denotes this again (via JsonConverter attribute annotation). This causes any deserialisation (and validation) via Json.Net to be defunct. This functionality we believe should be implemented correctly. As per JsonSubTypes documentation - the JsonConverter attribute is only required for annotation on the base class of the polymorphic hierarchy.
This issue can be reproduced by using this linked schema with version 6.5.0 of the openapi tools as:
Please open the following files to observe the issue
models_out/src/Org.OpenAPITools/Model/NetworkService.cs - JsonConverter attribute on class annotation expected
models_out/src/Org.OpenAPITools/Model/P2PNetworkService.cs - JsonConverter attribute on class annotation NOT expected
models_out/src/Org.OpenAPITools/Model/CloudNetworkService.cs - - JsonConverter attribute on class annotation NOT expected
Proposed fix:
An investigation into the java code was conducted to attempt to resolve the issue in the short term. It was found that a small modification to this block of code during CodeGenModel creation did remove any sub-class annotation using JsonConverter attribute.
Whether this fix is the permanent approach will be upto the admins of this project - and relevant tests will need to be included.
This issue is a matter of urgency for our project delivery and any assistance is greatly appreciated. I would like to add some observed moderators in a tag list to get this issue as much visibility as possible in the short term - thanks in advance.
Please review in due course - thanks again: @wing328 @mandrean @shibayan @MartinDelille @muttleyxd
We are observing an issue in relation to usage and implementation of JsonSubTypes apparatus which is included in the csharp-netcore generator (openapitools version 6.5.0).
When using this generator to create a polymorphic tree of objects (1 level deep) - we observe that the configured discriminator field is annotated on the base class and any derived type - even though the schema is configured correctly (as per OpenApi spec documentation [allOf section])
An example of the issue is shown below:
As can be seen the base class has the expected discriminator in place but the sub-type also denotes this again (via JsonConverter attribute annotation). This causes any deserialisation (and validation) via Json.Net to be defunct. This functionality we believe should be implemented correctly. As per JsonSubTypes documentation - the JsonConverter attribute is only required for annotation on the base class of the polymorphic hierarchy.
This issue can be reproduced by using this linked schema with version 6.5.0 of the openapi tools as:
Linked schema: https://raw.githubusercontent.com/barryf002/openapi-models-validation/main/schema_manual_mod.yaml
Please open the following files to observe the issue
models_out/src/Org.OpenAPITools/Model/NetworkService.cs
- JsonConverter attribute on class annotation expectedmodels_out/src/Org.OpenAPITools/Model/P2PNetworkService.cs
- JsonConverter attribute on class annotation NOT expectedmodels_out/src/Org.OpenAPITools/Model/CloudNetworkService.cs
- - JsonConverter attribute on class annotation NOT expectedProposed fix:
An investigation into the java code was conducted to attempt to resolve the issue in the short term. It was found that a small modification to this block of code during
CodeGenModel
creation did remove any sub-class annotation using JsonConverter attribute.The deduced change (also depicted) is to remove the discriminator from any CodeGenModel created for a non-base class in this method (fromModel): https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpNetCoreClientCodegen.java#L375
As:
Whether this fix is the permanent approach will be upto the admins of this project - and relevant tests will need to be included.
This issue is a matter of urgency for our project delivery and any assistance is greatly appreciated. I would like to add some observed moderators in a tag list to get this issue as much visibility as possible in the short term - thanks in advance.
Please review in due course - thanks again: @wing328 @mandrean @shibayan @MartinDelille @muttleyxd