Example usage for com.fasterxml.jackson.databind.node JsonNodeType STRING

List of usage examples for com.fasterxml.jackson.databind.node JsonNodeType STRING

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node JsonNodeType STRING.

Prototype

JsonNodeType STRING

To view the source code for com.fasterxml.jackson.databind.node JsonNodeType STRING.

Click Source Link

Usage

From source file:io.swagger.parser.util.SwaggerDeserializer.java

public List<String> tagStrings(ArrayNode nodes, String location, ParseResult result) {
    if (nodes == null)
        return null;

    List<String> output = new ArrayList<String>();

    for (JsonNode node : nodes) {
        if (node.getNodeType().equals(JsonNodeType.STRING)) {
            output.add(node.textValue());
        }/*from  w  w  w .j a v  a 2  s.  com*/
    }
    return output;
}

From source file:io.swagger.v3.parser.util.OpenAPIDeserializer.java

public Callback getCallback(ObjectNode node, String location, ParseResult result) {
    if (node == null) {
        return null;
    }/*from www  .  j  av a 2s  .  co  m*/

    Callback callback = new Callback();

    Set<String> keys = getKeys(node);
    for (String name : keys) {
        JsonNode value = node.get(name);
        if (node != null) {
            JsonNode ref = node.get("$ref");
            if (ref != null) {
                if (ref.getNodeType().equals(JsonNodeType.STRING)) {
                    String mungedRef = mungedRef(ref.textValue());
                    if (mungedRef != null) {
                        callback.set$ref(mungedRef);
                    } else {
                        callback.set$ref(ref.textValue());
                    }
                    return callback;
                } else {
                    result.invalidType(location, "$ref", "string", node);
                    return null;
                }
            }
            callback.addPathItem(name, getPathItem((ObjectNode) value, location, result));

            Map<String, Object> extensions = getExtensions(node);
            if (extensions != null && extensions.size() > 0) {
                callback.setExtensions(extensions);
            }
        }
    }

    return callback;
}

From source file:io.swagger.parser.util.SwaggerDeserializer.java

public String getString(JsonNode node, String location, ParseResult result) {
    String output = null;/*from w  w w  .java2s .c om*/
    if (!node.getNodeType().equals(JsonNodeType.STRING)) {
        result.invalidType(location, "", "string", node);
    } else {
        output = ((TextNode) node).asText();
    }
    return output;
}

From source file:io.swagger.v3.parser.util.OpenAPIDeserializer.java

public Parameter getParameter(ObjectNode obj, String location, ParseResult result) {
    if (obj == null) {
        return null;
    }/*from w w  w  .  j  a  v a  2 s  .c  o  m*/

    Parameter parameter = null;

    JsonNode ref = obj.get("$ref");
    if (ref != null) {
        if (ref.getNodeType().equals(JsonNodeType.STRING)) {
            parameter = new Parameter();
            String mungedRef = mungedRef(ref.textValue());
            if (mungedRef != null) {
                parameter.set$ref(mungedRef);
            } else {
                parameter.set$ref(ref.textValue());
            }
            return parameter;
        } else {
            result.invalidType(location, "$ref", "string", obj);
            return null;
        }
    }

    String l = null;
    JsonNode ln = obj.get("name");
    if (ln != null) {
        l = ln.asText();
    } else {
        l = "['unknown']";
    }
    location += ".[" + l + "]";

    String value = getString("in", obj, true, location, result);

    if (StringUtils.isBlank(value)) {
        return null;
    }

    if (QUERY_PARAMETER.equals(value)) {
        parameter = new QueryParameter();
    } else if (HEADER_PARAMETER.equals(value)) {
        parameter = new HeaderParameter();
    } else if (PATH_PARAMETER.equals(value)) {
        parameter = new PathParameter();
    } else if (COOKIE_PARAMETER.equals(value)) {
        parameter = new CookieParameter();
    }

    if (parameter == null) {
        result.invalidType(location, "in", "string", obj);
        return null;
    }

    parameter.setIn(value);

    value = getString("name", obj, true, location, result);
    if (StringUtils.isNotBlank(value)) {
        parameter.setName(value);
    }

    value = getString("description", obj, false, location, result);
    if (StringUtils.isNotBlank(value)) {
        parameter.setDescription(value);
    }

    Boolean required = getBoolean("required", obj, false, location, result);
    if (required != null) {
        parameter.setRequired(required);
    } else {
        parameter.setRequired(false);
    }

    Boolean deprecated = getBoolean("deprecated", obj, false, location, result);
    if (deprecated != null) {
        parameter.setDeprecated(deprecated);
    }

    if (parameter instanceof QueryParameter) {
        Boolean allowEmptyValue = getBoolean("allowEmptyValue", obj, false, location, result);
        if (allowEmptyValue != null) {
            parameter.setAllowEmptyValue(allowEmptyValue);
        }
    }

    value = getString("style", obj, false, location, result);
    setStyle(value, parameter, location, obj, result);

    Boolean explode = getBoolean("explode", obj, false, location, result);
    if (explode != null) {
        parameter.setExplode(explode);
    } else if (parameter.getStyle().equals(StyleEnum.FORM)) {
        parameter.setExplode(Boolean.TRUE);
    } else {
        parameter.setExplode(Boolean.FALSE);
    }

    ObjectNode parameterObject = getObject("schema", obj, false, location, result);
    if (parameterObject != null) {
        parameter.setSchema(getSchema(parameterObject, String.format("%s.%s", location, "schemas"), result));
    }

    ObjectNode examplesObject = getObject("examples", obj, false, location, result);
    if (examplesObject != null) {
        parameter
                .setExamples(getExamples(examplesObject, String.format("%s.%s", location, "examples"), result));
    }

    Object example = getAnyExample("example", obj, location, result);
    if (example != null) {
        parameter.setExample(example);
    }

    ObjectNode contentNode = getObject("content", obj, false, location, result);
    if (contentNode != null) {
        parameter.setContent(getContent(contentNode, String.format("%s.%s", location, "content"), result));
    }

    Map<String, Object> extensions = getExtensions(obj);
    if (extensions != null && extensions.size() > 0) {
        parameter.setExtensions(extensions);
    }

    Set<String> keys = getKeys(obj);
    for (String key : keys) {
        if (!PARAMETER_KEYS.contains(key) && !key.startsWith("x-")) {
            result.extra(location, key, obj.get(key));
        }
    }

    return parameter;
}

From source file:io.swagger.v3.parser.util.OpenAPIDeserializer.java

public Header getHeader(ObjectNode headerNode, String location, ParseResult result) {
    if (headerNode == null) {
        return null;
    }/* w w  w . jav  a 2  s.co  m*/

    Header header = new Header();

    JsonNode ref = headerNode.get("$ref");
    if (ref != null) {
        if (ref.getNodeType().equals(JsonNodeType.STRING)) {
            String mungedRef = mungedRef(ref.textValue());
            if (mungedRef != null) {
                header.set$ref(mungedRef);
            } else {
                header.set$ref(ref.textValue());
            }
            return header;
        } else {
            result.invalidType(location, "$ref", "string", headerNode);
            return null;
        }
    }

    String value = getString("description", headerNode, false, location, result);
    if (StringUtils.isNotBlank(value)) {
        header.setDescription(value);
    }

    Boolean required = getBoolean("required", headerNode, false, location, result);
    if (required != null) {
        header.setRequired(required);
    }

    Boolean deprecated = getBoolean("deprecated", headerNode, false, location, result);
    if (deprecated != null) {
        header.setDeprecated(deprecated);
    }

    Boolean explode = getBoolean("explode", headerNode, false, location, result);
    if (explode != null) {
        header.setExplode(explode);
    } else {
        header.setExplode(Boolean.FALSE);
    }

    header.setStyle(Header.StyleEnum.SIMPLE);

    ObjectNode headerObject = getObject("schema", headerNode, false, location, result);
    if (headerObject != null) {
        header.setSchema(getSchema(headerObject, location, result));
    }

    ObjectNode examplesObject = getObject("examples", headerNode, false, location, result);
    if (examplesObject != null) {
        header.setExamples(getExamples(examplesObject, location, result));
    }

    Object example = getAnyExample("example", headerNode, location, result);
    if (example != null) {
        header.setExample(example);
    }

    ObjectNode contentNode = getObject("content", headerNode, false, location, result);
    if (contentNode != null) {
        header.setContent(getContent(contentNode, String.format("%s.%s", location, "content"), result));
    }

    Map<String, Object> extensions = getExtensions(headerNode);
    if (extensions != null && extensions.size() > 0) {
        header.setExtensions(extensions);
    }

    Set<String> oAuthFlowKeys = getKeys(headerNode);
    for (String key : oAuthFlowKeys) {
        if (!HEADER_KEYS.contains(key) && !key.startsWith("x-")) {
            result.extra(location, key, headerNode.get(key));
        }
    }

    return header;
}

From source file:io.swagger.v3.parser.util.OpenAPIDeserializer.java

public Object getAnyExample(String nodeKey, ObjectNode node, String location, ParseResult result) {
    JsonNode example = node.get(nodeKey);
    if (example != null) {
        if (example.getNodeType().equals(JsonNodeType.STRING)) {
            String value = getString(nodeKey, node, false, location, result);
            if (StringUtils.isNotBlank(value)) {
                return value;
            }//w  w w.j  ava  2s . c o  m
        }
        if (example.getNodeType().equals(JsonNodeType.NUMBER)) {
            Integer integerExample = getInteger(nodeKey, node, false, location, result);
            if (integerExample != null) {
                return integerExample;
            } else {
                BigDecimal bigDecimalExample = getBigDecimal(nodeKey, node, false, location, result);
                if (bigDecimalExample != null) {
                    return bigDecimalExample;

                }
            }
        } else if (example.getNodeType().equals(JsonNodeType.OBJECT)) {
            ObjectNode objectValue = getObject(nodeKey, node, false, location, result);
            if (objectValue != null) {
                return objectValue;
            }
        } else if (example.getNodeType().equals(JsonNodeType.ARRAY)) {
            ArrayNode arrayValue = getArray(nodeKey, node, false, location, result);
            if (arrayValue != null) {
                return arrayValue;
            }
        }
    }
    return null;
}

From source file:io.swagger.v3.parser.util.OpenAPIDeserializer.java

public SecurityScheme getSecurityScheme(ObjectNode node, String location, ParseResult result) {
    if (node == null) {
        return null;
    }//w  ww .  j  av  a2s.  c o m

    SecurityScheme securityScheme = new SecurityScheme();

    JsonNode ref = node.get("$ref");
    if (ref != null) {
        if (ref.getNodeType().equals(JsonNodeType.STRING)) {
            String mungedRef = mungedRef(ref.textValue());
            if (mungedRef != null) {
                securityScheme.set$ref(mungedRef);
            } else {
                securityScheme.set$ref(ref.textValue());
            }
            return securityScheme;
        } else {
            result.invalidType(location, "$ref", "string", node);
            return null;
        }
    }

    boolean descriptionRequired, bearerFormatRequired, nameRequired, inRequired, schemeRequired, flowsRequired,
            openIdConnectRequired;
    descriptionRequired = bearerFormatRequired = nameRequired = inRequired = schemeRequired = flowsRequired = openIdConnectRequired = false;

    String value = getString("type", node, true, location, result);
    if (StringUtils.isNotBlank(value)) {
        if (SecurityScheme.Type.APIKEY.toString().equals(value)) {
            securityScheme.setType(SecurityScheme.Type.APIKEY);
            nameRequired = inRequired = true;
        } else if (SecurityScheme.Type.HTTP.toString().equals(value)) {
            securityScheme.setType(SecurityScheme.Type.HTTP);
            schemeRequired = true;
        } else if (SecurityScheme.Type.OAUTH2.toString().equals(value)) {
            securityScheme.setType(SecurityScheme.Type.OAUTH2);
            flowsRequired = true;
        } else if (SecurityScheme.Type.OPENIDCONNECT.toString().equals(value)) {
            securityScheme.setType(SecurityScheme.Type.OPENIDCONNECT);
            openIdConnectRequired = true;
        } else {
            result.invalidType(location + ".type", "type", "http|apiKey|oauth2|openIdConnect ", node);
        }
    }
    value = getString("description", node, descriptionRequired, location, result);
    if (StringUtils.isNotBlank(value)) {
        securityScheme.setDescription(value);
    }

    value = getString("name", node, nameRequired, location, result);
    if (StringUtils.isNotBlank(value)) {
        securityScheme.setName(value);
    }

    final String securitySchemeIn = getString("in", node, inRequired, location, result);
    final Optional<SecurityScheme.In> matchingIn = Arrays.stream(SecurityScheme.In.values())
            .filter(in -> in.toString().equals(securitySchemeIn)).findFirst();

    securityScheme.setIn(matchingIn.orElse(null));

    value = getString("scheme", node, schemeRequired, location, result);
    if (StringUtils.isNotBlank(value)) {
        securityScheme.setScheme(value);
    }

    value = getString("bearerFormat", node, bearerFormatRequired, location, result);
    if (StringUtils.isNotBlank(value)) {
        securityScheme.setBearerFormat(value);
    }

    ObjectNode flowsObject = getObject("flows", node, flowsRequired, location, result);
    if (flowsObject != null) {
        securityScheme.setFlows(getOAuthFlows(flowsObject, location, result));
    }

    value = getString("openIdConnectUrl", node, openIdConnectRequired, location, result);
    if (StringUtils.isNotBlank(value)) {
        securityScheme.setOpenIdConnectUrl(value);
    }

    Map<String, Object> extensions = getExtensions(node);
    if (extensions != null && extensions.size() > 0) {
        securityScheme.setExtensions(extensions);
    }

    Set<String> securitySchemeKeys = getKeys(node);
    for (String key : securitySchemeKeys) {
        if (!SECURITY_SCHEME_KEYS.contains(key) && !key.startsWith("x-")) {
            result.extra(location, key, node.get(key));
        }
    }

    return securityScheme;
}

From source file:io.swagger.v3.parser.util.OpenAPIDeserializer.java

public Schema getSchema(ObjectNode node, String location, ParseResult result) {
    if (node == null) {
        return null;
    }// w ww .j  a v a 2s  .  c  o m

    Schema schema = null;
    ArrayNode oneOfArray = getArray("oneOf", node, false, location, result);
    ArrayNode allOfArray = getArray("allOf", node, false, location, result);
    ArrayNode anyOfArray = getArray("anyOf", node, false, location, result);
    ObjectNode itemsNode = getObject("items", node, false, location, result);

    if ((allOfArray != null) || (anyOfArray != null) || (oneOfArray != null)) {
        ComposedSchema composedSchema = new ComposedSchema();

        if (allOfArray != null) {

            for (JsonNode n : allOfArray) {
                if (n.isObject()) {
                    schema = getSchema((ObjectNode) n, location, result);
                    composedSchema.addAllOfItem(schema);
                }
            }
            schema = composedSchema;
        }
        if (anyOfArray != null) {

            for (JsonNode n : anyOfArray) {
                if (n.isObject()) {
                    schema = getSchema((ObjectNode) n, location, result);
                    composedSchema.addAnyOfItem(schema);
                }
            }
            schema = composedSchema;
        }
        if (oneOfArray != null) {

            for (JsonNode n : oneOfArray) {
                if (n.isObject()) {
                    schema = getSchema((ObjectNode) n, location, result);
                    composedSchema.addOneOfItem(schema);
                }
            }
            schema = composedSchema;
        }
    }

    if (itemsNode != null) {
        ArraySchema items = new ArraySchema();
        if (itemsNode.getNodeType().equals(JsonNodeType.OBJECT)) {
            items.setItems(getSchema(itemsNode, location, result));
        } else if (itemsNode.getNodeType().equals(JsonNodeType.ARRAY)) {
            for (JsonNode n : itemsNode) {
                if (n.isValueNode()) {
                    items.setItems(getSchema(itemsNode, location, result));
                }
            }
        }
        schema = items;
    }

    if (schema == null) {
        schema = SchemaTypeUtil.createSchemaByType(node);
    }

    JsonNode ref = node.get("$ref");
    if (ref != null) {
        if (ref.getNodeType().equals(JsonNodeType.STRING)) {
            String mungedRef = mungedRef(ref.textValue());
            if (mungedRef != null) {
                schema.set$ref(mungedRef);
            } else {
                schema.set$ref(ref.asText());
            }
            return schema;
        } else {
            result.invalidType(location, "$ref", "string", node);
            return null;
        }
    }

    String value = getString("title", node, false, location, result);
    if (StringUtils.isNotBlank(value)) {
        schema.setTitle(value);
    }

    ObjectNode discriminatorNode = getObject("discriminator", node, false, location, result);
    if (discriminatorNode != null) {
        schema.setDiscriminator(getDiscriminator(discriminatorNode, location, result));
    }

    BigDecimal bigDecimal = getBigDecimal("multipleOf", node, false, location, result);
    if (bigDecimal != null) {
        schema.setMultipleOf(bigDecimal);
    }

    bigDecimal = getBigDecimal("maximum", node, false, location, result);
    if (bigDecimal != null) {
        schema.setMaximum(bigDecimal);
    }

    Boolean bool = getBoolean("exclusiveMaximum", node, false, location, result);
    if (bool != null) {
        schema.setExclusiveMaximum(bool);
    }

    bigDecimal = getBigDecimal("minimum", node, false, location, result);
    if (bigDecimal != null) {
        schema.setMinimum(bigDecimal);
    }

    bool = getBoolean("exclusiveMinimum", node, false, location, result);
    if (bool != null) {
        schema.setExclusiveMinimum(bool);
    }

    Integer integer = getInteger("minLength", node, false, location, result);
    if (integer != null) {
        schema.setMinLength(integer);
    }

    integer = getInteger("maxLength", node, false, location, result);
    if (integer != null) {
        schema.setMaxLength(integer);
    }

    String pattern = getString("pattern", node, false, location, result);
    if (StringUtils.isNotBlank(pattern)) {
        schema.setPattern(pattern);
    }

    integer = getInteger("maxItems", node, false, location, result);
    if (integer != null) {
        schema.setMaxItems(integer);
    }
    integer = getInteger("minItems", node, false, location, result);
    if (integer != null) {
        schema.setMinItems(integer);
    }

    bool = getBoolean("uniqueItems", node, false, location, result);
    if (bool != null) {
        schema.setUniqueItems(bool);
    }

    integer = getInteger("maxProperties", node, false, location, result);
    if (integer != null) {
        schema.setMaxProperties(integer);
    }

    integer = getInteger("minProperties", node, false, location, result);
    if (integer != null) {
        schema.setMinProperties(integer);
    }

    ArrayNode required = getArray("required", node, false, location, result);
    if (required != null) {
        List<String> requiredList = new ArrayList<>();
        for (JsonNode n : required) {
            if (n.getNodeType().equals(JsonNodeType.STRING)) {
                requiredList.add(((TextNode) n).textValue());
            } else {
                result.invalidType(location, "required", "string", n);
            }
        }
        if (requiredList.size() > 0) {
            schema.setRequired(requiredList);
        }
    }

    ArrayNode enumArray = getArray("enum", node, false, location, result);
    if (enumArray != null) {
        for (JsonNode n : enumArray) {
            if (n.isNumber()) {
                schema.addEnumItemObject(n.numberValue());
            } else if (n.isValueNode()) {
                schema.addEnumItemObject(n.asText());
            } else {
                result.invalidType(location, "enum", "value", n);
            }
        }
    }

    value = getString("type", node, false, location, result);
    if (StringUtils.isNotBlank(value)) {
        schema.setType(value);
    } else {
        // may have an enum where type can be inferred
        JsonNode enumNode = node.get("enum");
        if (enumNode != null && enumNode.isArray()) {
            String type = inferTypeFromArray((ArrayNode) enumNode);
            schema.setType(type);
        }
    }

    ObjectNode notObj = getObject("not", node, false, location, result);
    if (notObj != null) {
        Schema not = getSchema(notObj, location, result);
        if (not != null) {
            schema.setNot(not);
        }
    }

    Map<String, Schema> properties = new LinkedHashMap<>();
    ObjectNode propertiesObj = getObject("properties", node, false, location, result);
    Schema property = null;

    Set<String> keys = getKeys(propertiesObj);
    for (String name : keys) {
        JsonNode propertyValue = propertiesObj.get(name);
        if (!propertyValue.getNodeType().equals(JsonNodeType.OBJECT)) {
            result.invalidType(location, "properties", "object", propertyValue);
        } else {
            if (propertiesObj != null) {
                property = getSchema((ObjectNode) propertyValue, location, result);
                if (property != null) {
                    properties.put(name, property);
                }
            }
        }
    }
    if (propertiesObj != null) {
        schema.setProperties(properties);
    }

    if (node.get("additionalProperties") != null) {
        if (node.get("additionalProperties").getNodeType().equals(JsonNodeType.OBJECT)) {
            ObjectNode additionalPropertiesObj = getObject("additionalProperties", node, false, location,
                    result);
            if (additionalPropertiesObj != null) {
                Schema additionalProperties = getSchema(additionalPropertiesObj, location, result);
                if (additionalProperties != null) {
                    schema.setAdditionalProperties(additionalProperties);
                }
            }
        } else if (node.get("additionalProperties").getNodeType().equals(JsonNodeType.BOOLEAN)) {
            Boolean additionalProperties = getBoolean("additionalProperties", node, false, location, result);
            if (additionalProperties != null) {
                schema.setAdditionalProperties(additionalProperties);
            }

        }
    }
    value = getString("description", node, false, location, result);
    if (StringUtils.isNotBlank(value)) {
        schema.setDescription(value);
    }

    value = getString("format", node, false, location, result);
    if (StringUtils.isNotBlank(value)) {
        schema.setFormat(value);
    }

    value = getString("default", node, false, location, result);
    if (StringUtils.isNotBlank(value)) {
        schema.setDefault(value);
    }

    //discriminator

    bool = getBoolean("nullable", node, false, location, result);
    if (bool != null) {
        schema.setNullable(bool);
    }

    bool = getBoolean("readOnly", node, false, location, result);
    if (bool != null) {
        schema.setReadOnly(bool);
    }

    bool = getBoolean("writeOnly", node, false, location, result);
    if (bool != null) {
        schema.setWriteOnly(bool);
    }

    ObjectNode xmlNode = getObject("xml", node, false, location, result);
    if (xmlNode != null) {
        XML xml = getXml(xmlNode, location, result);
        if (xml != null) {
            schema.setXml(xml);
        }
    }

    ObjectNode externalDocs = getObject("externalDocs", node, false, location, result);
    if (externalDocs != null) {
        ExternalDocumentation docs = getExternalDocs(externalDocs, location, result);
        if (docs != null) {
            schema.setExternalDocs(docs);
        }
    }

    Object example = getAnyExample("example", node, location, result);
    if (example != null) {
        schema.setExample(example);
    }

    bool = getBoolean("deprecated", node, false, location, result);
    if (bool != null) {
        schema.setDeprecated(bool);
    }

    Map<String, Object> extensions = getExtensions(node);
    if (extensions != null && extensions.size() > 0) {
        schema.setExtensions(extensions);
    }

    Set<String> schemaKeys = getKeys(node);
    for (String key : schemaKeys) {
        if (!SCHEMA_KEYS.contains(key) && !key.startsWith("x-")) {
            result.extra(location, key, node.get(key));
        }
    }

    return schema;

}

From source file:io.swagger.v3.parser.util.OpenAPIDeserializer.java

public Example getExample(ObjectNode node, String location, ParseResult result) {
    if (node == null)
        return null;

    Example example = new Example();

    JsonNode ref = node.get("$ref");
    if (ref != null) {
        if (ref.getNodeType().equals(JsonNodeType.STRING)) {
            String mungedRef = mungedRef(ref.textValue());
            if (mungedRef != null) {
                example.set$ref(mungedRef);
            } else {
                example.set$ref(ref.textValue());
            }/*from www  . ja v  a  2s  .co  m*/
            return example;
        } else {
            result.invalidType(location, "$ref", "string", node);
            return null;
        }
    }

    String value = getString("summary", node, false, location, result);
    if (StringUtils.isNotBlank(value)) {
        example.setSummary(value);
    }

    value = getString("description", node, false, location, result);
    if (StringUtils.isNotBlank(value)) {
        example.setDescription(value);
    }

    Object sample = getAnyExample("value", node, location, result);
    if (sample != null) {
        example.setValue(sample);
    }

    value = getString("externalValue", node, false, location, result);
    if (StringUtils.isNotBlank(value)) {
        example.setExternalValue(value);
    }

    Map<String, Object> extensions = getExtensions(node);
    if (extensions != null && extensions.size() > 0) {
        example.setExtensions(extensions);
    }

    Set<String> keys = getKeys(node);
    for (String key : keys) {
        if (!EXAMPLE_KEYS.contains(key) && !key.startsWith("x-")) {
            result.extra(location, key, node.get(key));
        }
    }

    return example;
}

From source file:io.swagger.v3.parser.util.OpenAPIDeserializer.java

public ApiResponse getResponse(ObjectNode node, String location, ParseResult result) {
    if (node == null) {
        return null;
    }/*  w  w w.ja v a  2 s. c  o m*/

    ApiResponse apiResponse = new ApiResponse();
    JsonNode ref = node.get("$ref");
    if (ref != null) {
        if (ref.getNodeType().equals(JsonNodeType.STRING)) {
            String mungedRef = mungedRef(ref.textValue());
            if (mungedRef != null) {
                apiResponse.set$ref(mungedRef);
            } else {
                apiResponse.set$ref(ref.textValue());
            }
            return apiResponse;
        } else {
            result.invalidType(location, "$ref", "string", node);
            return null;
        }
    }

    String value = getString("description", node, true, location, result);
    if (StringUtils.isNotBlank(value)) {
        apiResponse.description(value);
    }

    ObjectNode headerObject = getObject("headers", node, false, location, result);
    if (headerObject != null) {
        Map<String, Header> headers = getHeaders(headerObject, location, result);
        if (headers != null && headers.size() > 0) {
            apiResponse.setHeaders(headers);
        }
    }

    ObjectNode linksObj = getObject("links", node, false, location, result);
    if (linksObj != null) {
        Map<String, Link> links = getLinks(linksObj, location, result);
        if (links != null && links.size() > 0) {
            apiResponse.setLinks(links);
        }
    }

    ObjectNode contentObject = getObject("content", node, false, location, result);
    if (contentObject != null) {
        apiResponse.setContent(getContent(contentObject, String.format("%s.%s", location, "content"), result));
    }

    Map<String, Object> extensions = getExtensions(node);
    if (extensions != null && extensions.size() > 0) {
        apiResponse.setExtensions(extensions);
    }

    Set<String> keys = getKeys(node);
    for (String key : keys) {
        if (!RESPONSE_KEYS.contains(key) && !key.startsWith("x-")) {
            result.extra(location, key, node.get(key));
        }
    }

    return apiResponse;
}