-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Support proper mapping of the byte array #4659
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
45 changes: 45 additions & 0 deletions
45
modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/BinaryParameterResourceTest.java
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,45 @@ | ||
package io.swagger.v3.jaxrs2; | ||
|
||
import java.io.IOException; | ||
|
||
import io.swagger.v3.oas.models.media.Schema; | ||
import org.testng.annotations.AfterTest; | ||
import org.testng.annotations.BeforeTest; | ||
import org.testng.annotations.Test; | ||
|
||
import io.swagger.v3.jaxrs2.annotations.AbstractAnnotationTest; | ||
import io.swagger.v3.jaxrs2.resources.BinaryParameterResource; | ||
|
||
public class BinaryParameterResourceTest extends AbstractAnnotationTest { | ||
|
||
@Test(description = "check binary model serialization with base64", singleThreaded = true) // tests issue #2466 | ||
public void shouldSerializeBinaryParameterBase64() throws IOException { | ||
try { | ||
System.setProperty(Schema.BINARY_STRING_CONVERSION_PROPERTY, Schema.BynaryStringConversion.BINARY_STRING_CONVERSION_BASE64.toString()); | ||
compareAsYaml(BinaryParameterResource.class, getOpenAPIAsString("BinaryParameterResource.yaml")); | ||
} finally { | ||
System.clearProperty(Schema.BINARY_STRING_CONVERSION_PROPERTY); | ||
} | ||
} | ||
|
||
@BeforeTest | ||
public void before() { | ||
System.clearProperty(Schema.BINARY_STRING_CONVERSION_PROPERTY); | ||
} | ||
|
||
@AfterTest | ||
public void after() { | ||
System.clearProperty(Schema.BINARY_STRING_CONVERSION_PROPERTY); | ||
} | ||
|
||
|
||
@Test(description = "check binary model serialization with StringSchema", singleThreaded = true) // tests issue #2466 | ||
public void shouldSerializeBinaryParameterStringSchema() throws IOException { | ||
try { | ||
System.setProperty(Schema.BINARY_STRING_CONVERSION_PROPERTY, Schema.BynaryStringConversion.BINARY_STRING_CONVERSION_STRING_SCHEMA.toString()); | ||
compareAsYaml(BinaryParameterResource.class, getOpenAPIAsString("BinaryParameterResource.yaml")); | ||
} finally { | ||
System.clearProperty(Schema.BINARY_STRING_CONVERSION_PROPERTY); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
.../swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/resources/BinaryParameterResource.java
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,44 @@ | ||
package io.swagger.v3.jaxrs2.resources; | ||
|
||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.core.Context; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.UriInfo; | ||
|
||
import io.swagger.v3.jaxrs2.resources.model.Item; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.headers.Header; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
|
||
@Path("/") | ||
public class BinaryParameterResource { | ||
@Consumes({ MediaType.APPLICATION_JSON }) | ||
@Path("/binary") | ||
@POST | ||
@Operation( | ||
summary = "Create new item", | ||
description = "Post operation with entity in a body", | ||
responses = { | ||
@ApiResponse( | ||
content = @Content( | ||
schema = @Schema(implementation = Item.class), | ||
mediaType = MediaType.APPLICATION_JSON | ||
), | ||
headers = @Header(name = "Location"), | ||
responseCode = "201" | ||
) | ||
} | ||
) | ||
public Response createItem(@Context final UriInfo uriInfo, @Parameter(required = true) final Item item) { | ||
return Response | ||
.created(uriInfo.getBaseUriBuilder().path(item.getName()).build()) | ||
.entity(item).build(); | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/resources/model/Item.java
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,57 @@ | ||
package io.swagger.v3.jaxrs2.resources.model; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
public class Item { | ||
private String name; | ||
private String value; | ||
@Schema(example = "Ynl0ZQ==") | ||
private byte[] bytes; | ||
@Schema(format = "binary", example = "YmluYXJ5") | ||
private byte[] binary; | ||
|
||
private byte[] byteNoAnnotation; | ||
|
||
public Item() { | ||
} | ||
|
||
public void setBinary(byte[] binary) { | ||
this.binary = binary; | ||
} | ||
|
||
public byte[] getBinary() { | ||
return binary; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public void setBytes(byte[] bytes) { | ||
this.bytes = bytes; | ||
} | ||
|
||
public byte[] getBytes() { | ||
return bytes; | ||
} | ||
|
||
public void setByteNoAnnotation(byte[] byteNoAnnotation) { | ||
this.byteNoAnnotation = byteNoAnnotation; | ||
} | ||
|
||
public byte[] getByteNoAnnotation() { | ||
return byteNoAnnotation; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
modules/swagger-jaxrs2/src/test/resources/BinaryParameterResource.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,42 @@ | ||
openapi: 3.0.1 | ||
paths: | ||
/binary: | ||
post: | ||
summary: Create new item | ||
description: Post operation with entity in a body | ||
operationId: createItem | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Item' | ||
required: true | ||
responses: | ||
"201": | ||
headers: | ||
Location: | ||
style: simple | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Item' | ||
components: | ||
schemas: | ||
Item: | ||
type: object | ||
properties: | ||
name: | ||
type: string | ||
value: | ||
type: string | ||
bytes: | ||
type: string | ||
format: byte | ||
example: Ynl0ZQ== | ||
binary: | ||
type: string | ||
format: binary | ||
example: YmluYXJ5 | ||
byteNoAnnotation: | ||
type: string | ||
format: byte |
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
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.
Check warning
Code scanning / CodeQL
Cross-site scripting