use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIssue975_array_array.
@Test(description = "Test that relative references are resolvable when property is an array with an array with a reference to a relative file.")
public void testIssue975_array_array() {
Map<String, Schema> properties = issue975ExtractPropertiesFromTestResource();
ArraySchema imagesArray = (ArraySchema) properties.get("imagesArrayArray");
imagesArray = (ArraySchema) imagesArray.getItems();
assertEquals(imagesArray.getItems().get$ref(), "#/components/schemas/Image");
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIssue975_array_map.
@Test(description = "Test that relative references are resolvable when property is an array with a map with a reference to a relative file.")
public void testIssue975_array_map() {
Map<String, Schema> properties = issue975ExtractPropertiesFromTestResource();
ArraySchema imagesArray = (ArraySchema) properties.get("imagesArrayMap");
Schema imagesdMap = (Schema) imagesArray.getItems().getAdditionalProperties();
assertEquals(imagesdMap.get$ref(), "#/components/schemas/Image");
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class InlineModelResolverTest method resolveInlineArrayRequestBody.
@Test
public void resolveInlineArrayRequestBody() throws Exception {
OpenAPI openAPI = new OpenAPI();
ObjectSchema addressSchema = new ObjectSchema();
addressSchema.addProperties("street", new StringSchema());
ObjectSchema objectSchema = new ObjectSchema();
objectSchema.addProperties("address", addressSchema);
ArraySchema arraySchema = new ArraySchema();
arraySchema.items(objectSchema);
openAPI.path("/hello", new PathItem().get(new Operation().requestBody(new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(arraySchema))))));
new InlineModelResolver().flatten(openAPI);
RequestBody body = openAPI.getPaths().get("/hello").getGet().getRequestBody();
Schema schema = body.getContent().get("*/*").getSchema();
assertTrue(schema instanceof ArraySchema);
ArraySchema am = (ArraySchema) schema;
Schema inner = am.getItems();
assertTrue(inner.get$ref() != null);
assertEquals("#/components/schemas/hello_body", inner.get$ref());
Schema inline = openAPI.getComponents().getSchemas().get("hello_body");
assertNotNull(inline);
assertTrue(inline instanceof Schema);
Schema address = (Schema) inline.getProperties().get("address");
assertNotNull(address);
assertEquals("#/components/schemas/hello_address", address.get$ref());
Schema inlineProp = openAPI.getComponents().getSchemas().get("hello_address");
assertNotNull(inlineProp);
assertTrue(inlineProp instanceof Schema);
assertNotNull(inlineProp.getProperties().get("street"));
assertTrue(inlineProp.getProperties().get("street") instanceof StringSchema);
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class InlineModelResolverTest method resolveInlineArrayResponseWithTitle.
@Test
public void resolveInlineArrayResponseWithTitle() throws Exception {
OpenAPI openAPI = new OpenAPI();
ApiResponse apiResponse = new ApiResponse();
apiResponse.addExtension("x-foo", "bar");
apiResponse.description("it works!");
Map<String, Schema> properties = new HashMap<>();
properties.put("name", new StringSchema());
apiResponse.content(new Content().addMediaType("*/*", new MediaType().schema(new ArraySchema().items(new ObjectSchema().title("FooBar").properties(properties)))));
openAPI.path("/foo/baz", new PathItem().get(new Operation().responses(new ApiResponses().addApiResponse("200", apiResponse))));
new InlineModelResolver().flatten(openAPI);
ApiResponse response = openAPI.getPaths().get("/foo/baz").getGet().getResponses().get("200");
assertNotNull(response);
assertNotNull(response.getContent().get("*/*").getSchema());
Schema responseProperty = response.getContent().get("*/*").getSchema();
// no need to flatten more
assertTrue(responseProperty instanceof ArraySchema);
ArraySchema ap = (ArraySchema) responseProperty;
Schema p = ap.getItems();
assertNotNull(p);
assertEquals(p.get$ref(), "#/components/schemas/" + "FooBar");
Schema inline = openAPI.getComponents().getSchemas().get("FooBar");
assertNotNull(inline);
assertTrue(inline instanceof Schema);
assertNotNull(inline.getProperties().get("name"));
assertTrue(inline.getProperties().get("name") instanceof StringSchema);
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class InlineModelResolverTest method testArbitraryObjectModelWithArrayInlineWithoutTitle.
@Test
public void testArbitraryObjectModelWithArrayInlineWithoutTitle() {
OpenAPI openAPI = new OpenAPI();
openAPI.setComponents(new Components());
Schema items = new ObjectSchema();
items.setDefault("default");
items.setReadOnly(false);
items.setDescription("description");
items.setName("name");
items.addProperties("arbitrary", new ObjectSchema());
openAPI.getComponents().addSchemas("User", new ArraySchema().items(items).addRequiredItem("name"));
new InlineModelResolver().flatten(openAPI);
Schema model = openAPI.getComponents().getSchemas().get("User");
assertTrue(model instanceof ArraySchema);
ArraySchema am = (ArraySchema) model;
Schema inner = am.getItems();
assertTrue(inner.get$ref() != null);
Schema userInner = openAPI.getComponents().getSchemas().get("User_inner");
assertNotNull(userInner);
Schema inlineProp = (Schema) userInner.getProperties().get("arbitrary");
assertTrue(inlineProp instanceof ObjectSchema);
ObjectSchema op = (ObjectSchema) inlineProp;
assertNull(op.getProperties());
}
Aggregations