use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testArrayRemoteModelProperty.
private void testArrayRemoteModelProperty(String remoteRef) {
final OpenAPI swagger = new OpenAPI();
swagger.components(new Components().addSchemas("Sample", new Schema().addProperties("remoteRef", new ArraySchema().items(new Schema().$ref(remoteRef)))));
final OpenAPI resolved = new OpenAPIResolver(swagger, null).resolve();
final Schema prop = (Schema) resolved.getComponents().getSchemas().get("Sample").getProperties().get("remoteRef");
assertTrue(prop instanceof ArraySchema);
final ArraySchema ap = (ArraySchema) prop;
assertEquals(ap.getItems().get$ref(), "#/components/schemas/Tag");
assertNotNull(swagger.getComponents().getSchemas().get("Tag"));
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIssue975_array.
@Test(description = "Test that relative references are resolvable when property is an array with a reference to a relative file.")
public void testIssue975_array() {
Map<String, Schema> properties = issue975ExtractPropertiesFromTestResource();
ArraySchema imagesArray = (ArraySchema) properties.get("imagesArray");
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 testIssue75.
@Test
public void testIssue75() {
OpenAPIV3Parser parser = new OpenAPIV3Parser();
final OpenAPI openAPI = parser.read("src/test/resources/issue99.yaml");
RequestBody body = openAPI.getPaths().get("/albums").getPost().getRequestBody();
Schema model = body.getContent().get("application/json").getSchema();
assertNotNull(model);
assertTrue(model instanceof ArraySchema);
ArraySchema am = (ArraySchema) model;
assertTrue(am.getItems() instanceof ByteArraySchema);
assertEquals(am.getItems().getFormat(), "byte");
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testLoadRecursiveExternalDef.
@Test
public void testLoadRecursiveExternalDef() throws Exception {
OpenAPIV3Parser parser = new OpenAPIV3Parser();
final OpenAPI openAPI = parser.read("src/test/resources/file-reference-to-recursive-defs/b.yaml");
Map<String, Schema> definitions = openAPI.getComponents().getSchemas();
assertEquals((((ArraySchema) definitions.get("v").getProperties().get("children")).getItems()).get$ref(), "#/components/schemas/v");
assertTrue(definitions.containsKey("y"));
assertEquals((((ArraySchema) definitions.get("x").getProperties().get("children")).getItems()).get$ref(), "#/components/schemas/y");
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testPetstore.
@Test
public void testPetstore() throws Exception {
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = parser.readLocation("src/test/resources/petstore.yaml", null, options);
assertNotNull(result);
assertTrue(result.getMessages().size() == 2);
OpenAPI openAPI = result.getOpenAPI();
Map<String, Schema> definitions = openAPI.getComponents().getSchemas();
Set<String> expectedDefinitions = new HashSet<String>();
expectedDefinitions.add("User");
expectedDefinitions.add("Category");
expectedDefinitions.add("Pet");
expectedDefinitions.add("Tag");
expectedDefinitions.add("Order");
expectedDefinitions.add("PetArray");
assertEquals(definitions.keySet(), expectedDefinitions);
Schema petModel = definitions.get("Pet");
Set<String> expectedPetProps = new HashSet<String>();
expectedPetProps.add("id");
expectedPetProps.add("category");
expectedPetProps.add("name");
expectedPetProps.add("photoUrls");
expectedPetProps.add("tags");
expectedPetProps.add("status");
assertEquals(petModel.getProperties().keySet(), expectedPetProps);
ArraySchema petArrayModel = (ArraySchema) definitions.get("PetArray");
assertEquals(petArrayModel.getType(), "array");
Schema refProp = petArrayModel.getItems();
assertEquals(refProp.get$ref(), "#/components/schemas/Pet");
assertNull(petArrayModel.getProperties());
}
Aggregations