[BUG][Go] Support allOf inheritance with embedded go structs
Created by: sebastien-rosset
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
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
JAR_FILE=openapi-generator-cli.jar
config=config.yaml
spec=vehicles.yaml
java -jar ${JAR_FILE} generate \
-c $config \
-i ${spec} \
-g go-experimental \
-o out \
--enable-post-process-file
Steps to reproduce
- Checkout OpenAPITool from master and build it
- Generate go client code from the OAS spec: https://gist.github.com/sebastien-rosset/f32f0abea11416bf82175577b48c251e
- Notice the model files are flattened and do not use supportsInheritance
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: https://github.com/OpenAPITools/openapi-generator/pull/4454
Issue with proposal to use interfaces: https://github.com/OpenAPITools/openapi-generator/issues/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.