-
Notifications
You must be signed in to change notification settings - Fork 422
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
Default value for enumeratum #1852
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
72aeebe
Regression test for Request Body with annotated defaults
mkrzemien 6c5dacf
Test for query parameter as enum with defaults
mkrzemien 3ffe984
Test for query parameter as enum with other default ignored
mkrzemien 198ca6b
Test for Request Body with enum and annotated default
mkrzemien 84638e5
Work-around with explicit encoded in default
mkrzemien 25f0808
Cleanup - test name
mkrzemien 0097f54
Cleanup - test name
mkrzemien 6eae808
Cleanup - test name for ignored case
mkrzemien 980a3f2
Draft macro for explicit encoded in default
mkrzemien 9e6ab40
Cleanup - test names
mkrzemien 70ec254
Fix for Scala 3
mkrzemien 4851df1
Fixing the target of the default macro
mkrzemien c8a405f
Reverting the default macro after review
mkrzemien 143b89f
Test macro with various combinations of annotation params
mkrzemien 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 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 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 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 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 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 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 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 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 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
54 changes: 54 additions & 0 deletions
54
...t/resources/enum/expected_enumeratum_enum_adding_default_when_encoded_value_specified.yml
This file contains 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,54 @@ | ||
openapi: 3.0.3 | ||
info: | ||
title: Fruits | ||
version: '1.0' | ||
paths: | ||
/: | ||
post: | ||
operationId: postRoot | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
$ref:'#/components/schemas/FruitQueryWithEncoded' | ||
required: true | ||
responses: | ||
'200': | ||
description: '' | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/FruitWithEnum' | ||
'400': | ||
description: 'Invalid value for: body' | ||
content: | ||
text/plain: | ||
schema: | ||
type: string | ||
components: | ||
schemas: | ||
FruitQueryWithEncoded: | ||
type: object | ||
properties: | ||
fruitType: | ||
$ref: '#/components/schemas/FruitType' | ||
FruitType: | ||
type: string | ||
default: PEAR | ||
enum: | ||
- APPLE | ||
- PEAR | ||
FruitWithEnum: | ||
required: | ||
- fruit | ||
- amount | ||
type: object | ||
properties: | ||
fruit: | ||
type: string | ||
amount: | ||
type: integer | ||
fruitType: | ||
type: array | ||
items: | ||
$ref: '#/components/schemas/FruitType' |
50 changes: 50 additions & 0 deletions
50
docs/openapi-docs/src/test/resources/enum/expected_enumeratum_enum_default.yml
This file contains 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,50 @@ | ||
openapi: 3.0.3 | ||
info: | ||
title: Fruits | ||
version: '1.0' | ||
paths: | ||
/: | ||
get: | ||
operationId: getRoot | ||
parameters: | ||
- name: type | ||
in: query | ||
required: false | ||
schema: | ||
$ref: '#/components/schemas/FruitType' | ||
example: APPLE | ||
responses: | ||
'200': | ||
description: '' | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/FruitWithEnum' | ||
'400': | ||
description: 'Invalid value for: query parameter type' | ||
content: | ||
text/plain: | ||
schema: | ||
type: string | ||
components: | ||
schemas: | ||
FruitType: | ||
type: string | ||
default: PEAR | ||
enum: | ||
- APPLE | ||
- PEAR | ||
FruitWithEnum: | ||
required: | ||
- fruit | ||
- amount | ||
type: object | ||
properties: | ||
fruit: | ||
type: string | ||
amount: | ||
type: integer | ||
fruitType: | ||
type: array | ||
items: | ||
$ref: '#/components/schemas/FruitType' |
53 changes: 53 additions & 0 deletions
53
...rces/enum/expected_enumeratum_enum_not_adding_default_when_no_encoded_value_specified.yml
This file contains 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,53 @@ | ||
openapi: 3.0.3 | ||
info: | ||
title: Fruits | ||
version: '1.0' | ||
paths: | ||
/: | ||
post: | ||
operationId: postRoot | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
$ref:'#/components/schemas/FruitQuery' | ||
required: true | ||
responses: | ||
'200': | ||
description: '' | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/FruitWithEnum' | ||
'400': | ||
description: 'Invalid value for: body' | ||
content: | ||
text/plain: | ||
schema: | ||
type: string | ||
components: | ||
schemas: | ||
FruitQuery: | ||
type: object | ||
properties: | ||
fruitType: | ||
$ref: '#/components/schemas/FruitType' | ||
FruitType: | ||
type: string | ||
enum: | ||
- APPLE | ||
- PEAR | ||
FruitWithEnum: | ||
required: | ||
- fruit | ||
- amount | ||
type: object | ||
properties: | ||
fruit: | ||
type: string | ||
amount: | ||
type: integer | ||
fruitType: | ||
type: array | ||
items: | ||
$ref: '#/components/schemas/FruitType' |
71 changes: 71 additions & 0 deletions
71
.../src/test/resources/enum/expected_enumeratum_enum_using_first_specified_default_value.yml
This file contains 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,71 @@ | ||
openapi: 3.0.3 | ||
info: | ||
title: Fruits | ||
version: '1.0' | ||
paths: | ||
/fruit-by-type1: | ||
get: | ||
operationId: getFruit-by-type1 | ||
parameters: | ||
- name: type1 | ||
in: query | ||
required: false | ||
schema: | ||
$ref: '#/components/schemas/FruitType' | ||
responses: | ||
'200': | ||
description: '' | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/FruitWithEnum' | ||
'400': | ||
description: 'Invalid value for: query parameter type1' | ||
content: | ||
text/plain: | ||
schema: | ||
type: string | ||
/fruit-by-type2: | ||
get: | ||
operationId: getFruit-by-type2 | ||
parameters: | ||
- name: type2 | ||
in: query | ||
required: false | ||
schema: | ||
$ref: '#/components/schemas/FruitType' | ||
responses: | ||
'200': | ||
description: '' | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/FruitWithEnum' | ||
'400': | ||
description: 'Invalid value for: query parameter type2' | ||
content: | ||
text/plain: | ||
schema: | ||
type: string | ||
components: | ||
schemas: | ||
FruitType: | ||
type: string | ||
default: PEAR | ||
enum: | ||
- APPLE | ||
- PEAR | ||
FruitWithEnum: | ||
required: | ||
- fruit | ||
- amount | ||
type: object | ||
properties: | ||
fruit: | ||
type: string | ||
amount: | ||
type: integer | ||
fruitType: | ||
type: array | ||
items: | ||
$ref: '#/components/schemas/FruitType' |
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.
out of curiosity, why not just return the second element of the list, which will correspond to the
encoded
annotation parameter?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.
Currently this method is used in
AnnotationMacros
(andEndpointAnnotationMacros
for Scala 2) where the first parameter is required.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.
Hm not sure I understand. Do you mean you needed to cover the cases when there are both 1 or 2 parameters if an annotation?
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.
I think my question is, why wouldn't this work:
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.
Yes, I've added the method to cover the cases with 1 or 2 parameters. I've described all these cases in a new test-case.
Actually, only the first parameter is currently used, the second one being ignored. So as an alternative I've been considering a different method - returning first arg and simply ignoring the rest.
I've created another PR with this alternative. The patter matching there is indeed much simpler.
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.
I wanted to make sure, that the second parameter was Optional. Now I think I might have overcomplicated it :/
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.
Happens :)