-
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.
refs #4771 - schema resolution for container types and oas31
- Loading branch information
Showing
4 changed files
with
121 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
98 changes: 98 additions & 0 deletions
98
modules/swagger-core/src/test/java/io/swagger/v3/core/resolving/Ticket4771Test.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,98 @@ | ||
package io.swagger.v3.core.resolving; | ||
|
||
import io.swagger.v3.core.converter.AnnotatedType; | ||
import io.swagger.v3.core.converter.ModelConverters; | ||
import io.swagger.v3.core.converter.ResolvedSchema; | ||
import io.swagger.v3.core.matchers.SerializationMatchers; | ||
import io.swagger.v3.oas.models.media.Schema; | ||
import org.testng.annotations.Test; | ||
|
||
public class Ticket4771Test { | ||
|
||
@Test | ||
public void testArraySchemaItemsValidation(){ | ||
ModelConverters.reset(); | ||
System.clearProperty(Schema.APPLY_SCHEMA_RESOLUTION_PROPERTY); | ||
ResolvedSchema schema = ModelConverters.getInstance(false, Schema.SchemaResolution.INLINE).resolveAsResolvedSchema(new AnnotatedType().type(CustomClass[].class)); | ||
String expectedJson = "{\n" + | ||
" \"schema\" : {\n" + | ||
" \"type\" : \"array\",\n" + | ||
" \"items\" : {\n" + | ||
" \"type\" : \"object\",\n" + | ||
" \"properties\" : {\n" + | ||
" \"foo\" : {\n" + | ||
" \"type\" : \"string\"\n" + | ||
" }\n" + | ||
" }\n" + | ||
" }\n" + | ||
" },\n" + | ||
" \"referencedSchemas\" : {\n" + | ||
" \"CustomClass\" : {\n" + | ||
" \"type\" : \"object\",\n" + | ||
" \"properties\" : {\n" + | ||
" \"foo\" : {\n" + | ||
" \"type\" : \"string\"\n" + | ||
" }\n" + | ||
" }\n" + | ||
" }\n" + | ||
" }\n" + | ||
"}"; | ||
SerializationMatchers.assertEqualsToJson(schema, expectedJson); | ||
ModelConverters.reset(); | ||
schema = ModelConverters.getInstance(true, Schema.SchemaResolution.INLINE).resolveAsResolvedSchema(new AnnotatedType().type(CustomClass[].class)); | ||
expectedJson = "{\n" + | ||
" \"schema\" : {\n" + | ||
" \"type\" : \"array\",\n" + | ||
" \"items\" : {\n" + | ||
" \"$ref\" : \"#/components/schemas/CustomClass\"\n" + | ||
" }\n" + | ||
" },\n" + | ||
" \"referencedSchemas\" : {\n" + | ||
" \"CustomClass\" : {\n" + | ||
" \"type\" : \"object\",\n" + | ||
" \"properties\" : {\n" + | ||
" \"foo\" : {\n" + | ||
" \"type\" : \"string\"\n" + | ||
" }\n" + | ||
" }\n" + | ||
" }\n" + | ||
" }\n" + | ||
"}"; | ||
SerializationMatchers.assertEqualsToJson31(schema, expectedJson); | ||
ModelConverters.reset(); | ||
System.setProperty(Schema.APPLY_SCHEMA_RESOLUTION_PROPERTY, "true"); | ||
schema = ModelConverters.getInstance(true, Schema.SchemaResolution.INLINE).resolveAsResolvedSchema(new AnnotatedType().type(CustomClass[].class)); | ||
expectedJson = "{\n" + | ||
" \"schema\" : {\n" + | ||
" \"type\" : \"array\",\n" + | ||
" \"items\" : {\n" + | ||
" \"type\" : \"object\",\n" + | ||
" \"properties\" : {\n" + | ||
" \"foo\" : {\n" + | ||
" \"type\" : \"string\"\n" + | ||
" }\n" + | ||
" }\n" + | ||
" }\n" + | ||
" },\n" + | ||
" \"referencedSchemas\" : {\n" + | ||
" \"CustomClass\" : {\n" + | ||
" \"type\" : \"object\",\n" + | ||
" \"properties\" : {\n" + | ||
" \"foo\" : {\n" + | ||
" \"type\" : \"string\"\n" + | ||
" }\n" + | ||
" }\n" + | ||
" }\n" + | ||
" }\n" + | ||
"}"; | ||
SerializationMatchers.assertEqualsToJson31(schema, expectedJson); | ||
System.clearProperty(Schema.APPLY_SCHEMA_RESOLUTION_PROPERTY); | ||
ModelConverters.reset(); | ||
|
||
|
||
} | ||
|
||
private static class CustomClass { | ||
public String foo; | ||
} | ||
} |
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