You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Whenever the OpenAPI spec contains one of the anyOf or oneOf sections it will generate uncompilable .NET Core server code.
It will generate attributes and method signatures which contain a reference to the class AnyOf<modelnames>, or OneOf<modelnames> (where the <modelnames> part is the names of the models in that section).
For example, the following OpenApi spec snippet (taken from the example spec below):
It seems the referenced type in this signature was intended to be a base class to the generated CustomerModel and ProjectModel classes, but the base class is never generated (and the generated models don't inherit from it) so this method signature throws a compiler error.
Generate the example spec using the above generation cli
The resulting code should be uncompilable due to the missing OneOfProjectModelCustomerModel class
Related issues/PRs
Issues #5938 and #7414 seem to be similar issues occurring on other languages
Suggest a fix
I haven't been able to solve this using templates (this issue seemingly occurs before the templates are invoked)
I'm not familiar enough with the source code of the generator to be able to pinpoint the exact moment the issue occurs.
The text was updated successfully, but these errors were encountered:
Looking further into this it seems this does indeed occur before the templates are invoked.
Debugging the operations using --global-property debugOperations=true yields the following metadata for the mustache templates: "openApiType" : "OneOfProjectModelCustomerModel"
Bug Report Checklist
Description
Whenever the OpenAPI spec contains one of the anyOf or oneOf sections it will generate uncompilable .NET Core server code.
It will generate attributes and method signatures which contain a reference to the class
AnyOf<modelnames>
, orOneOf<modelnames>
(where the<modelnames>
part is the names of the models in that section).For example, the following OpenApi spec snippet (taken from the example spec below):
would generate the following method (operation) signature:
[ProducesResponseType(statusCode: 200, type: typeof(OneOfCustomerModelProjectModel))]
It seems the referenced type in this signature was intended to be a base class to the generated
CustomerModel
andProjectModel
classes, but the base class is never generated (and the generated models don't inherit from it) so this method signature throws a compiler error.openapi-generator version
Tested with versions:
5.0.0
5.0.1-SNAPSHOT (20210108.082455-27)
5.1.0-SNAPSHOT (20201221.091745-1)
6.0.0-SNAPSHOT (20201221.092151-1)
OpenAPI declaration file content or url
Full example spec
Generation Details
Code generated using:
java -jar openapi-generator-cli.jar generate -i ./swagger.json -g aspnetcore -o ./output --additional-properties="generateBody=false,classModifier=abstract,operationResultTask=true,aspnetCoreVersion=3.1,buildTarget=library,isLibrary=true,packageName=MyProject.GeneratedStubs,useSwashbuckle=false"
Steps to reproduce
Generate the example spec using the above generation cli
The resulting code should be uncompilable due to the missing
OneOfProjectModelCustomerModel
classRelated issues/PRs
Issues #5938 and #7414 seem to be similar issues occurring on other languages
Suggest a fix
I haven't been able to solve this using templates (this issue seemingly occurs before the templates are invoked)
I'm not familiar enough with the source code of the generator to be able to pinpoint the exact moment the issue occurs.
The text was updated successfully, but these errors were encountered: