-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Keep nullability when inlining ref to primitive #21614
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
base: master
Are you sure you want to change the base?
Conversation
Hi, Could you add one of the terms mentioned in this documentation before your issue reference so that github can better visualize that a PR exists for your issue? E.g., writing It will add the icon highlighed in red in the image below. I would suggested that we add a test case to Note: I am in no way affiliated with the openapi-generator project, so these point are not part of a review. I am merely providing my own personal suggestions as another contributor to the project. |
@Mattias-Sehlstedt Good ideas - done. |
Hello again, I was a bit curious as to whether this was the cause of the error, since I had assumed that the normalizer would adjust this properly so that the parser could interpret a more "standard structure specification". I thus created a branch to test it, and to me it seems like this will not fix the missing nullability? I have taken your unaliasing change and I have then extended the test specification The normalizer changes the property to
|
I also expected that, however, after some extensive 'print-debugging' , it seems that the un-aliasing occurs after normalization. |
I found that this debugging worked well with investigating this scenario. I came to the same conclusion as you that the unaliasing for parameters causes the issue, since the current implementation expects that the nullability is derived from the "actual schema". But for this case that won't work due to the "actual schema" being an alias itself. TL;DR warning, see So after normalization the model will have two schema properties:
The first The latter
With the above in mind, do one want: ...
} else {
Schema unaliased = unaliasSchema(openAPI, allSchemas.get(ModelUtils.getSimpleRef(schema.get$ref())), schemaMappings);
// Preserve nullable property from the original schema reference
Schema newSchema = cloneSchema(unaliased, false);
newSchema.setNullable(schema.getNullable());
return newSchema;
} or ...
} else if (isPrimitiveSchema(ref)) {
// Preserve nullable property from the original schema reference
return cloneSchema(ref, ref.getSpecVersion().equals(SpecVersion.V31)).setNullable(schema.getNullable());
} else {
return unaliasSchema(openAPI, allSchemas.get(ModelUtils.getSimpleRef(schema.get$ref())), schemaMappings);
} ? I have tried the latter approach since I find that it better describes that the case "an alias to primitive schema" is a "terminal alias state" (I read it as all if-cases being different terminal states, and that the else represents "we need to go one step deeper"). I tried it out in a branch here, but I made it in an overloaded function for typescript rather than the lower level DefaultCodegen just when testing so I did not affect anything else.
I found that maybe the above solution with |
Fixes #21612
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming7.x.0
minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)