Add test case for InlineModelResolver: inline array schema (#1772)

* Add test case

* Delete legacy test case

* Add a test case: inline array schema

* Delete legacy test case

* Fix test yaml
This commit is contained in:
Akihito Nakano 2018-12-30 10:32:02 +09:00 committed by GitHub
parent 6a4f3385d8
commit 77b5cea518
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 68 deletions

View File

@ -274,59 +274,21 @@ public class InlineModelResolverTest {
assertTrue(model.getProperties().get("name") instanceof StringSchema); assertTrue(model.getProperties().get("name") instanceof StringSchema);
} }
/*
@Test @Test
public void resolveInlineArraySchemaWithTitle() throws Exception { public void resolveInlineArraySchemaWithTitle() {
OpenAPI openapi = new OpenAPI(); OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/inline_model_resolver.yaml", null, new ParseOptions()).getOpenAPI();
new InlineModelResolver().flatten(openAPI);
openapi.getComponents().addSchemas("User", new ArraySchema() assertTrue(openAPI.getComponents().getSchemas().get("Users") instanceof ArraySchema);
.items(new ObjectSchema()
.title("InnerUserTitle")
.access("access")
.readOnly(false)
.required(true)
.description("description")
.name("name")
.addProperties("street", new StringSchema())
.addProperties("city", new StringSchema())));
new InlineModelResolver().flatten(openapi); ArraySchema users = (ArraySchema) openAPI.getComponents().getSchemas().get("Users");
assertTrue(users.getItems() instanceof ObjectSchema);
Schema model = openapi.getComponents().getSchemas().get("User"); ObjectSchema user = (ObjectSchema) users.getItems();
assertTrue(model instanceof ArraySchema); assertEquals("User", user.getTitle());
assertTrue(user.getProperties().get("street") instanceof StringSchema);
Schema user = openapi.getComponents().getSchemas().get("InnerUserTitle"); assertTrue(user.getProperties().get("city") instanceof StringSchema);
assertNotNull(user);
assertEquals("description", user.getDescription());
} }
/*
@Test
public void resolveInlineArraySchemaWithoutTitle() throws Exception {
OpenAPI openapi = new OpenAPI();
openapi.getComponents().addSchemas("User", new ArraySchema()
.items(new ObjectSchema()
._default("default")
.access("access")
.readOnly(false)
.required(true)
.description("description")
.name("name")
.addProperties("street", new StringSchema())
.addProperties("city", new StringSchema())));
new InlineModelResolver().flatten(openapi);
Schema model = openapi.getComponents().getSchemas().get("User");
assertTrue(model instanceof ArraySchema);
Model user = openapi.getComponents().getSchemas().get("User_inner");
assertNotNull(user);
assertEquals("description", user.getDescription());
}
*/
@Test @Test
public void resolveInlineRequestBody() { public void resolveInlineRequestBody() {
@ -386,29 +348,21 @@ public class InlineModelResolverTest {
ObjectSchema impl = (ObjectSchema) body; ObjectSchema impl = (ObjectSchema) body;
assertNotNull(impl.getProperties().get("address")); assertNotNull(impl.getProperties().get("address"));
} }
*/
@Test @Test
public void notResolveNonModelBodyParameter() throws Exception { public void nonModelRequestBody() {
OpenAPI openapi = new OpenAPI(); OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/inline_model_resolver.yaml", null, new ParseOptions()).getOpenAPI();
new InlineModelResolver().flatten(openAPI);
openapi.path("/hello", new Path() MediaType mediaType = openAPI.getPaths().get("/non_model_request_body").getPost().getRequestBody().getContent().get("multipart/form-data");
.get(new Operation()
.parameter(new BodyParameter()
.name("body")
.schema(new ObjectSchema()
.type("string")
.format("binary")))));
new InlineModelResolver().flatten(openapi); assertTrue(mediaType.getSchema() instanceof BinarySchema);
assertEquals("string", mediaType.getSchema().getType());
Operation operation = openapi.getPaths().get("/hello").getGet(); assertEquals("binary", mediaType.getSchema().getFormat());
BodyParameter bp = (BodyParameter)operation.getParameters().get(0);
assertTrue(bp.getSchema() instanceof ObjectSchema);
ObjectSchema m = (ObjectSchema) bp.getSchema();
assertEquals("string", m.getType());
assertEquals("binary", m.getFormat());
} }
/*
@Test @Test
public void resolveInlineArrayBodyParameter() throws Exception { public void resolveInlineArrayBodyParameter() throws Exception {
OpenAPI openapi = new OpenAPI(); OpenAPI openapi = new OpenAPI();

View File

@ -41,5 +41,27 @@ paths:
responses: responses:
'200': '200':
description: OK description: OK
/non_model_request_body:
post:
requestBody:
content:
multipart/form-data:
schema:
type: string
format: binary
operationId: nonModelRequestBody
responses:
'200':
description: OK
components: components:
schemas: schemas:
Users:
type: array
items:
title: User
type: object
properties:
street:
type: string
city:
type: string