-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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] [Engine] InlineModelResolver creates weird named duplicate inline models and there is no way to turn it off #12838
Comments
Same issue here, this is causing our models to be incorrect now. |
We definitely want the previous behavior where it would auto link: |
Related: #13056 |
It seems like this bug was actually caused by #12348, which always turns allOf-schemas into inline models. This caused another regression in combination with This bug is another instance of the same regression, where a combination with |
Quick addition: "MyClass": {
"type": "object",
"properties": {
"subclass": {
"description": "This is a description",
"allOf": [{ "$ref": "#/components/schemas/MySubclass" }]
},
},
"required": ["subclass"]
} The description should apply to the property on the parent and and generate a comment in the parent model: export interface MyClass {
/**
* This is a description
*/
subclass: MySubclass;
} This worked fine in v5.x. export interface MyClass {
subclass: MyClassMySubclass;
} The description gets swallowed into a new inline model I think the change in #12348 needs to be reevaluated on when exactly an |
I'll try to squeeze some time to take a look at this issue in Oct. I already have some solutions in mind. Can you guys please share the minimal spec to reproduce the issue? Thanks. |
Here is a minimal spec, including the relevant typescript-angular output from version 5.4 and version 6.1: An additional note I found while researching this, is that the allOf-nullable-pattern does not actually mean what most people think it means, according to a clarifaction in the OpenAPI spec (see also OAI/OpenAPI-Specification#1368). A schema that is non-nullable cannot be made nullable using
Neither v5.4 nor v6.1 follow spec here, since the `nullableSubclass` property should _not_ be nullable according to spec. I don't think current behavior here should be changed, since this would probably break even more things. There is no alternative nice way to describe nullable properties in the OpenAPI 3.0 spec.
OpenAPI 3.1 will get rid of oneOf:
- type: 'null'
- $ref: '#/components/schemas/MySubclass' However, OpenAPI 3.1 is not widely supported yet. The second case using I think the fix to this is that the usage of *Edit: Or, like in the original bug that was fixed, |
@wing328 |
Ah, this looks like we can probably apply the same fix for readonly as nullable. I'll raise a new PR. |
#16096 improves this even further, where it also doesn't generate new classes for a combination of description + a single ref |
Bug Report Checklist
Description
InlineModelResolver introduced a critical regression bug for nullable objects in OpenAPI schema
openapi-generator version
6.0.1
OpenAPI declaration file content or URL
#12237
modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java
Generation Details
Let's say we have an object defined in my OpenAPI 3.0.3 schema
Before this PR, the OpenAPI generator will link
LoginPasswordlessResponse.user
toBaseUser
without creating a redundant inline model.But now it will create a new model called
LoginPasswordlessResponse_user
And I cannot overwrite it with
--inline-schema-name-mappings
option because if I overwriteLoginPasswordlessResponse_user
withBaseUser
the whole openapi generator will just break due to duplicate model names.(and by the way you missed the ending "s" in the log output, which is very misleading. I spend hours on figuring out why --inline-schema-name-mapping is an invalid option, turns out it should be --inline-schema-name-mappings)
Steps to reproduce
Shown above
Related issues/PRs
#12237
Suggest a fix
The text was updated successfully, but these errors were encountered: