-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add Header Object missing attributes #4608
Merged
+418
−9
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
83a1ca1
Add explode attribute to header annotation
micryc 363d4bc
Add hidden attribute
micryc 55b2f73
Add example,examples attributes
micryc de2ad48
Add array attribute
micryc 3ba1cc8
Add explode,hidden,example and examples attributes tests
micryc 129196f
Add Header with ArraySchema attribute test
micryc 6ded486
Delete sout in test
micryc 5aae525
Fix schema implementation parsing process
micryc 6f884ae
Delete unused imports and spaces
micryc a56905b
Fix schema implementation test
micryc 3cc802b
Fix APIs backward compatibility
micryc cc14df5
Add space after coma
micryc 5e157ed
Refs #4196 - reintroduce original getHeader(s) methods signatures
frantuma 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package io.swagger.v3.jaxrs2.annotations.operations; | ||
|
||
import io.swagger.v3.jaxrs2.annotations.AbstractAnnotationTest; | ||
import io.swagger.v3.jaxrs2.petstore31.User; | ||
import io.swagger.v3.jaxrs2.resources.GenericResponsesResource; | ||
import io.swagger.v3.jaxrs2.resources.HiddenAnnotatedUserResource; | ||
import io.swagger.v3.jaxrs2.resources.HiddenUserResource; | ||
|
@@ -10,8 +11,10 @@ | |
import io.swagger.v3.jaxrs2.resources.UserResource; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.enums.Explode; | ||
import io.swagger.v3.oas.annotations.enums.ParameterIn; | ||
import io.swagger.v3.oas.annotations.headers.Header; | ||
import io.swagger.v3.oas.annotations.media.ArraySchema; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.ExampleObject; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
@@ -359,6 +362,139 @@ static class GetOperationWithResponseMultipleHeaders { | |
public void simpleGet() { | ||
} | ||
} | ||
@Test | ||
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 would add a new line (applies to all added methods) |
||
public void testOperationWithResponseArraySchema() { | ||
String openApiYAML = readIntoYaml(GetOperationResponseHeaderWithArraySchema.class); | ||
int start = openApiYAML.indexOf("get:"); | ||
String extractedYAML = openApiYAML.substring(start); | ||
String expectedYAML = "get:\n" + | ||
" summary: Simple get operation\n" + | ||
" description: Defines a simple get operation with no inputs and a complex output\n" + | ||
" operationId: getWithPayloadResponse\n" + | ||
" responses:\n" + | ||
" \"200\":\n" + | ||
" description: voila!\n" + | ||
" headers:\n" + | ||
" Rate-Limit-Limit:\n" + | ||
" description: The number of allowed requests in the current period\n" + | ||
" style: simple\n" + | ||
" schema:\n" + | ||
" maxItems: 10\n" + | ||
" minItems: 1\n" + | ||
" type: array\n" + | ||
" items:\n" + | ||
" type: integer\n" + | ||
" deprecated: true\n"; | ||
assertEquals(expectedYAML, extractedYAML); | ||
} | ||
static class GetOperationResponseHeaderWithArraySchema { | ||
@Operation( | ||
summary = "Simple get operation", | ||
description = "Defines a simple get operation with no inputs and a complex output", | ||
operationId = "getWithPayloadResponse", | ||
deprecated = true, | ||
responses = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "voila!", | ||
headers = {@Header( | ||
name = "Rate-Limit-Limit", | ||
description = "The number of allowed requests in the current period", | ||
array = @ArraySchema(maxItems = 10, minItems = 1,schema = @Schema(type = "integer")))})}) | ||
@GET | ||
@Path("/path") | ||
public void simpleGet() { | ||
} | ||
} | ||
static class GetOperationResponseWithoutHiddenHeader { | ||
@Operation( | ||
summary = "Simple get operation", | ||
description = "Defines a simple get operation with no inputs and a complex output", | ||
operationId = "getWithPayloadResponse", | ||
deprecated = true, | ||
responses = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "voila!", | ||
headers = {@Header( | ||
hidden = true, | ||
name = "Rate-Limit-Limit", | ||
description = "The number of allowed requests in the current period", | ||
schema = @Schema(type = "integer")), | ||
@Header( | ||
name = "X-Rate-Limit-Desc", | ||
description = "The description of rate limit", | ||
schema = @Schema(type = "string"))}) | ||
}) | ||
@GET | ||
@Path("/path") | ||
public void simpleGet() { | ||
} | ||
} | ||
static class GetOperationWithResponseMultipleHeadersAndExamples { | ||
@Operation( | ||
summary = "Simple get operation", | ||
description = "Defines a simple get operation with no inputs and a complex output", | ||
operationId = "getWithPayloadResponse", | ||
deprecated = true, | ||
responses = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "voila!", | ||
headers = {@Header( | ||
examples = { | ||
@ExampleObject( | ||
name = "ex 1", | ||
description = "example description", | ||
value = "example value" | ||
), | ||
@ExampleObject( | ||
name = "ex 2", | ||
description = "example description 2", | ||
value = "example value 2" | ||
) | ||
}, | ||
name = "Rate-Limit-Limit", | ||
description = "The number of allowed requests in the current period", | ||
schema = @Schema(type = "object")), | ||
@Header( | ||
name = "X-Rate-Limit-Desc", | ||
description = "The description of rate limit", | ||
array = @ArraySchema(schema = @Schema()), | ||
example = "example1")}) | ||
|
||
}) | ||
@GET | ||
@Path("/path") | ||
public void simpleGet() { | ||
} | ||
} | ||
static class GetOperationResponseWithHeaderExplodeAttribute { | ||
@Operation( | ||
summary = "Simple get operation", | ||
description = "Defines a simple get operation with no inputs and a complex output", | ||
operationId = "getWithPayloadResponse", | ||
deprecated = true, | ||
responses = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "voila!", | ||
headers = {@Header( | ||
name = "Rate-Limit-Limit", | ||
description = "The number of allowed requests in the current period", | ||
explode = Explode.TRUE, | ||
schema = @Schema(type = "object")), | ||
@Header( | ||
name = "X-Rate-Limit-Desc", | ||
description = "The description of rate limit", | ||
explode = Explode.FALSE, | ||
schema = @Schema(type = "array"))}) | ||
}) | ||
@GET | ||
@Path("/path") | ||
public void simpleGet() { | ||
} | ||
} | ||
|
||
@Test | ||
public void testOperationWithResponseMultipleHeaders() { | ||
|
@@ -386,6 +522,87 @@ public void testOperationWithResponseMultipleHeaders() { | |
" deprecated: true\n"; | ||
assertEquals(expectedYAML, extractedYAML); | ||
} | ||
@Test | ||
public void testOperationWithResponseMultipleHeadersAndExplodeAttribute() { | ||
String openApiYAML = readIntoYaml(GetOperationResponseWithHeaderExplodeAttribute.class); | ||
int start = openApiYAML.indexOf("get:"); | ||
String extractedYAML = openApiYAML.substring(start); | ||
String expectedYAML = "get:\n" + | ||
" summary: Simple get operation\n" + | ||
" description: Defines a simple get operation with no inputs and a complex output\n" + | ||
" operationId: getWithPayloadResponse\n" + | ||
" responses:\n" + | ||
" \"200\":\n" + | ||
" description: voila!\n" + | ||
" headers:\n" + | ||
" X-Rate-Limit-Desc:\n" + | ||
" description: The description of rate limit\n" + | ||
" style: simple\n" + | ||
" explode: false\n" + | ||
" schema:\n" + | ||
" type: array\n" + | ||
" Rate-Limit-Limit:\n" + | ||
" description: The number of allowed requests in the current period\n" + | ||
" style: simple\n" + | ||
" explode: true\n" + | ||
" schema:\n" + | ||
" type: object\n" + | ||
" deprecated: true\n"; | ||
assertEquals(expectedYAML, extractedYAML); | ||
} | ||
@Test | ||
public void testOperationResponseWithoutHiddenHeader() { | ||
String openApiYAML = readIntoYaml(GetOperationResponseWithoutHiddenHeader.class); | ||
int start = openApiYAML.indexOf("get:"); | ||
String extractedYAML = openApiYAML.substring(start); | ||
String expectedYAML = "get:\n" + | ||
" summary: Simple get operation\n" + | ||
" description: Defines a simple get operation with no inputs and a complex output\n" + | ||
" operationId: getWithPayloadResponse\n" + | ||
" responses:\n" + | ||
" \"200\":\n" + | ||
" description: voila!\n" + | ||
" headers:\n" + | ||
" X-Rate-Limit-Desc:\n" + | ||
" description: The description of rate limit\n" + | ||
" style: simple\n" + | ||
" schema:\n" + | ||
" type: string\n" + | ||
" deprecated: true\n"; | ||
assertEquals(expectedYAML, extractedYAML); | ||
} | ||
@Test | ||
public void testOperationWithResponseMultipleHeadersAndExamples() { | ||
String openApiYAML = readIntoYaml(GetOperationWithResponseMultipleHeadersAndExamples.class); | ||
int start = openApiYAML.indexOf("get:"); | ||
String extractedYAML = openApiYAML.substring(start); | ||
String expectedYAML = "get:\n" + | ||
" summary: Simple get operation\n" + | ||
" description: Defines a simple get operation with no inputs and a complex output\n" + | ||
" operationId: getWithPayloadResponse\n" + | ||
" responses:\n" + | ||
" \"200\":\n" + | ||
" description: voila!\n" + | ||
" headers:\n" + | ||
" X-Rate-Limit-Desc:\n" + | ||
" description: The description of rate limit\n" + | ||
" style: simple\n" + | ||
" example: example1\n" + | ||
" Rate-Limit-Limit:\n" + | ||
" description: The number of allowed requests in the current period\n" + | ||
" style: simple\n" + | ||
" schema:\n" + | ||
" type: object\n" + | ||
" examples:\n" + | ||
" ex 1:\n" + | ||
" description: example description\n" + | ||
" value: example value\n" + | ||
" ex 2:\n" + | ||
" description: example description 2\n" + | ||
" value: example value 2\n" + | ||
" deprecated: true\n"; | ||
assertEquals(expectedYAML, extractedYAML); | ||
} | ||
|
||
@Test(description = "reads the pet resource from sample") | ||
public void testCompletePetResource() throws IOException { | ||
|
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.
not used import?