-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Feature/add kotlin enum unknown default case support #23936
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
Open
dijkstrar
wants to merge
11
commits into
OpenAPITools:master
Choose a base branch
from
dijkstrar:feature/add-kotlin-enumUnknownDefaultCase-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+376
−9
Open
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d053a5b
update docs for generators
dijkstrar b7a8641
only apply flag to kotlin spring generator
dijkstrar cf86eb0
add unknown default value to moustache, and make tests to assert corr…
dijkstrar c9a6337
address review comments
dijkstrar 586b171
fix typo in cliOption to CliOption...
dijkstrar b899d9d
oneline the override in the moustache file
dijkstrar 84be4bf
add unknown default enum case to the dataclass moustache file
dijkstrar 599444e
test the inclusion of the enum default for the dataclass files
dijkstrar e7702b2
create resources file for testing enum dataclass default
dijkstrar df45fd0
fallback is non nullable, resolves to 11184809
dijkstrar 5f444ca
update kotlin spring docs so that enumUnknownDefaultCase docs is equa…
dijkstrar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 20 additions & 7 deletions
27
modules/openapi-generator/src/main/resources/kotlin-spring/enumClass.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,30 @@ | ||
| /** | ||
| * {{{description}}} | ||
| * Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}} | ||
| */ | ||
| enum class {{classname}}(@get:JsonValue {{#useEnumValueInterface}}override {{/useEnumValueInterface}}val value: {{dataType}}) {{#vendorExtensions.x-kotlin-implements}}{{#-first}}: {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}} {{/vendorExtensions.x-kotlin-implements}}{ | ||
| * {{{description}}} | ||
| * Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}} | ||
| */ | ||
| enum class {{classname}}( | ||
| @get:JsonValue {{#useEnumValueInterface}}override {{/useEnumValueInterface}}val value: {{dataType}} | ||
| ) {{#vendorExtensions.x-kotlin-implements}}{{#-first}}: {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-kotlin-implements}} { | ||
|
|
||
| {{#allowableValues}}{{#enumVars}} | ||
| {{&name}}({{{value}}}){{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}}; | ||
| {{&name}}({{{value}}}){{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}} | ||
| {{#enumUnknownDefaultCase}}, | ||
| UNKNOWN_DEFAULT_OPEN_API({{#isString}}"unknown_default_open_api"{{/isString}}{{^isString}}{{#dataType}}null{{/dataType}}{{/isString}}) | ||
| {{/enumUnknownDefaultCase}}; | ||
|
|
||
| companion object { | ||
| @JvmStatic | ||
| @JsonCreator | ||
| fun forValue(value: {{dataType}}): {{classname}} { | ||
| return values().firstOrNull{it -> it.value == value} | ||
| ?: throw IllegalArgumentException("Unexpected value '$value' for enum '{{classname}}'") | ||
| return values().firstOrNull { it.value == value } | ||
| {{#enumUnknownDefaultCase}} | ||
| ?: UNKNOWN_DEFAULT_OPEN_API | ||
| {{/enumUnknownDefaultCase}} | ||
| {{^enumUnknownDefaultCase}} | ||
| ?: throw IllegalArgumentException( | ||
| "Unexpected value '$value' for enum '{{classname}}'" | ||
| ) | ||
| {{/enumUnknownDefaultCase}} | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
modules/openapi-generator/src/test/resources/3_1/enum_unknown_default_case.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| openapi: 3.0.0 | ||
| info: | ||
| title: Enum Test API | ||
| description: API for testing enum generation with enumUnknownDefaultCase | ||
| version: 1.0.0 | ||
| paths: | ||
| /colors: | ||
| get: | ||
| summary: Get color | ||
| operationId: getColor | ||
| responses: | ||
| '200': | ||
| description: Successful response | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/ColorResponse' | ||
| components: | ||
| schemas: | ||
| ColorResponse: | ||
| type: object | ||
| required: | ||
| - color | ||
| - status | ||
| properties: | ||
| color: | ||
| $ref: '#/components/schemas/ColorEnum' | ||
| status: | ||
| $ref: '#/components/schemas/StatusEnum' | ||
| priority: | ||
| $ref: '#/components/schemas/PriorityEnum' | ||
| ColorEnum: | ||
| type: string | ||
| description: Available colors | ||
| enum: | ||
| - RED | ||
| - GREEN | ||
| - BLUE | ||
| - YELLOW | ||
| StatusEnum: | ||
| type: string | ||
| description: Status values | ||
| enum: | ||
| - PENDING | ||
| - APPROVED | ||
| - REJECTED | ||
| - IN_PROGRESS | ||
| PriorityEnum: | ||
| type: integer | ||
| description: Priority levels | ||
| enum: | ||
| - 1 | ||
| - 2 | ||
| - 3 | ||
| - 4 | ||
| - 5 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.