use of io.swagger.v3.parser.util.InlineModelResolver 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.parser.util.InlineModelResolver in project swagger-parser by swagger-api.
the class InlineModelResolverTest method resolveInlineArrayModelWithoutTitle.
@Test
public void resolveInlineArrayModelWithoutTitle() throws Exception {
OpenAPI openAPI = new OpenAPI();
openAPI.setComponents(new Components());
Schema objectSchema = new ObjectSchema();
objectSchema.setDefault("default");
objectSchema.setReadOnly(false);
objectSchema.setDescription("description");
objectSchema.setName("name");
objectSchema.addProperties("street", new StringSchema());
objectSchema.addProperties("city", new StringSchema());
ArraySchema arraySchema = new ArraySchema();
List<String> required = new LinkedList<>();
required.add("name");
arraySchema.setRequired(required);
arraySchema.setItems(objectSchema);
openAPI.getComponents().addSchemas("User", arraySchema);
new InlineModelResolver().flatten(openAPI);
Schema model = openAPI.getComponents().getSchemas().get("User");
assertTrue(model instanceof ArraySchema);
Schema user = openAPI.getComponents().getSchemas().get("User_inner");
assertNotNull(user);
assertEquals("description", user.getDescription());
}
use of io.swagger.v3.parser.util.InlineModelResolver 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.parser.util.InlineModelResolver 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.parser.util.InlineModelResolver 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