-
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 10 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
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' |
34 changes: 34 additions & 0 deletions
34
docs/openapi-docs/src/test/resources/expected_default_request_body.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,34 @@ | ||
openapi: 3.0.3 | ||
info: | ||
title: Entities | ||
version: '1.0' | ||
paths: | ||
/: | ||
post: | ||
operationId: postRoot | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/ObjectWithDefaults' | ||
required: true | ||
responses: | ||
'200': | ||
description: '' | ||
'400': | ||
description: 'Invalid value for: body' | ||
content: | ||
text/plain: | ||
schema: | ||
type: string | ||
components: | ||
schemas: | ||
ObjectWithDefaults: | ||
type: object | ||
properties: | ||
name: | ||
type: string | ||
default: foo | ||
count: | ||
type: integer | ||
default: 12 |
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.
Should we allow to pass
encoded
here? It can cause ambiguity if someone passes a value that doest not match the codec encodingThere 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.
Without this change I get following compilation error:
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.
Right, we are passing
encoded
using this method in annotations macro.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.
Encoded defaults only have to be passed to schemas, not to inputs (as they have codecs). So I guess @kubinio123 is right, and we should instead opt out of using the encoded parameter on inputs (and document why :) )
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.
Ok, I'll revert this change.
I just need to find another way to pass the
encoded
value from the@default
annotation to the schema without using this method.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.
But the default value is already passed, being automatically encoded to the correct form?
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.
It turned out that the
EndpointIO.default
method was used by the macros instead of theSchema.default
. I've updated the macros and reverted the change inEndpointIO
.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.
Reverting to using EndpointIO.default (as suggested in the review).
Adding more tests for macro handling annotation with additional parameter.