Search in sources :

Example 36 with JsonMapObject

use of org.apache.cxf.jaxrs.json.basic.JsonMapObject in project cxf by apache.

the class SwaggerToOpenApiConversionUtilsTest method verifyMapContent.

private void verifyMapContent(JsonMapObject contentMap, String mediaType, String type, String format) {
    JsonMapObject content = contentMap.getJsonMapProperty(mediaType);
    assertEquals(1, content.size());
    JsonMapObject schema = content.getJsonMapProperty("schema");
    assertEquals(2, schema.size());
    assertEquals("object", schema.getStringProperty("type"));
    JsonMapObject additionalProps = schema.getJsonMapProperty("additionalProperties");
    assertEquals(type, additionalProps.getStringProperty("type"));
    assertEquals(format, additionalProps.getStringProperty("format"));
}
Also used : JsonMapObject(org.apache.cxf.jaxrs.json.basic.JsonMapObject)

Example 37 with JsonMapObject

use of org.apache.cxf.jaxrs.json.basic.JsonMapObject in project cxf by apache.

the class BigQueryService method getMatchingTexts.

static List<ShakespeareText> getMatchingTexts(WebClient bqClient, ClientAccessToken accessToken, String searchWord, String maxResults) {
    bqClient.authorization(accessToken);
    String bigQuerySelect = String.format(BQ_SELECT, searchWord);
    String bigQueryRequest = String.format(BQ_REQUEST, bigQuerySelect, Integer.parseInt(maxResults));
    JsonMapObject jsonMap = bqClient.post(bigQueryRequest, JsonMapObject.class);
    List<ShakespeareText> texts = new LinkedList<ShakespeareText>();
    List<Map<String, Object>> rows = CastUtils.cast((List<?>) jsonMap.getProperty("rows"));
    if (rows != null) {
        for (Map<String, Object> row : rows) {
            List<Map<String, Object>> fields = CastUtils.cast((List<?>) row.get("f"));
            ShakespeareText text = new ShakespeareText((String) fields.get(0).get("v"), (String) fields.get(1).get("v"));
            texts.add(text);
        }
    }
    return texts;
}
Also used : JsonMapObject(org.apache.cxf.jaxrs.json.basic.JsonMapObject) Map(java.util.Map) LinkedList(java.util.LinkedList) JsonMapObject(org.apache.cxf.jaxrs.json.basic.JsonMapObject)

Example 38 with JsonMapObject

use of org.apache.cxf.jaxrs.json.basic.JsonMapObject in project cxf by apache.

the class SwaggerToOpenApiConversionUtils method prepareFormContent.

private static JsonMapObject prepareFormContent(List<JsonMapObject> formList, List<String> mediaTypes) {
    String mediaType = StringUtils.isEmpty(mediaTypes) ? "application/x-www-form-urlencoded" : mediaTypes.get(0);
    JsonMapObject content = new JsonMapObject();
    JsonMapObject formType = new JsonMapObject();
    JsonMapObject schema = new JsonMapObject();
    schema.setProperty("type", "object");
    JsonMapObject props = new JsonMapObject();
    for (JsonMapObject prop : formList) {
        String name = (String) prop.removeProperty("name");
        props.setProperty(name, prop);
        if ("file".equals(prop.getProperty("type"))) {
            prop.setProperty("type", "string");
            if (!prop.containsProperty("format")) {
                prop.setProperty("format", "binary");
            }
        }
    }
    schema.setProperty("properties", props);
    formType.setProperty("schema", schema);
    content.setProperty(mediaType, formType);
    return content;
}
Also used : JsonMapObject(org.apache.cxf.jaxrs.json.basic.JsonMapObject)

Example 39 with JsonMapObject

use of org.apache.cxf.jaxrs.json.basic.JsonMapObject in project cxf by apache.

the class SwaggerToOpenApiConversionUtils method setPathsProperty.

private static void setPathsProperty(JsonMapObject sw2, JsonMapObject sw3, Map<String, JsonMapObject> requestBodies) {
    JsonMapObject sw2Paths = sw2.getJsonMapProperty("paths");
    for (Map.Entry<String, Object> sw2PathEntries : sw2Paths.asMap().entrySet()) {
        JsonMapObject sw2PathVerbs = new JsonMapObject(CastUtils.cast((Map<?, ?>) sw2PathEntries.getValue()));
        for (Map.Entry<String, Object> sw2PathVerbEntries : sw2PathVerbs.asMap().entrySet()) {
            JsonMapObject sw2PathVerbProps = new JsonMapObject(CastUtils.cast((Map<?, ?>) sw2PathVerbEntries.getValue()));
            prepareRequestBody(sw2PathVerbProps, requestBodies);
            prepareResponses(sw2PathVerbProps);
        }
    }
    sw3.setProperty("paths", sw2Paths);
}
Also used : JsonMapObject(org.apache.cxf.jaxrs.json.basic.JsonMapObject) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) JsonMapObject(org.apache.cxf.jaxrs.json.basic.JsonMapObject)

Example 40 with JsonMapObject

use of org.apache.cxf.jaxrs.json.basic.JsonMapObject in project cxf by apache.

the class SwaggerToOpenApiConversionUtilsTest method verifyUserPathPost.

private void verifyUserPathPost(JsonMapObject store, OpenApiConfiguration cfg) {
    JsonMapObject userPost = store.getJsonMapProperty("post");
    assertEquals(6, userPost.size());
    testCommonVerbPropsExceptSec(userPost, "createUser");
    assertNull(userPost.getProperty("parameters"));
    if (cfg.isCreateRequestBodies()) {
        verifyRequestBodyRef(userPost, "User");
    } else {
        JsonMapObject contentIn = verifyRequestBodyContent(userPost);
        assertEquals(1, contentIn.size());
        verifySimpleContent(contentIn, "application/json", "User");
    }
    testDefaultResponse(userPost);
}
Also used : JsonMapObject(org.apache.cxf.jaxrs.json.basic.JsonMapObject)

Aggregations

JsonMapObject (org.apache.cxf.jaxrs.json.basic.JsonMapObject)63 Map (java.util.Map)23 LinkedHashMap (java.util.LinkedHashMap)5 JsonMapObjectReaderWriter (org.apache.cxf.jaxrs.json.basic.JsonMapObjectReaderWriter)5 Test (org.junit.Test)3 LinkedList (java.util.LinkedList)2 IOException (java.io.IOException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 WebClient (org.apache.cxf.jaxrs.client.WebClient)1