Opt-in solution to remove unnecessary model for inline schema composition#9834
Closed
leo-sale wants to merge 1 commit intoOpenAPITools:masterfrom
Closed
Opt-in solution to remove unnecessary model for inline schema composition#9834leo-sale wants to merge 1 commit intoOpenAPITools:masterfrom
leo-sale wants to merge 1 commit intoOpenAPITools:masterfrom
Conversation
75bbadd to
8cf451a
Compare
Author
|
Hey @wing328, could you have a look at this PR ? It has almost been 2 months but there is still no review 😢 |
|
Eagerly awaiting this to be merged |
|
Anyone? Why is this PR ignored for half a year when this is a widely requested change? |
|
Hi @wing328 If you don't mind, please have a look at this PR. |
|
any updates on this? |
Member
|
can you try the PR I filed instead? You can find the details in #3100 (comment) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix #3100 fix #5171
Description
When there is a
ComposedSchemawith 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,_anyOfor_oneOf, or taking thetitlevalue 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 theimportsof the parent. (example in this issue)This is alright when we have a
discriminatorin 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-ignorebut it does not remove the schemas from theallModelsinstance 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.