use of io.swagger.v3.oas.models.media.Content in project vertx-web by vert-x3.
the class OpenAPI3ValidationTest method testCircularReferences.
@Test
@Ignore
public void testCircularReferences() throws Exception {
Operation op = testSpec.getPaths().get("/circularReferences").getPost();
OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
loadHandlers("/circularReferences", HttpMethod.POST, false, validationHandler, (routingContext) -> {
RequestParameters params = routingContext.get("parsedParameters");
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("Content-Type", "application/json").end(params.body().getJsonObject().encode());
});
JsonObject obj = new JsonObject("{\n" + " \"a\": {\n" + " \"a\": [\n" + " {\n" + " \"a\": {\n" + " \"a\": []\n" + " },\n" + " \"b\": \"hi\",\n" + " \"c\": 10\n" + " }\n" + " ]\n" + " },\n" + " \"b\": \"hello\",\n" + " \"c\": 6\n" + "}");
testRequestWithJSON(HttpMethod.POST, "/circularReferences", obj, 200, "OK", obj);
}
use of io.swagger.v3.oas.models.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.models.media.Content in project gravitee-management-rest-api by gravitee-io.
the class SwaggerServiceImpl method transformV3.
private OpenAPI transformV3(String content, PageConfigurationEntity config) {
SwaggerParseResult result = new OpenAPIV3Parser().readContents(content, null, null);
if (result != null && config != null && config.getTryItURL() != null) {
URI newURI = URI.create(config.getTryItURL());
result.getOpenAPI().getServers().forEach(server -> {
try {
server.setUrl(new URI(newURI.getScheme(), newURI.getUserInfo(), newURI.getHost(), newURI.getPort(), newURI.getPath(), newURI.getQuery(), newURI.getFragment()).toString());
} catch (URISyntaxException e) {
logger.error(e.getMessage(), e);
}
});
}
if (result != null) {
return result.getOpenAPI();
} else {
return null;
}
}
use of io.swagger.v3.oas.models.media.Content in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testPathLabelExplodeArray.
/**
* Test: path_label_explode_array
* Expected parameters sent:
* color: .blue.black.brown
* Expected response: {"color":["blue","black","brown"]}
* @throws Exception
*/
@Test
public void testPathLabelExplodeArray() throws Exception {
routerFactory.addHandlerByOperationId("path_label_explode_array", routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
RequestParameter color_path = params.pathParameter("color");
assertNotNull(color_path);
assertTrue(color_path.isArray());
res.put("color", new JsonArray(color_path.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_path;
color_path = new ArrayList<>();
color_path.add("blue");
color_path.add("black");
color_path.add("brown");
startServer();
apiClient.pathLabelExplodeArray(color_path, (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);
}
use of io.swagger.v3.oas.models.media.Content in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testPathSimpleNoexplodeArray.
/**
* Test: path_simple_noexplode_array
* Expected parameters sent:
* color: blue,black,brown
* Expected response: {"color":["blue","black","brown"]}
* @throws Exception
*/
@Test
public void testPathSimpleNoexplodeArray() throws Exception {
routerFactory.addHandlerByOperationId("path_simple_noexplode_array", routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
RequestParameter color_path = params.pathParameter("color");
assertNotNull(color_path);
assertTrue(color_path.isArray());
res.put("color", new JsonArray(color_path.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_path;
color_path = new ArrayList<>();
color_path.add("blue");
color_path.add("black");
color_path.add("brown");
startServer();
apiClient.pathSimpleNoexplodeArray(color_path, (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