Java Code Examples for io.swagger.v3.oas.models.OpenAPI#setExternalDocs()

The following examples show how to use io.swagger.v3.oas.models.OpenAPI#setExternalDocs() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApiDocV3Service.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Updates External documentation in OpenAPI
 *
 * @param openAPI    the API doc
 * @param apiDocInfo the service information
 */
protected void updateExternalDoc(OpenAPI openAPI, ApiDocInfo apiDocInfo) {
    if (apiDocInfo.getApiInfo() == null)
        return;

    String externalDocUrl = apiDocInfo.getApiInfo().getDocumentationUrl();

    if (externalDocUrl != null) {
        ExternalDocumentation externalDoc = new ExternalDocumentation();
        externalDoc.setDescription(EXTERNAL_DOCUMENTATION);
        externalDoc.setUrl(externalDocUrl);
        openAPI.setExternalDocs(externalDoc);
    }
}
 
Example 2
Source File: OpenAPIDeserializer.java    From swagger-parser with Apache License 2.0 4 votes vote down vote up
public OpenAPI parseRoot(JsonNode node, ParseResult result, String path) {
    String location = "";
    OpenAPI openAPI = new OpenAPI();
    if (node.getNodeType().equals(JsonNodeType.OBJECT)) {
        ObjectNode rootNode = (ObjectNode) node;

        // required
        String value = getString("openapi", rootNode, true, location, result);

        // we don't even try if the version isn't there
        if(value == null || !value.startsWith("3.0")) {
            return null;
        }
        openAPI.setOpenapi(value);

        ObjectNode obj = getObject("info", rootNode, true, location, result);
        if (obj != null) {
            Info info = getInfo(obj, "info", result);
            openAPI.setInfo(info);
        }

        obj = getObject("components", rootNode, false, location, result);
        if (obj != null) {
            Components components = getComponents(obj, "components", result);
            openAPI.setComponents(components);
            this.components=components;
        }

        obj = getObject("paths", rootNode, true, location, result);
        if (obj != null) {
            Paths paths = getPaths(obj, "paths", result);
            openAPI.setPaths(paths);
        }


        ArrayNode array = getArray("servers", rootNode, false, location, result);
        if (array != null && array.size() > 0) {
            openAPI.setServers(getServersList(array, String.format("%s.%s", location, "servers"), result, path));
        }else {
            Server defaultServer = new Server();
            defaultServer.setUrl("/");
            List<Server>  servers = new ArrayList<>();
            servers.add(defaultServer);
            openAPI.setServers(servers);
        }

        obj = getObject("externalDocs", rootNode, false, location, result);
        if (obj != null) {
            ExternalDocumentation externalDocs = getExternalDocs(obj, "externalDocs", result);
            openAPI.setExternalDocs(externalDocs);
        }

        array = getArray("tags", rootNode, false, location, result);
        if (array != null && array.size() > 0) {
            openAPI.setTags(getTagList(array, "tags", result));
        }

        array = getArray("security", rootNode, false, location, result);
        if (array != null && array.size() > 0) {
            List<SecurityRequirement> securityRequirements = getSecurityRequirementsList(array, "security", result);
            if (securityRequirements != null && securityRequirements. size() > 0) {
                openAPI.setSecurity(securityRequirements);
            }
        }

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

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

    } else {
        result.invalidType(location, "openapi", "object", node);
        result.invalid();
        return null;
    }

    return openAPI;
}