-
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.
schema resolution options - Phase 4: granular schema resolution via @…
…Schema.schemaResolution
- Loading branch information
Showing
6 changed files
with
283 additions
and
13 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
117 changes: 117 additions & 0 deletions
117
...les/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/SchemaResolutionAnnotationTest.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,117 @@ | ||
package io.swagger.v3.jaxrs2; | ||
|
||
import io.swagger.v3.core.converter.ModelConverters; | ||
import io.swagger.v3.jaxrs2.matchers.SerializationMatchers; | ||
import io.swagger.v3.jaxrs2.schemaResolution.SchemaResolutionAnnotatedResource; | ||
import io.swagger.v3.oas.integration.SwaggerConfiguration; | ||
import io.swagger.v3.oas.models.OpenAPI; | ||
import org.testng.annotations.Test; | ||
|
||
public class SchemaResolutionAnnotationTest { | ||
|
||
@Test | ||
public void testSchemaResolutionAnnotation() { | ||
ModelConverters.reset(); | ||
Reader reader = new Reader(new SwaggerConfiguration().openAPI(new OpenAPI())); | ||
OpenAPI openAPI = reader.read(SchemaResolutionAnnotatedResource.class); | ||
String yaml = "openapi: 3.0.1\n" + | ||
"paths:\n" + | ||
" /test/inlineSchemaFirst:\n" + | ||
" get:\n" + | ||
" operationId: inlineSchemaFirst\n" + | ||
" responses:\n" + | ||
" default:\n" + | ||
" description: default response\n" + | ||
" content:\n" + | ||
" '*/*':\n" + | ||
" schema:\n" + | ||
" $ref: '#/components/schemas/InlineSchemaFirst'\n" + | ||
" /test/inlineSchemaSecond:\n" + | ||
" get:\n" + | ||
" operationId: inlineSchemaSecond\n" + | ||
" requestBody:\n" + | ||
" content:\n" + | ||
" '*/*':\n" + | ||
" schema:\n" + | ||
" type: object\n" + | ||
" properties:\n" + | ||
" foo:\n" + | ||
" type: string\n" + | ||
" propertySecond1:\n" + | ||
" $ref: '#/components/schemas/InlineSchemaPropertySecond'\n" + | ||
" property2:\n" + | ||
" $ref: '#/components/schemas/InlineSchemaPropertyFirst'\n" + | ||
" description: InlineSchemaSecond API\n" + | ||
" responses:\n" + | ||
" default:\n" + | ||
" description: default response\n" + | ||
" content:\n" + | ||
" '*/*':\n" + | ||
" schema:\n" + | ||
" $ref: '#/components/schemas/InlineSchemaSecond'\n" + | ||
"components:\n" + | ||
" schemas:\n" + | ||
" InlineSchemaFirst:\n" + | ||
" type: object\n" + | ||
" properties:\n" + | ||
" property1:\n" + | ||
" description: InlineSchemaFirst property 1\n" + | ||
" nullable: true\n" + | ||
" allOf:\n" + | ||
" - $ref: '#/components/schemas/InlineSchemaPropertyFirst'\n" + | ||
" property2:\n" + | ||
" type: object\n" + | ||
" properties:\n" + | ||
" bar:\n" + | ||
" type: string\n" + | ||
" description: property\n" + | ||
" example: example\n" + | ||
" InlineSchemaPropertyFirst:\n" + | ||
" type: object\n" + | ||
" properties:\n" + | ||
" bar:\n" + | ||
" type: string\n" + | ||
" description: property\n" + | ||
" example: example\n" + | ||
" InlineSchemaPropertySecond:\n" + | ||
" type: object\n" + | ||
" properties:\n" + | ||
" bar:\n" + | ||
" $ref: '#/components/schemas/InlineSchemaSimple'\n" + | ||
" description: propertysecond\n" + | ||
" nullable: true\n" + | ||
" example: examplesecond\n" + | ||
" InlineSchemaPropertySimple:\n" + | ||
" type: object\n" + | ||
" properties:\n" + | ||
" bar:\n" + | ||
" type: string\n" + | ||
" description: property\n" + | ||
" InlineSchemaSecond:\n" + | ||
" type: object\n" + | ||
" properties:\n" + | ||
" foo:\n" + | ||
" type: string\n" + | ||
" propertySecond1:\n" + | ||
" $ref: '#/components/schemas/InlineSchemaPropertySecond'\n" + | ||
" property2:\n" + | ||
" $ref: '#/components/schemas/InlineSchemaPropertyFirst'\n" + | ||
" description: InlineSchemaSecond API\n" + | ||
" InlineSchemaSimple:\n" + | ||
" type: object\n" + | ||
" properties:\n" + | ||
" property1:\n" + | ||
" type: object\n" + | ||
" properties:\n" + | ||
" bar:\n" + | ||
" type: string\n" + | ||
" description: property\n" + | ||
" property2:\n" + | ||
" description: property 2\n" + | ||
" example: example\n" + | ||
" allOf:\n" + | ||
" - $ref: '#/components/schemas/InlineSchemaPropertySimple'\n"; | ||
SerializationMatchers.assertEqualsToYaml(openAPI, yaml); | ||
ModelConverters.reset(); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
...rc/test/java/io/swagger/v3/jaxrs2/schemaResolution/SchemaResolutionAnnotatedResource.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,83 @@ | ||
package io.swagger.v3.jaxrs2.schemaResolution; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
@Path("test") | ||
public class SchemaResolutionAnnotatedResource { | ||
|
||
@GET | ||
@Path("/inlineSchemaSecond") | ||
public InlineSchemaSecond inlineSchemaSecond(@Schema(description = "InlineSchemaSecond API", schemaResolution = Schema.SchemaResolution.INLINE) InlineSchemaSecond inlineSchemaSecond) { | ||
return null; | ||
} | ||
@GET | ||
@Path("/inlineSchemaFirst") | ||
public InlineSchemaFirst inlineSchemaFirst() { | ||
return null; | ||
} | ||
|
||
|
||
static class InlineSchemaFirst { | ||
|
||
// public String foo; | ||
|
||
@Schema(description = "InlineSchemaFirst property 1", nullable = true, schemaResolution = Schema.SchemaResolution.ALL_OF_REF) | ||
public InlineSchemaPropertyFirst property1; | ||
|
||
|
||
private InlineSchemaPropertyFirst property2; | ||
|
||
@Schema(description = " InlineSchemaFirst property 2", example = "example 2", schemaResolution = Schema.SchemaResolution.INLINE) | ||
public InlineSchemaPropertyFirst getProperty2() { | ||
return null; | ||
} | ||
} | ||
|
||
static class InlineSchemaSecond { | ||
|
||
public String foo; | ||
|
||
@Schema(description = "InlineSchemaSecond property 1", nullable = true) | ||
public InlineSchemaPropertySecond propertySecond1; | ||
|
||
|
||
private InlineSchemaPropertyFirst property2; | ||
|
||
@Schema(description = "InlineSchemaSecond property 2", example = "InlineSchemaSecond example 2") | ||
public InlineSchemaPropertyFirst getProperty2() { | ||
return null; | ||
} | ||
} | ||
|
||
@Schema(description = "property", example = "example") | ||
static class InlineSchemaPropertyFirst { | ||
public String bar; | ||
} | ||
|
||
@Schema(description = "propertysecond", example = "examplesecond") | ||
static class InlineSchemaPropertySecond { | ||
public InlineSchemaSimple bar; | ||
} | ||
|
||
static class InlineSchemaSimple { | ||
|
||
@Schema(description = "property 1", schemaResolution = Schema.SchemaResolution.INLINE) | ||
public InlineSchemaPropertySimple property1; | ||
|
||
|
||
private InlineSchemaPropertySimple property2; | ||
|
||
@Schema(description = "property 2", example = "example", schemaResolution = Schema.SchemaResolution.ALL_OF_REF) | ||
public InlineSchemaPropertySimple getProperty2() { | ||
return null; | ||
} | ||
} | ||
|
||
@Schema(description = "property") | ||
static class InlineSchemaPropertySimple { | ||
public String bar; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...t/java/io/swagger/v3/jaxrs2/schemaResolution/SchemaResolutionAnnotatedSimpleResource.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,32 @@ | ||
package io.swagger.v3.jaxrs2.schemaResolution; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
@Path("test") | ||
public class SchemaResolutionAnnotatedSimpleResource { | ||
|
||
@GET | ||
@Path("/inlineSchemaFirst") | ||
public InlineSchemaFirst inlineSchemaFirst() { | ||
return null; | ||
} | ||
|
||
|
||
static class InlineSchemaFirst { | ||
|
||
private InlineSchemaPropertyFirst property2; | ||
|
||
@Schema(description = " InlineSchemaFirst property 2", example = "example 2", schemaResolution = Schema.SchemaResolution.INLINE) | ||
public InlineSchemaPropertyFirst getProperty2() { | ||
return null; | ||
} | ||
} | ||
|
||
@Schema(description = "property", example = "example") | ||
static class InlineSchemaPropertyFirst { | ||
// public String bar; | ||
} | ||
} |