Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

leo-sale
Copy link

@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
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

Eagerly awaiting this to be merged

@RoundbootyGuilliman
Copy link

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

@efriandika
Copy link

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

@magentaRE
Copy link

any updates on this?

@wing328
Copy link
Member

wing328 commented Jan 11, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants