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
Currently, golang structs are generated as a flat structure, even when the OAS spec uses "allOf" and discriminators. I understand generating flat structures is valid, but IMO it would be better to leverage the "supportsInheritance" attribute and generate embedded go structs, or at least have an option to generate embedded go structs. This would make the generated code less verbose, easier to read and use, reduce the size of the generated code.
Hi Sebastien, I'm trying to use this feature but it doesn't embed the parent structure into the child. I'm using open-api-generator 4.3.1 . I changed the mustache also. Is anything else I can do ?
Hi Sebastien, I'm trying to use this feature but it doesn't embed the parent structure into the child. I'm using open-api-generator 4.3.1 . I changed the mustache also. Is anything else I can do ?
You use the go-experimental target, not go, right? This feature is not available in go and it's not available in the go server.
Also note that in 5.0, the go target is renamed to go-deprecated and go-experimental is renamed to go.
I am closing this issue this it was fixed with #4607
Can you verify #4607 was merged before 4.3.1 was released?
Bug Report Checklist
Description
Currently, golang structs are generated as a flat structure, even when the OAS spec uses "allOf" and discriminators. I understand generating flat structures is valid, but IMO it would be better to leverage the "supportsInheritance" attribute and generate embedded go structs, or at least have an option to generate embedded go structs. This would make the generated code less verbose, easier to read and use, reduce the size of the generated code.
openapi-generator version
4.2.1
OpenAPI declaration file content or url
https://gist.github.com/sebastien-rosset/f32f0abea11416bf82175577b48c251e
Command line used for generation
Steps to reproduce
Also, the AbstractGoCodegen.java file does not set the "supportsInheritance" field to true, unlike the AbstractJavaCodegen:
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java#L97
Related issues/PRs
PR to inherit the discriminators from all ancestors:
#4454
Issue with proposal to use interfaces:
#4559
Suggest a fix
Strawman proposal:
Set the "supportsInheritance" attribute to true for golang code.
In model.mustache, generate embedded go structs for the parent.
Potentially, there could be a flag to control whether or not the generated classes should be flattened.
The text was updated successfully, but these errors were encountered: