@Test public void testInlineMapResponse() throws Exception { Swagger swagger = new Swagger(); MapProperty schema = new MapProperty(); schema.setAdditionalProperties(new StringProperty()); swagger.path( "/foo/baz", new Path() .get( new Operation() .response( 200, new Response() .vendorExtension("x-foo", "bar") .description("it works!") .schema(schema)))); new InlineModelResolver().flatten(swagger); Json.prettyPrint(swagger); Response response = swagger.getPaths().get("/foo/baz").getGet().getResponses().get("200"); Property property = response.getSchema(); assertTrue(property instanceof MapProperty); assertTrue(swagger.getDefinitions().size() == 0); }
@Test public void testInlineMapResponseWithObjectProperty() throws Exception { Swagger swagger = new Swagger(); MapProperty schema = new MapProperty(); schema.setAdditionalProperties(new ObjectProperty().property("name", new StringProperty())); swagger.path( "/foo/baz", new Path() .get( new Operation() .response( 200, new Response() .vendorExtension("x-foo", "bar") .description("it works!") .schema(schema)))); new InlineModelResolver().flatten(swagger); Response response = swagger.getPaths().get("/foo/baz").getGet().getResponses().get("200"); Property property = response.getSchema(); assertTrue(property instanceof RefProperty); Model inline = swagger.getDefinitions().get("inline_response_200"); assertTrue(inline instanceof ModelImpl); ModelImpl impl = (ModelImpl) inline; Property innerProperty = impl.getAdditionalProperties(); assertTrue(innerProperty instanceof ObjectProperty); ObjectProperty obj = (ObjectProperty) innerProperty; Property name = obj.getProperties().get("name"); assertTrue(name instanceof StringProperty); }