-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
[BUG][TypeScript - axios] Redundant models - the same type is generated multiple times #15077
Comments
I'm having the same problem, and it seems to be caused by having a description in combination with allOf. "NumberRange": {
"type": "object",
"properties": {
"min": { "type": "number", "description": "Minimum value of the range" },
"max": { "type": "number", "description": "Maximum value of the range" },
"step": { "type": "number", "description": "Step size for valid values" }
},
"required": ["min", "max"]
},
"MyModel": {
"type": "object",
"properties": {
"range1": {
"description": "This range describes...",
"readOnly": true,
"allOf": [{ "$ref": "#/components/schemas/NumberRange" }]
},
"range2": {
"readOnly": true,
"allOf": [{ "$ref": "#/components/schemas/NumberRange" }]
}
},
"required": ["range1", "range2"]
} Using OpenAPI Generator 6.5.0 with export interface MyModel {
readonly range1: MyModelRange1;
readonly range2: NumberRange;
}
/**
* This range describes...
*/
export interface MyModelRange1 extends NumberRange {
} It creates a new model for each property with a description, which in reality are many more than just one. The new models extend the base model (because of Of course I can remove the description, which gets rid of the additional models: export interface MyModel {
readonly range1: NumberRange;
readonly range2: NumberRange;
} However, especially in a case like this, where the model of the property is something general (like The output I really want is this, which is what OpenAPI Generator 5.4.0 generated: export interface MyModel {
/**
* This range describes...
*/
readonly range1: NumberRange;
readonly range2: NumberRange;
} This issue is realted to #12838, where special case handling of The temporary workaround was supposed to be replaced by a Normalizer ruleset, but as far as I can tell none of the currently available rulesets solve this issue. |
Any update? I tried v6.6.0 ... same result > It generates 4 same type (OffsetsObjectTypeOffsetsSUFFIX.ts files). I noticed this in console:
I mean this: WARN o.o.codegen.InlineModelResolver - allOf schema "null" containing multiple types (not model) is not supported at the moment. What to do? This is part of YAMLfile:
What is wrong? What command can it do correctly without redundancy? Im lost with this :/ |
This was partially fixed by #16096, however the issue still persists if |
Fixes OpenAPITools#15077 The previous fix for this in OpenAPITools#16096 is incomplete because it still generates unnecessary inline models when readOnly or nullable is used in conjunction with other properties like description. This commit fixes the logic error and adds testcases.
Fixes OpenAPITools#15077 The previous fix for this in OpenAPITools#16096 is incomplete because it still generates unnecessary inline models when readOnly or nullable is used in conjunction with other properties like description. This commit fixes the logic error and adds testcases.
Fixes OpenAPITools#15077 The previous fix for this in OpenAPITools#16096 is incomplete because it still generates unnecessary inline models when readOnly or nullable is used in conjunction with other properties like description. This commit fixes the logic error and adds testcases.
Bug Report Checklist
Description
OpenApi description generated just one model file in 5.4.0. In 6+ (tested with 6.0.0 and 6.4.0) every property (of the same schema) is generating one file per property, and all these files are pointing to the one (same) model/type.
openapi-generator version
5.4.0 ok, but generating with 6.0.0 and 6.4.0 causes issue described above.
OpenAPI declaration file content or url
There is sample of problematic part (in schemas)
Generation Details
"npx openapi-generator-cli generate --generator-key ${yaml-filename}"
I tried "--openapi-normalizer REF_AS_PARENT_IN_ALLOF=true" but no effect
Steps to reproduce
simply run generate sample above ... it will create (useless?) four (suffixed) models:
![image](https://user-images.githubusercontent.com/71878667/228747748-15222e37-730f-4897-9ed5-fc70d5e3ba58.png)
You can see propertyName suffix ... with contents:
offsets-object-type-offsets.ts:
offsets-object-type-offsets-first.ts:
offsets-object-type-offsets-next..ts:
offsets-object-type-offsets-previous.ts:
offsets-object-type-offsets-self.ts:
pagination-offset-type.ts:
v5.4.0 was generating:
![image](https://user-images.githubusercontent.com/71878667/228750286-06c9c559-11e6-43d3-837f-1f32389d59c7.png)
offsets-object-type.ts:
offsets-object-type-offsets.ts:
pagination-offset-type.ts:
I would exepect the same result, optimized, not reduntant files/types (with "equal" content)
Related issues/PRs
I have not found any related issue
Suggest a fix
No idea
The text was updated successfully, but these errors were encountered: