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
  • Merge requests
  • !9834

Opt-in solution to remove unnecessary model for inline schema composition

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Administrator requested to merge github/fork/leo-sale/fix-unnecessary-models into master Jun 23, 2021
  • Overview 0
  • Commits 1
  • Pipelines 1
  • Changes 33

Created by: leo-sale

fix #3100 fix #5171

Description

When there is a ComposedSchema with inline schemas, the children are flatten. What is does is it's creating a new schema, by taking the parent's name and adding _allOf, _anyOf or _oneOf, or taking the title value and appending all the properties defined in the inline schema. Then the inline schema becomes just a reference to the newly created schema which is added to the imports of the parent. (example in this issue)

This is alright when we have a discriminator in our inline schema and what we wish for is inheritance but when all we want is composition it's just creating unused schemas.

A possible quick fix to prevent these unnecessary schemas is to ignore them in the .openapi-generator-ignore but it does not remove the schemas from the allModels instance meaning that you can have reference to them in your generated files (like some imports or exports, hence possibly breaking the build).

Solution

The proposed solution is to generate the new models only when it's for inheritance and just adding the properties of the inline schema to the parent (overriding the parent's properties when there is a name's conflict) without generating a new model. This solution comes with an opt-in CLI parameter : --allow-inline-schemas, to ease the merge of this fix.

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
   -i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml \
   -g php \
   -o /var/tmp/php_api_client
   --allow-inline-schemas
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/leo-sale/fix-unnecessary-models