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
  • #1358
Closed
Open
Issue created Oct 31, 2018 by Administrator@rootContributor

[Java] "allOf" no longer supports inheritance AND composition

Created by: clintfoster

Description

I just attempted to migrate from swagger-codegen to openapi-generator. It was mostly successful, except the behavior of allOf has changed. Previously the generated Java class would inherit from the first $ref and compose from the rest. With the new generator the Java class still extends the first $ref, as expected. But all the other $refs are ignored. (Their fields are no longer composed directly into the Java class.)

openapi-generator version

I am using the new Gradle plugin: openapi-generator-gradle-plugin:3.3.2 (much appreciated).

This previously worked with swagger-codegen-cli:3.0.2. In case you're wondering, since there is no official Gradle plugin I was using this org.hidetake.swagger.generator, which wraps the CLI as a Gradle plugin.

OpenAPI declaration file

See comments next to each $ref:

    Foo:
      allOf:
      - $ref: "#/components/schemas/FooBase"  # generated Java extended this class (still works)
      - $ref: "#/components/schemas/FooComposed1"  # all fields inlined (no longer works)
      - $ref: "#/components/schemas/FooComposed2"  # all fields inlined (no longer works)
      - properties:  # other props also inlined (still works)
          fooCount:
            type: integer

Note: FooBase has a discriminator. The composed models do not:

    FooBase:
      discriminator:
        propertyName: fooType
      required:
      - fooType
      properties:
        fooType:
          type: string
Command line used for generation
build.gradle excerpt
openApiGenerate {
    generatorName = 'java'
    configFile = 'open-api-cfg.json'
}
config file
{
  "modelPackage"     : "com.foo",
  "serializableModel": "true",
  "dateLibrary"      : "java8",
  "java8"            : "true"
}
Suggest a fix/enhancement

The Java generator should support single inheritance, plus an arbitrary number of composed models, as it did before. This allows a great deal of flexibility. For example, I have models representing "views" returned to clients consisting of a database record that extends a base model, plus fields composed from other models. The client need not know which fields came directly from the db record, and which are calculated on-the-fly and returned from other models.

Assignee
Assign to
Time tracking