Created by: leo-sale
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