-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
fix(core): single value enums (const
) are not generated correctly in 3.1
specs
#19696
Conversation
import { HttpFile } from '../http/http'; | ||
|
||
export class SingleValueEnum31 { | ||
'type': string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be:
'type': string; | |
'type': 'this-is-my-only-value'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix in 9d36e99
This comment was marked as outdated.
This comment was marked as outdated.
@@ -1251,6 +1251,12 @@ private Schema processNormalize31Spec(Schema schema, Set<Schema> visitedSchemas) | |||
schema.getTypes().remove("null"); | |||
} | |||
|
|||
// process const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the actual fix that transforms a single const into an enum with one value, so the 3.1 and 3.0 representations are equivalent
import { HttpFile } from '../http/http'; | ||
|
||
export class SingleValueEnum31 { | ||
'type': SingleValueEnum31TypeEnum; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the fix (1)
} | ||
|
||
export enum SingleValueEnum31TypeEnum { | ||
ThisIsMyOnlyValue = 'this-is-my-only-value' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and (2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
thanks for the PR cc @OpenAPITools/generator-core-team |
Thank you. Sorry, wasn't aware there was a core team alias, will use that one from now on. Update: actually, I think this team doesn't exist? But it would be great if it did, and even greater if we had one per generator? We could then update the pull request template as well with the correct mention, which will work as well for additions and removals and people in the respective team can also tailor their notification preferences around it and/or filter emails |
Is there anything I can do to help this one along? I am somewhat blocked in planet-a-ventures/affinity-node#49 until this issue has been resolved. |
lgtm. thanks for the PR |
fyi. samples updated via c8fad42 |
This pull request extends the
OpenApiNormalizer
to translate single const enums (3.1) into an enum with a single value (3.0).The fix and a unit test is in 9d36e99
The diff of the samples produced by that fix can be seen in 2760c37
Background:
Currently single value enums in
3.1
are not generated correctly.In
3.1
these two schemas should produce equivalent code:(the
type
property of each model can only ever have the valuethis-is-my-only-value
. For3.1
specs this seems to be widened tostring
, which is only technically correct.It is especially visible in the
typescript
generator, where values are now widened tostring
instead of a"this-is-my-only-value" as const
type. //cc @macjohnnyReal-world example (a spec that was upgraded from
3.0.1
to3.1.0
:via planet-a-ventures/affinity-node#49
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)targeting a particular programming languagecore: @wing328