use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method resolveComposedSchema.
@Test
public void resolveComposedSchema(@Injectable final List<AuthorizationValue> auths) {
ParseOptions options = new ParseOptions();
options.setResolveCombinators(false);
options.setResolveFully(true);
OpenAPI openAPI = new OpenAPIV3Parser().readLocation("src/test/resources/oneof-anyof.yaml", auths, options).getOpenAPI();
assertTrue(openAPI.getPaths().get("/mixed-array").getGet().getResponses().get("200").getContent().get("application/json").getSchema() instanceof ArraySchema);
ArraySchema arraySchema = (ArraySchema) openAPI.getPaths().get("/mixed-array").getGet().getResponses().get("200").getContent().get("application/json").getSchema();
assertTrue(arraySchema.getItems() instanceof ComposedSchema);
ComposedSchema oneOf = (ComposedSchema) arraySchema.getItems();
assertEquals(oneOf.getOneOf().get(0).getType(), "string");
// System.out.println(openAPI.getPaths().get("/oneOf").getGet().getResponses().get("200").getContent().get("application/json").getSchema() );
assertTrue(openAPI.getPaths().get("/oneOf").getGet().getResponses().get("200").getContent().get("application/json").getSchema() instanceof ComposedSchema);
ComposedSchema oneOfSchema = (ComposedSchema) openAPI.getPaths().get("/oneOf").getGet().getResponses().get("200").getContent().get("application/json").getSchema();
assertEquals(oneOfSchema.getOneOf().get(0).getType(), "object");
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class SchemaProcessorTest method testProcessArraySchema.
@Test
public void testProcessArraySchema() throws Exception {
Schema property = new Schema();
SchemaProcessor propertyProcessor = new SchemaProcessor(cache, openAPI);
propertyProcessor.processSchema(property);
ArraySchema model = new ArraySchema();
model.setItems(property);
SchemaProcessor schemaProcessor = new SchemaProcessor(cache, openAPI);
schemaProcessor.processSchema(model);
assertEquals(property, model.getItems());
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class InlineModelResolverTest method testArbitraryObjectModelWithArrayInlineWithTitle.
@Test
public void testArbitraryObjectModelWithArrayInlineWithTitle() {
OpenAPI openAPI = new OpenAPI();
openAPI.setComponents(new Components());
Schema items = new ObjectSchema();
items.setTitle("InnerUserTitle");
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("InnerUserTitle");
assertNotNull(userInner);
Schema inlineProp = (Schema) userInner.getProperties().get("arbitrary");
assertTrue(inlineProp instanceof ObjectSchema);
ObjectSchema op = (ObjectSchema) inlineProp;
assertNull(op.getProperties());
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class InlineModelResolverTest method testArbitraryObjectResponseArray.
@Test
public void testArbitraryObjectResponseArray() {
OpenAPI openAPI = new OpenAPI();
openAPI.path("/foo/baz", new PathItem().get(new Operation().responses(new ApiResponses().addApiResponse("200", new ApiResponse().description("it works!").content(new Content().addMediaType("*/*", new MediaType().schema(new ArraySchema().items(new ObjectSchema()))))))));
new InlineModelResolver().flatten(openAPI);
ApiResponse response = openAPI.getPaths().get("/foo/baz").getGet().getResponses().get("200");
assertTrue(response.getContent().get("*/*").getSchema() instanceof ArraySchema);
ArraySchema arraySchema = (ArraySchema) response.getContent().get("*/*").getSchema();
Schema items = arraySchema.getItems();
assertTrue(items instanceof ObjectSchema);
ObjectSchema op = (ObjectSchema) items;
assertNull(op.getProperties());
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class InlineModelResolverTest method testArbitraryObjectResponseArrayInline.
@Test
public void testArbitraryObjectResponseArrayInline() {
OpenAPI openAPI = new OpenAPI();
ArraySchema arraySchema = new ArraySchema();
ObjectSchema objectSchema = new ObjectSchema();
objectSchema.addProperties("arbitrary", new ObjectSchema());
arraySchema.items(objectSchema);
ApiResponse apiResponse = new ApiResponse();
apiResponse.addExtension("x-foo", "bar");
apiResponse.description("it works!");
apiResponse.content(new Content().addMediaType("*/*", new MediaType().schema(arraySchema)));
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();
assertTrue(responseProperty instanceof ArraySchema);
ArraySchema arraySchema1 = (ArraySchema) responseProperty;
Schema items = arraySchema1.getItems();
assertNotNull(items);
assertEquals("#/components/schemas/inline_response_200", items.get$ref());
Schema inline = openAPI.getComponents().getSchemas().get("inline_response_200");
assertNotNull(inline);
assertTrue(inline instanceof Schema);
Schema inlineProp = (Schema) inline.getProperties().get("arbitrary");
assertNotNull(inlineProp);
assertTrue(inlineProp instanceof ObjectSchema);
assertNull(inlineProp.getProperties());
}
Aggregations