-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into openApi-3.1-ComposedSchema-fix
- Loading branch information
Showing
10 changed files
with
291 additions
and
8 deletions.
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
45 changes: 45 additions & 0 deletions
45
modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/BinaryParameterResourceTest.java
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,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 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 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 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 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
Oops, something went wrong.