use of io.swagger.v3.oas.models.PathItem in project swagger-parser by swagger-api.
the class InlineModelResolverTest method testArrayResponse.
@Test
public void testArrayResponse() {
OpenAPI openAPI = new OpenAPI();
ObjectSchema objectSchema = new ObjectSchema();
objectSchema.addProperties("name", new StringSchema());
ArraySchema schema = new ArraySchema();
schema.setItems(objectSchema);
ApiResponse apiResponse = new ApiResponse();
apiResponse.addExtension("x-foo", "bar");
apiResponse.setDescription("it works!");
apiResponse.setContent(new Content().addMediaType("*/*", new MediaType().schema(schema)));
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");
assertTrue(response.getContent().get("*/*").getSchema() instanceof ArraySchema);
ArraySchema am = (ArraySchema) response.getContent().get("*/*").getSchema();
Schema items = am.getItems();
assertTrue(items.get$ref() != null);
assertEquals(items.get$ref(), "#/components/schemas/inline_response_200");
Schema inline = openAPI.getComponents().getSchemas().get("inline_response_200");
assertTrue(inline instanceof Schema);
assertNotNull(inline.getProperties().get("name"));
assertTrue(inline.getProperties().get("name") instanceof StringSchema);
}
use of io.swagger.v3.oas.models.PathItem in project swagger-parser by swagger-api.
the class InlineModelResolverTest method notResolveNonModelRequestBody.
@Test
public void notResolveNonModelRequestBody() throws Exception {
OpenAPI openAPI = new OpenAPI();
openAPI.path("/hello", new PathItem().get(new Operation().requestBody(new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(new Schema().type("string").format("binary")))))));
new InlineModelResolver().flatten(openAPI);
Operation operation = openAPI.getPaths().get("/hello").getGet();
RequestBody body = operation.getRequestBody();
assertTrue(body.getContent().get("*/*").getSchema() instanceof Schema);
Schema schema = body.getContent().get("*/*").getSchema();
assertEquals("string", schema.getType());
assertEquals("binary", schema.getFormat());
}
use of io.swagger.v3.oas.models.PathItem in project swagger-parser by swagger-api.
the class InlineModelResolverTest method testArbitraryObjectBodyParamArrayInline.
@Test
public void testArbitraryObjectBodyParamArrayInline() {
OpenAPI openAPI = new OpenAPI();
ObjectSchema items = new ObjectSchema();
items.addProperties("arbitrary", new ObjectSchema());
openAPI.path("/hello", new PathItem().get(new Operation().requestBody(new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(new ArraySchema().items(items)))))));
new InlineModelResolver().flatten(openAPI);
RequestBody requestBody = openAPI.getPaths().get("/hello").getGet().getRequestBody();
Schema schema = requestBody.getContent().get("*/*").getSchema();
assertTrue(schema instanceof ArraySchema);
ArraySchema arraySchema = (ArraySchema) schema;
Schema inner = arraySchema.getItems();
assertTrue(inner.get$ref() != null);
assertEquals(inner.get$ref(), "#/components/schemas/hello_body");
Schema inline = openAPI.getComponents().getSchemas().get("hello_body");
assertNotNull(inline);
Schema p = (Schema) inline.getProperties().get("arbitrary");
assertNotNull(p);
assertTrue(p instanceof ObjectSchema);
}
use of io.swagger.v3.oas.models.PathItem in project swagger-parser by swagger-api.
the class InlineModelResolverTest method resolveInlineParameter.
@Test
public void resolveInlineParameter() throws Exception {
OpenAPI openAPI = new OpenAPI();
ObjectSchema objectSchema = new ObjectSchema();
objectSchema.addProperties("street", new StringSchema());
Schema schema = new Schema();
schema.addProperties("address", objectSchema);
schema.addProperties("name", new StringSchema());
Parameter parameter = new Parameter();
parameter.setName("name");
parameter.setSchema(schema);
List parameters = new ArrayList();
parameters.add(parameter);
Operation operation = new Operation();
operation.setParameters(parameters);
PathItem pathItem = new PathItem();
pathItem.setGet(operation);
openAPI.path("/hello", pathItem);
new InlineModelResolver().flatten(openAPI);
Operation getOperation = openAPI.getPaths().get("/hello").getGet();
Parameter param = getOperation.getParameters().get(0);
assertTrue(param.getSchema().get$ref() != null);
Schema bodySchema = openAPI.getComponents().getSchemas().get("name");
assertTrue(bodySchema instanceof Schema);
assertNotNull(bodySchema.getProperties().get("address"));
}
use of io.swagger.v3.oas.models.PathItem in project swagger-parser by swagger-api.
the class InlineModelResolverTest method testArbitraryObjectResponse.
@Test
public void testArbitraryObjectResponse() {
OpenAPI openAPI = new OpenAPI();
openAPI.path("/foo/bar", new PathItem().get(new Operation().responses(new ApiResponses().addApiResponse("200", new ApiResponse().description("it works!").content(new Content().addMediaType("*/*", new MediaType().schema(new ObjectSchema())))))));
new InlineModelResolver().flatten(openAPI);
Map<String, ApiResponse> responses = openAPI.getPaths().get("/foo/bar").getGet().getResponses();
ApiResponse response = responses.get("200");
assertNotNull(response);
assertTrue(response.getContent().get("*/*").getSchema() instanceof ObjectSchema);
ObjectSchema op = (ObjectSchema) response.getContent().get("*/*").getSchema();
assertNull(op.getProperties());
}
Aggregations