-
-
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
22
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.
Open
Changes from all commits
Commits
Show all changes
22 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 cabc59f
alter test assertions to only assert on UNKNOWN_DEFAULT_OPEN_API and …
dijkstrar a3bd32d
enum is correctly generated, but one of the cases uses incorrect capi…
dijkstrar 8b2a43b
alter whitespace in enum class moustache, and generate dataclass mous…
dijkstrar cf4f29c
alter white space in moustache files, remove useless it->it.value==...
dijkstrar 270695d
also make testcase for enum integers in kotlin spring :)
dijkstrar 1cedbe5
tests now assert based on correctly, originally, capitalized unknown_…
dijkstrar 929309e
test based on the lowercased value of unknown_default_open_api, and a…
dijkstrar 99e545d
dont test on the enum vars themselves, but rely on the ci workflow fo…
dijkstrar 316833e
update docs based on provided script
dijkstrar 9e3518d
Merge branch 'master' into feature/add-kotlin-enumUnknownDefaultCase-…
dijkstrar dece211
add extra line after main merge...
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,15 +49,26 @@ | |
| * Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}} | ||
| */ | ||
| enum class {{{nameInPascalCase}}}(@get:JsonValue {{#useEnumValueInterface}}{{^isContainer}}override {{/isContainer}}{{/useEnumValueInterface}}val value: {{#isContainer}}{{#items}}{{{dataType}}}{{/items}}{{/isContainer}}{{^isContainer}}{{{dataType}}}{{/isContainer}}) {{#vendorExtensions.x-kotlin-implements}}{{#-first}}: {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}} {{/vendorExtensions.x-kotlin-implements}}{ | ||
| {{#allowableValues}}{{#enumVars}} | ||
| {{{name}}}({{{value}}}){{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}}; | ||
|
|
||
| {{#allowableValues}}{{#enumVars}} | ||
| {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}} | ||
| companion object { | ||
| @JvmStatic | ||
| @JsonCreator | ||
| fun forValue(value: {{#isContainer}}{{#items}}{{{dataType}}}{{/items}}{{/isContainer}}{{^isContainer}}{{{dataType}}}{{/isContainer}}): {{{nameInPascalCase}}} { | ||
| return values().firstOrNull{it -> it.value == value} | ||
| ?: throw IllegalArgumentException("Unexpected value '$value' for enum '{{nameInPascalCase}}'") | ||
| return values().firstOrNull{ it.value == value } | ||
| {{#enumUnknownDefaultCase}} | ||
| {{#allowableValues}} | ||
| {{#enumVars}} | ||
| {{#-last}} | ||
| ?: {{{name}}} | ||
| {{/-last}} | ||
| {{/enumVars}} | ||
| {{/allowableValues}} | ||
| {{/enumUnknownDefaultCase}} | ||
| {{^enumUnknownDefaultCase}} | ||
| ?: throw IllegalArgumentException("Unexpected value '$value' for enum '{{nameInPascalCase}}'") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i prefer to keep the spacing (4-space) same as before (line 60) |
||
| {{/enumUnknownDefaultCase}} | ||
| } | ||
| } | ||
| } | ||
|
|
||
34 changes: 25 additions & 9 deletions
34
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,33 @@ | ||
| /** | ||
| * {{{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}}; | ||
| * {{{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}}{{#-last}};{{/-last}} | ||
| {{/enumVars}} | ||
| {{/allowableValues}} | ||
|
|
||
| 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}} | ||
| {{#allowableValues}} | ||
| {{#enumVars}} | ||
| {{#-last}} | ||
| ?: {{&name}} | ||
| {{/-last}} | ||
| {{/enumVars}} | ||
| {{/allowableValues}} | ||
| {{/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
39 changes: 39 additions & 0 deletions
39
modules/openapi-generator/src/test/resources/3_1/dataclass_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,39 @@ | ||
| openapi: 3.0.0 | ||
| info: | ||
| title: Dataclass Nested Enum Test API | ||
| description: API for testing inline/nested enum generation in data classes 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 | ||
| properties: | ||
| color: | ||
| type: string | ||
| description: Available colors | ||
| enum: | ||
| - RED | ||
| - GREEN | ||
| - BLUE | ||
| - YELLOW | ||
| priority: | ||
| type: integer | ||
| description: Priority levels | ||
| enum: | ||
| - 1 | ||
| - 2 | ||
| - 3 |
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 |
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
better avoid spaces in empty lines if possible.