Skip to content

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

Closed
leo-sale wants to merge 1 commit intoOpenAPITools:masterfrom
leo-sale:fix-unnecessary-models
Closed

Opt-in solution to remove unnecessary model for inline schema composition#9834
leo-sale wants to merge 1 commit intoOpenAPITools:masterfrom
leo-sale:fix-unnecessary-models

Conversation

@leo-sale
Copy link
Copy Markdown

@leo-sale leo-sale commented Jun 23, 2021

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

@leo-sale leo-sale requested a review from jimschubert as a code owner June 23, 2021 15:27
@leo-sale leo-sale marked this pull request as draft June 23, 2021 15:36
@leo-sale leo-sale force-pushed the fix-unnecessary-models branch from 75bbadd to 8cf451a Compare June 23, 2021 16:05
@leo-sale leo-sale closed this Jun 24, 2021
@leo-sale leo-sale reopened this Jun 24, 2021
@leo-sale leo-sale marked this pull request as ready for review June 24, 2021 07:17
@leo-sale
Copy link
Copy Markdown
Author

Hey @wing328, could you have a look at this PR ? It has almost been 2 months but there is still no review 😢
Thank you 😃

@dapperdandev
Copy link
Copy Markdown

Eagerly awaiting this to be merged

@RoundbootyGuilliman
Copy link
Copy Markdown

Anyone? Why is this PR ignored for half a year when this is a widely requested change?

@efriandika
Copy link
Copy Markdown

Hi @wing328 If you don't mind, please have a look at this PR.

@magentaRE
Copy link
Copy Markdown

any updates on this?

@wing328
Copy link
Copy Markdown
Member

wing328 commented Jan 11, 2023

can you try the PR I filed instead? You can find the details in #3100 (comment)

@JMLX42 JMLX42 mentioned this pull request Apr 28, 2025
@wing328 wing328 closed this Aug 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][typescript-angular] allOf without discriminator results in unnecessary imports [BUG] [JAVA] Java generation of 'extra' class with allOf

6 participants