use of io.swagger.v3.parser.util.InlineModelResolver in project swagger-parser by swagger-api.
the class InlineModelResolverTest method resolveInlineRequestBodyWithTitle.
@Test
public void resolveInlineRequestBodyWithTitle() throws Exception {
OpenAPI openAPI = new OpenAPI();
ObjectSchema objectSchema = new ObjectSchema();
objectSchema.addProperties("street", new StringSchema());
objectSchema.addProperties("name", new StringSchema());
Schema addressModelItem = new Schema();
String addressModelName = "DetailedAddress";
addressModelItem.setTitle(addressModelName);
addressModelItem.addProperties("address", objectSchema);
openAPI.path("/hello", new PathItem().get(new Operation().requestBody(new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(addressModelItem))))));
new InlineModelResolver().flatten(openAPI);
Operation operation = openAPI.getPaths().get("/hello").getGet();
RequestBody requestBody = operation.getRequestBody();
assertTrue(requestBody.getContent().get("*/*").getSchema().get$ref() != null);
Schema body = openAPI.getComponents().getSchemas().get(addressModelName);
assertTrue(body instanceof Schema);
assertNotNull(body.getProperties().get("address"));
}
Aggregations