Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #4606
Closed
Open
Issue created Nov 25, 2019 by Administrator@rootContributor4 of 6 checklist items completed4/6 checklist items

[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
  1. Checkout OpenAPITool from master and build it
  2. Generate go client code from the OAS spec: https://gist.github.com/sebastien-rosset/f32f0abea11416bf82175577b48c251e
  3. 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.

Assignee
Assign to
Time tracking