use of io.swagger.v3.oas.models.media.Content in project ballerina by ballerina-lang.
the class SwaggerConverterUtils method getTopLevelNodeFromBallerinaFile.
/**
* Generate ballerina fine from the String definition.
*
* @param bFile ballerina string definition
* @return ballerina file created from ballerina string definition
* @throws IOException IO exception
*/
public static BLangCompilationUnit getTopLevelNodeFromBallerinaFile(BFile bFile) throws IOException {
String filePath = bFile.getFilePath();
String fileName = bFile.getFileName();
String content = bFile.getContent();
Path fileRoot = Paths.get(filePath);
org.wso2.ballerinalang.compiler.tree.BLangPackage model;
// Sometimes we are getting Ballerina content without a file in the file-system.
if (!Files.exists(Paths.get(filePath, fileName))) {
BallerinaFile ballerinaFile = ParserUtils.getBallerinaFileForContent(fileRoot, fileName, content, CompilerPhase.CODE_ANALYZE);
model = ballerinaFile.getBLangPackage();
} else {
BallerinaFile ballerinaFile = ParserUtils.getBallerinaFile(filePath, fileName);
model = ballerinaFile.getBLangPackage();
}
final Map<String, ModelPackage> modelPackage = new HashMap<>();
ParserUtils.loadPackageMap(Constants.CURRENT_PACKAGE_NAME, model, modelPackage);
Optional<BLangCompilationUnit> compilationUnit = model.getCompilationUnits().stream().filter(compUnit -> fileName.equals(compUnit.getName())).findFirst();
return compilationUnit.orElse(null);
}
use of io.swagger.v3.oas.models.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);
}
use of io.swagger.v3.oas.models.media.Content in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testPathMultiLabelMatrix.
/**
* Test: path_multi_label_matrix
* Expected parameters sent:
* color_label: .blue.black.brown
* color_matrix: ;R=100;G=200;B=150
* Expected response: {"color_label":["blue","black","brown"],"color_matrix":{"R":"100","G":"200","B":"150"}}
* @throws Exception
*/
@Test
public void testPathMultiLabelMatrix() throws Exception {
routerFactory.addHandlerByOperationId("path_multi_label_matrix", routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
RequestParameter colorLabel_path = params.pathParameter("color_label");
assertNotNull(colorLabel_path);
assertTrue(colorLabel_path.isArray());
res.put("color_label", new JsonArray(colorLabel_path.getArray().stream().map(param -> param.getString()).collect(Collectors.toList())));
RequestParameter colorMatrix_path = params.pathParameter("color_matrix");
assertNotNull(colorMatrix_path);
assertTrue(colorMatrix_path.isObject());
Map<String, String> map = new HashMap<>();
for (String key : colorMatrix_path.getObjectKeys()) map.put(key, colorMatrix_path.getObjectValue(key).getString());
res.put("color_matrix", map);
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
CountDownLatch latch = new CountDownLatch(1);
List<Object> colorLabel_path;
colorLabel_path = new ArrayList<>();
colorLabel_path.add("blue");
colorLabel_path.add("black");
colorLabel_path.add("brown");
Map<String, Object> colorMatrix_path;
colorMatrix_path = new HashMap<>();
colorMatrix_path.put("R", "100");
colorMatrix_path.put("G", "200");
colorMatrix_path.put("B", "150");
startServer();
apiClient.pathMultiLabelMatrix(colorLabel_path, colorMatrix_path, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
assertEquals(200, ar.result().statusCode());
assertTrue("Expected: " + new JsonObject("{\"color_label\":[\"blue\",\"black\",\"brown\"],\"color_matrix\":{\"R\":\"100\",\"G\":\"200\",\"B\":\"150\"}}").encode() + " Actual: " + ar.result().bodyAsJsonObject().encode(), new JsonObject("{\"color_label\":[\"blue\",\"black\",\"brown\"],\"color_matrix\":{\"R\":\"100\",\"G\":\"200\",\"B\":\"150\"}}").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 testCookieFormExplodeArray.
/**
* Test: cookie_form_explode_array
* Expected parameters sent:
* color: color=blue&color=black&color=brown
* Expected response: {"color":["blue","black","brown"]}
* @throws Exception
*/
@Test
public void testCookieFormExplodeArray() throws Exception {
routerFactory.addHandlerByOperationId("cookie_form_explode_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.cookieFormExplodeArray(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);
}
use of io.swagger.v3.oas.models.media.Content in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testQueryFormNoexplodeArray.
/**
* Test: query_form_noexplode_array
* Expected parameters sent:
* color: color=blue,black,brown
* Expected response: {"color":["blue","black","brown"]}
* @throws Exception
*/
@Test
public void testQueryFormNoexplodeArray() throws Exception {
routerFactory.addHandlerByOperationId("query_form_noexplode_array", routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
RequestParameter color_query = params.queryParameter("color");
assertNotNull(color_query);
assertTrue(color_query.isArray());
res.put("color", new JsonArray(color_query.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_query;
color_query = new ArrayList<>();
color_query.add("blue");
color_query.add("black");
color_query.add("brown");
startServer();
apiClient.queryFormNoexplodeArray(color_query, (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