Skip to content

Commit 7f02383

Browse files
authored
Add test case for InlineModelResolver: inline array schema (OpenAPITools#1772)
* Add test case * Delete legacy test case * Add a test case: inline array schema * Delete legacy test case * Fix test yaml
1 parent 268727a commit 7f02383

File tree

2 files changed

+44
-68
lines changed

2 files changed

+44
-68
lines changed

modules/openapi-generator/src/test/java/org/openapitools/codegen/InlineModelResolverTest.java

Lines changed: 21 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -274,60 +274,22 @@ public void testInlineResponseModelWithTitle() throws Exception {
274274
assertTrue(model.getProperties().get("name") instanceof StringSchema);
275275
}
276276

277-
278-
279-
/*
280277
@Test
281-
public void resolveInlineArraySchemaWithTitle() throws Exception {
282-
OpenAPI openapi = new OpenAPI();
283-
284-
openapi.getComponents().addSchemas("User", new ArraySchema()
285-
.items(new ObjectSchema()
286-
.title("InnerUserTitle")
287-
.access("access")
288-
.readOnly(false)
289-
.required(true)
290-
.description("description")
291-
.name("name")
292-
.addProperties("street", new StringSchema())
293-
.addProperties("city", new StringSchema())));
278+
public void resolveInlineArraySchemaWithTitle() {
279+
OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/inline_model_resolver.yaml", null, new ParseOptions()).getOpenAPI();
280+
new InlineModelResolver().flatten(openAPI);
294281

295-
new InlineModelResolver().flatten(openapi);
282+
assertTrue(openAPI.getComponents().getSchemas().get("Users") instanceof ArraySchema);
296283

297-
Schema model = openapi.getComponents().getSchemas().get("User");
298-
assertTrue(model instanceof ArraySchema);
284+
ArraySchema users = (ArraySchema) openAPI.getComponents().getSchemas().get("Users");
285+
assertTrue(users.getItems() instanceof ObjectSchema);
299286

300-
Schema user = openapi.getComponents().getSchemas().get("InnerUserTitle");
301-
assertNotNull(user);
302-
assertEquals("description", user.getDescription());
287+
ObjectSchema user = (ObjectSchema) users.getItems();
288+
assertEquals("User", user.getTitle());
289+
assertTrue(user.getProperties().get("street") instanceof StringSchema);
290+
assertTrue(user.getProperties().get("city") instanceof StringSchema);
303291
}
304-
/*
305-
@Test
306-
public void resolveInlineArraySchemaWithoutTitle() throws Exception {
307-
OpenAPI openapi = new OpenAPI();
308-
309-
openapi.getComponents().addSchemas("User", new ArraySchema()
310-
.items(new ObjectSchema()
311-
._default("default")
312-
.access("access")
313-
.readOnly(false)
314-
.required(true)
315-
.description("description")
316-
.name("name")
317-
.addProperties("street", new StringSchema())
318-
.addProperties("city", new StringSchema())));
319-
320-
new InlineModelResolver().flatten(openapi);
321-
322-
Schema model = openapi.getComponents().getSchemas().get("User");
323-
assertTrue(model instanceof ArraySchema);
324-
325-
Model user = openapi.getComponents().getSchemas().get("User_inner");
326-
assertNotNull(user);
327-
assertEquals("description", user.getDescription());
328-
}
329-
*/
330-
292+
331293
@Test
332294
public void resolveInlineRequestBody() {
333295
OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/inline_model_resolver.yaml", null, new ParseOptions()).getOpenAPI();
@@ -385,30 +347,22 @@ public void resolveInlineBodyParameterWithTitle() throws Exception {
385347
386348
ObjectSchema impl = (ObjectSchema) body;
387349
assertNotNull(impl.getProperties().get("address"));
388-
}
350+
}
351+
*/
389352

390353
@Test
391-
public void notResolveNonModelBodyParameter() throws Exception {
392-
OpenAPI openapi = new OpenAPI();
393-
394-
openapi.path("/hello", new Path()
395-
.get(new Operation()
396-
.parameter(new BodyParameter()
397-
.name("body")
398-
.schema(new ObjectSchema()
399-
.type("string")
400-
.format("binary")))));
354+
public void nonModelRequestBody() {
355+
OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/inline_model_resolver.yaml", null, new ParseOptions()).getOpenAPI();
356+
new InlineModelResolver().flatten(openAPI);
401357

402-
new InlineModelResolver().flatten(openapi);
358+
MediaType mediaType = openAPI.getPaths().get("/non_model_request_body").getPost().getRequestBody().getContent().get("multipart/form-data");
403359

404-
Operation operation = openapi.getPaths().get("/hello").getGet();
405-
BodyParameter bp = (BodyParameter)operation.getParameters().get(0);
406-
assertTrue(bp.getSchema() instanceof ObjectSchema);
407-
ObjectSchema m = (ObjectSchema) bp.getSchema();
408-
assertEquals("string", m.getType());
409-
assertEquals("binary", m.getFormat());
360+
assertTrue(mediaType.getSchema() instanceof BinarySchema);
361+
assertEquals("string", mediaType.getSchema().getType());
362+
assertEquals("binary", mediaType.getSchema().getFormat());
410363
}
411364

365+
/*
412366
@Test
413367
public void resolveInlineArrayBodyParameter() throws Exception {
414368
OpenAPI openapi = new OpenAPI();

modules/openapi-generator/src/test/resources/3_0/inline_model_resolver.yaml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,27 @@ paths:
4141
responses:
4242
'200':
4343
description: OK
44+
/non_model_request_body:
45+
post:
46+
requestBody:
47+
content:
48+
multipart/form-data:
49+
schema:
50+
type: string
51+
format: binary
52+
operationId: nonModelRequestBody
53+
responses:
54+
'200':
55+
description: OK
4456
components:
45-
schemas:
57+
schemas:
58+
Users:
59+
type: array
60+
items:
61+
title: User
62+
type: object
63+
properties:
64+
street:
65+
type: string
66+
city:
67+
type: string

0 commit comments

Comments
 (0)