use of io.swagger.v3.oas.annotations.media.Content in project swagger-parser by swagger-api.
the class InlineModelResolverTest method resolveInlineRequestBody_stripsDotsFromPath.
@Test
public void resolveInlineRequestBody_stripsDotsFromPath() 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());
MediaType mediaType = new MediaType();
mediaType.setSchema(schema);
Content content = new Content();
content.addMediaType("*/*", mediaType);
RequestBody requestBody = new RequestBody();
requestBody.setContent(content);
Operation operation = new Operation();
operation.setRequestBody(requestBody);
PathItem pathItem = new PathItem();
pathItem.setGet(operation);
openAPI.path("/api/Cloud.Greet.Hello", pathItem);
new InlineModelResolver(true, true).flatten(openAPI);
Operation getOperation = openAPI.getPaths().get("/api/Cloud.Greet.Hello").getGet();
RequestBody body = getOperation.getRequestBody();
assertEquals("use dot as common word separator: as it occurs frequently on OData services", "#/components/schemas/ApiCloudGreetHelloBody", body.getContent().get("*/*").getSchema().get$ref());
Schema bodySchema = openAPI.getComponents().getSchemas().get("ApiCloudGreetHelloBody");
assertTrue(bodySchema instanceof Schema);
assertNotNull(bodySchema.getProperties().get("address"));
}
use of io.swagger.v3.oas.annotations.media.Content in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testCodegenIssue4555.
@Test
public void testCodegenIssue4555() throws Exception {
OpenAPIV3Parser parser = new OpenAPIV3Parser();
String yaml = "openapi: 3.0.0\n" + "info:\n" + " title: test\n" + " version: \"0.0.1\"\n" + "\n" + "paths:\n" + " '/contents/{id}':\n" + " parameters:\n" + " - name: id\n" + " in: path\n" + " description: test\n" + " required: true\n" + " schema:\n" + " type: integer\n" + " get:\n" + " description: test\n" + " responses:\n" + " '200':\n" + " description: OK\n" + " schema: null\n" + " $ref: '#/components/schemas/Content'\n" + "components:\n" + " schemas:\n" + " Content:\n" + " type: object\n" + " title: \t\ttest";
final SwaggerParseResult result = parser.readContents(yaml, null, null);
// can't parse with tabs!
assertNull(result.getOpenAPI());
}
use of io.swagger.v3.oas.annotations.media.Content in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIssue243.
@Test
public void testIssue243() {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + " version: 0.0.0\n" + " title: Simple API\n" + "paths:\n" + " /:\n" + " get:\n" + " responses:\n" + " '200':\n" + " description: OK\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " $ref: '#/components/schemas/Simple'\n" + "components:\n" + " schemas:\n" + " Simple:\n" + " type: string";
SwaggerParseResult result = new OpenAPIV3Parser().readContents(yaml, null, null);
assertNotNull(result.getOpenAPI());
}
use of io.swagger.v3.oas.annotations.media.Content in project syncope by apache.
the class SyncopeOpenApiCustomizer method customize.
@Override
public OpenAPIConfiguration customize(final OpenAPIConfiguration configuration) {
Map<String, Header> headers = new LinkedHashMap<>();
headers.put(RESTHeaders.ERROR_CODE, new Header().schema(new Schema<>().type("string")).description("Error code"));
headers.put(RESTHeaders.ERROR_INFO, new Header().schema(new Schema<>().type("string")).description("Error message"));
Content content = new Content();
content.addMediaType(javax.ws.rs.core.MediaType.APPLICATION_JSON, new MediaType().schema(new Schema<ErrorTO>()));
content.addMediaType(javax.ws.rs.core.MediaType.APPLICATION_XML, new MediaType().schema(new Schema<ErrorTO>()));
configuration.getOpenAPI().getComponents().addResponses("400", new ApiResponse().description("An error occurred; HTTP status code can vary depending on the actual error: " + "400, 403, 404, 409, 412").headers(headers).content(content));
return super.customize(configuration);
}
use of io.swagger.v3.oas.annotations.media.Content in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testCookieFormNoexplodeArray.
/**
* Test: cookie_form_noexplode_array
* Expected parameters sent:
* color: color=blue,black,brown
* Expected response: {"color":["blue","black","brown"]}
* @throws Exception
*/
@Test
public void testCookieFormNoexplodeArray() throws Exception {
routerFactory.addHandlerByOperationId("cookie_form_noexplode_array", routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
RequestParameter color_cookie = params.cookieParameter("color");
assertNotNull(color_cookie);
assertTrue(color_cookie.isArray());
res.put("color", new JsonArray(color_cookie.getArray().stream().map(param -> param.getString()).collect(Collectors.toList())));
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
CountDownLatch latch = new CountDownLatch(1);
List<Object> color_cookie;
color_cookie = new ArrayList<>();
color_cookie.add("blue");
color_cookie.add("black");
color_cookie.add("brown");
startServer();
apiClient.cookieFormNoexplodeArray(color_cookie, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
assertEquals(200, ar.result().statusCode());
assertTrue("Expected: " + new JsonObject("{\"color\":[\"blue\",\"black\",\"brown\"]}").encode() + " Actual: " + ar.result().bodyAsJsonObject().encode(), new JsonObject("{\"color\":[\"blue\",\"black\",\"brown\"]}").equals(ar.result().bodyAsJsonObject()));
} else {
assertTrue(ar.cause().getMessage(), false);
}
latch.countDown();
});
awaitLatch(latch);
}
Aggregations