use of org.apache.cxf.jaxrs.json.basic.JsonMapObject in project cxf by apache.
the class JwsCompactConsumer method getJwsHeaders.
public JwsHeaders getJwsHeaders() {
if (jwsHeaders == null) {
JsonMapObject joseHeaders = reader.fromJsonToJsonObject(headersJson);
if (joseHeaders.getUpdateCount() != null) {
LOG.warning("Duplicate headers have been detected");
throw new JwsException(JwsException.Error.INVALID_COMPACT_JWS);
}
jwsHeaders = new JwsHeaders(joseHeaders.asMap());
}
return jwsHeaders;
}
use of org.apache.cxf.jaxrs.json.basic.JsonMapObject in project cxf by apache.
the class SwaggerToOpenApiConversionTest method verifyBookStoreIdGet.
private void verifyBookStoreIdGet(JsonMapObject bookstore) {
JsonMapObject bookstoreGet = bookstore.getJsonMapProperty("get");
assertEquals(6, bookstoreGet.size());
List<String> bookstoreGetTags = bookstoreGet.getListStringProperty("tags");
assertEquals(1, bookstoreGetTags.size());
assertEquals("bookstore", bookstoreGetTags.get(0));
assertEquals("Get book by Id", bookstoreGet.getProperty("summary"));
assertEquals("Get book by Id", bookstoreGet.getProperty("description"));
assertEquals("getBook", bookstoreGet.getProperty("operationId"));
List<Map<String, Object>> bookstoreGetParams = bookstoreGet.getListMapProperty("parameters");
assertEquals(1, bookstoreGetParams.size());
JsonMapObject firstParam = new JsonMapObject(bookstoreGetParams.get(0));
assertEquals(5, firstParam.size());
assertEquals("id", firstParam.getProperty("name"));
assertEquals("path", firstParam.getProperty("in"));
assertEquals("id", firstParam.getProperty("description"));
assertTrue(firstParam.getBooleanProperty("required"));
JsonMapObject schema = firstParam.getJsonMapProperty("schema");
assertEquals(2, schema.size());
assertEquals("integer", schema.getProperty("type"));
assertEquals("int64", schema.getProperty("format"));
JsonMapObject responses = bookstoreGet.getJsonMapProperty("responses");
assertEquals(1, responses.size());
JsonMapObject okResp = responses.getJsonMapProperty("200");
assertEquals(2, okResp.size());
assertEquals("successful operation", okResp.getProperty("description"));
JsonMapObject content = okResp.getJsonMapProperty("content");
assertEquals(1, content.size());
JsonMapObject jsonResp = content.getJsonMapProperty("application/json");
assertEquals(1, jsonResp.size());
JsonMapObject jsonRespSchema = jsonResp.getJsonMapProperty("schema");
assertEquals(1, jsonRespSchema.size());
assertEquals("#components/schemas/Book", jsonRespSchema.getProperty("$ref"));
}
use of org.apache.cxf.jaxrs.json.basic.JsonMapObject in project cxf by apache.
the class SwaggerToOpenApiConversionTest method verifyBookStoreIdDelete.
private void verifyBookStoreIdDelete(JsonMapObject bookstore) {
JsonMapObject bookstoreDel = bookstore.getJsonMapProperty("delete");
assertEquals(6, bookstoreDel.size());
List<String> bookstoreDelTags = bookstoreDel.getListStringProperty("tags");
assertEquals(1, bookstoreDelTags.size());
assertEquals("bookstore", bookstoreDelTags.get(0));
assertEquals("Delete book", bookstoreDel.getProperty("summary"));
assertEquals("Delete book", bookstoreDel.getProperty("description"));
assertEquals("delete", bookstoreDel.getProperty("operationId"));
List<Map<String, Object>> bookstoreDelParams = bookstoreDel.getListMapProperty("parameters");
assertEquals(1, bookstoreDelParams.size());
JsonMapObject firstParam = new JsonMapObject(bookstoreDelParams.get(0));
assertEquals(5, firstParam.size());
assertEquals("id", firstParam.getProperty("name"));
assertEquals("path", firstParam.getProperty("in"));
assertEquals("id", firstParam.getProperty("description"));
assertTrue(firstParam.getBooleanProperty("required"));
JsonMapObject schema = firstParam.getJsonMapProperty("schema");
assertEquals(1, schema.size());
assertEquals("string", schema.getProperty("type"));
JsonMapObject responses = bookstoreDel.getJsonMapProperty("responses");
assertEquals(1, responses.size());
JsonMapObject okResp = responses.getJsonMapProperty("default");
assertEquals(1, okResp.size());
assertEquals("successful operation", okResp.getProperty("description"));
}
use of org.apache.cxf.jaxrs.json.basic.JsonMapObject in project cxf by apache.
the class SwaggerToOpenApiConversionTest method testOpenApiJSON.
@Test
public void testOpenApiJSON() throws Exception {
final WebClient client = createWebClient("/openapi.json");
String openApiResponse = client.get(String.class);
JsonMapObject openApiJson = new JsonMapObjectReaderWriter().fromJsonToJsonObject(openApiResponse);
assertEquals(6, openApiJson.size());
// version
assertEquals("3.0.0", openApiJson.getProperty("openapi"));
// servers
List<Map<String, Object>> servers = openApiJson.getListMapProperty("servers");
assertEquals(1, servers.size());
assertEquals(1, servers.get(0).size());
assertEquals("http://localhost:" + PORT, servers.get(0).get("url"));
// info
JsonMapObject info = openApiJson.getJsonMapProperty("info");
assertEquals(4, info.size());
assertEquals(DESCRIPTION, info.getProperty("description"));
assertEquals(TITLE, info.getProperty("title"));
JsonMapObject contact = info.getJsonMapProperty("contact");
assertEquals(1, contact.size());
assertEquals(CONTACT, contact.getProperty("name"));
JsonMapObject license = info.getJsonMapProperty("license");
assertEquals(2, license.size());
assertEquals(LICENSE, license.getProperty("name"));
assertEquals(LICENSE_URL, license.getProperty("url"));
// tags
List<Map<String, Object>> tags = openApiJson.getListMapProperty("tags");
assertEquals(1, tags.size());
assertEquals(1, tags.get(0).size());
assertEquals("bookstore", tags.get(0).get("name"));
// paths
JsonMapObject paths = openApiJson.getJsonMapProperty("paths");
assertEquals(2, paths.size());
// 1: bookstore
JsonMapObject bookstore = paths.getJsonMapProperty("/bookstore");
assertEquals(1, bookstore.size());
// get
verifyBookStoreGet(bookstore);
// 2: bookstore/{id}
JsonMapObject bookstoreId = paths.getJsonMapProperty("/bookstore/{id}");
assertEquals(2, bookstoreId.size());
// get
verifyBookStoreIdGet(bookstoreId);
// delete
verifyBookStoreIdDelete(bookstoreId);
// components
JsonMapObject comps = openApiJson.getJsonMapProperty("components");
assertEquals(3, comps.size());
JsonMapObject requestBodies = comps.getJsonMapProperty("requestBodies");
assertEquals(0, requestBodies.size());
JsonMapObject schemas = comps.getJsonMapProperty("schemas");
assertEquals(1, schemas.size());
JsonMapObject secSchemes = comps.getJsonMapProperty("securitySchemes");
assertEquals(1, secSchemes.size());
// Finally check swagger.json can still be generated.
doTestSwagger2JSON();
}
use of org.apache.cxf.jaxrs.json.basic.JsonMapObject in project cxf by apache.
the class SwaggerToOpenApiConversionTest method verifyBookStoreGet.
private void verifyBookStoreGet(JsonMapObject bookstore) {
JsonMapObject bookstoreGet = bookstore.getJsonMapProperty("get");
assertEquals(6, bookstoreGet.size());
List<String> bookstoreGetTags = bookstoreGet.getListStringProperty("tags");
assertEquals(1, bookstoreGetTags.size());
assertEquals("bookstore", bookstoreGetTags.get(0));
assertEquals("Get books", bookstoreGet.getProperty("summary"));
assertEquals("Get books", bookstoreGet.getProperty("description"));
assertEquals("getBooks", bookstoreGet.getProperty("operationId"));
List<Map<String, Object>> bookstoreGetParams = bookstoreGet.getListMapProperty("parameters");
assertEquals(1, bookstoreGetParams.size());
JsonMapObject firstParam = new JsonMapObject(bookstoreGetParams.get(0));
assertEquals(5, firstParam.size());
assertEquals("page", firstParam.getProperty("name"));
assertEquals("query", firstParam.getProperty("in"));
assertEquals("Page to fetch", firstParam.getProperty("description"));
assertTrue(firstParam.getBooleanProperty("required"));
JsonMapObject schema = firstParam.getJsonMapProperty("schema");
assertEquals(3, schema.size());
assertEquals("integer", schema.getProperty("type"));
assertEquals("int32", schema.getProperty("format"));
assertEquals(Integer.valueOf(1), schema.getIntegerProperty("default"));
JsonMapObject responses = bookstoreGet.getJsonMapProperty("responses");
assertEquals(1, responses.size());
JsonMapObject okResp = responses.getJsonMapProperty("200");
assertEquals(2, okResp.size());
assertEquals("successful operation", okResp.getProperty("description"));
JsonMapObject content = okResp.getJsonMapProperty("content");
assertEquals(1, content.size());
JsonMapObject jsonResp = content.getJsonMapProperty("application/json");
assertEquals(1, jsonResp.size());
JsonMapObject jsonRespSchema = jsonResp.getJsonMapProperty("schema");
assertEquals(2, jsonRespSchema.size());
assertEquals("array", jsonRespSchema.getProperty("type"));
JsonMapObject jsonRespSchemaItems = jsonRespSchema.getJsonMapProperty("items");
assertEquals(1, jsonRespSchemaItems.size());
assertEquals("#components/schemas/Book", jsonRespSchemaItems.getProperty("$ref"));
}
Aggregations