forked from loafle/openapi-generator-original
Add test case for InlineModelResolver: inline object response with additionalProperties (#1781)
* Add test case : inline object response with additionalProperties * Delete legacy test case
This commit is contained in:
parent
3ec90a86cb
commit
f96e64bd9e
@ -454,64 +454,29 @@ public class InlineModelResolverTest {
|
||||
ArraySchema responseSchema = (ArraySchema) mediaType.getSchema();
|
||||
assertEquals("#/components/schemas/resolveInlineArrayResponseWithTitleItems", responseSchema.getItems().get$ref());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveInlineObjectResponseWithAdditionalProperties() {
|
||||
OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/inline_model_resolver.yaml", null, new ParseOptions()).getOpenAPI();
|
||||
new InlineModelResolver().flatten(openAPI);
|
||||
|
||||
MediaType mediaType = openAPI
|
||||
.getPaths()
|
||||
.get("/resolve_inline_object_response_with_additional_properties")
|
||||
.getGet()
|
||||
.getResponses()
|
||||
.get("200")
|
||||
.getContent()
|
||||
.get("application/json");
|
||||
|
||||
assertTrue(mediaType.getSchema() instanceof ObjectSchema);
|
||||
assertTrue(mediaType.getSchema().getAdditionalProperties() instanceof ObjectSchema);
|
||||
|
||||
ObjectSchema additionalProperties = (ObjectSchema) mediaType.getSchema().getAdditionalProperties();
|
||||
assertTrue(additionalProperties.getProperties().get("resolve_inline_object_response_with_additional_properties") instanceof StringSchema);
|
||||
}
|
||||
|
||||
/*
|
||||
@Test
|
||||
public void testInlineMapResponse() throws Exception {
|
||||
OpenAPI openapi = new OpenAPI();
|
||||
|
||||
MapProperty schema = new MapProperty();
|
||||
schema.setAdditionalProperties(new StringSchema());
|
||||
schema.setVendorExtension("x-ext", "ext-prop");
|
||||
|
||||
openapi.path("/foo/baz", new Path()
|
||||
.get(new Operation()
|
||||
.response(200, new Response()
|
||||
.vendorExtension("x-foo", "bar")
|
||||
.description("it works!")
|
||||
.schema(schema))));
|
||||
new InlineModelResolver().flatten(openapi);
|
||||
Json.prettyPrint(openapi);
|
||||
|
||||
Response response = openapi.getPaths().get("/foo/baz").getGet().getResponses().get("200");
|
||||
|
||||
Property property = response.getSchema();
|
||||
assertTrue(property instanceof MapProperty);
|
||||
assertTrue(openapi.getComponents().getSchemas().size() == 0);
|
||||
assertEquals(1, property.getVendorExtensions().size());
|
||||
assertEquals("ext-prop", property.getVendorExtensions().get("x-ext"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInlineMapResponseWithObjectSchema() throws Exception {
|
||||
OpenAPI openapi = new OpenAPI();
|
||||
|
||||
MapProperty schema = new MapProperty();
|
||||
schema.setAdditionalProperties(new ObjectSchema()
|
||||
.addProperties("name", new StringSchema()));
|
||||
schema.setVendorExtension("x-ext", "ext-prop");
|
||||
|
||||
openapi.path("/foo/baz", new Path()
|
||||
.get(new Operation()
|
||||
.response(200, new Response()
|
||||
.vendorExtension("x-foo", "bar")
|
||||
.description("it works!")
|
||||
.schema(schema))));
|
||||
new InlineModelResolver().flatten(openapi);
|
||||
|
||||
Response response = openapi.getPaths().get("/foo/baz").getGet().getResponses().get("200");
|
||||
Property property = response.getSchema();
|
||||
assertTrue(property instanceof MapProperty);
|
||||
assertEquals(1, property.getVendorExtensions().size());
|
||||
assertEquals("ext-prop", property.getVendorExtensions().get("x-ext"));
|
||||
assertTrue(openapi.getComponents().getSchemas().size() == 1);
|
||||
|
||||
Model inline = openapi.getComponents().getSchemas().get("inline_response_200");
|
||||
assertTrue(inline instanceof ObjectSchema);
|
||||
ObjectSchema impl = (ObjectSchema) inline;
|
||||
assertNotNull(impl.getProperties().get("name"));
|
||||
assertTrue(impl.getProperties().get("name") instanceof StringSchema);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayResponse() {
|
||||
OpenAPI openapi = new OpenAPI();
|
||||
|
@ -121,6 +121,21 @@ paths:
|
||||
properties:
|
||||
array_response_with_title_property:
|
||||
type: string
|
||||
/resolve_inline_object_response_with_additional_properties:
|
||||
get:
|
||||
operationId: resolveInlineObjectResponseWithAdditionalProperties
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
additionalProperties:
|
||||
type: object
|
||||
properties:
|
||||
resolve_inline_object_response_with_additional_properties:
|
||||
type: string
|
||||
components:
|
||||
schemas:
|
||||
Users:
|
||||
|
Loading…
x
Reference in New Issue
Block a user