Search in sources :

Example 21 with Tags

use of io.swagger.v3.oas.annotations.tags.Tags in project cxf by apache.

the class OpenApiCustomizer method customize.

public void customize(final OpenAPI oas) {
    if (replaceTags || javadocProvider != null) {
        Map<String, ClassResourceInfo> operations = new HashMap<>();
        Map<Pair<String, String>, OperationResourceInfo> methods = new HashMap<>();
        cris.forEach(cri -> {
            cri.getMethodDispatcher().getOperationResourceInfos().forEach(ori -> {
                String normalizedPath = getNormalizedPath(cri.getURITemplate().getValue(), ori.getURITemplate().getValue());
                operations.put(normalizedPath, cri);
                methods.put(Pair.of(ori.getHttpMethod(), normalizedPath), ori);
            });
        });
        List<Tag> tags = new ArrayList<>();
        oas.getPaths().forEach((pathKey, pathItem) -> {
            Optional<Tag> tag;
            if (replaceTags && operations.containsKey(pathKey)) {
                ClassResourceInfo cri = operations.get(pathKey);
                tag = Optional.of(new Tag());
                tag.get().setName(cri.getURITemplate().getValue().replaceAll("/", "_"));
                if (javadocProvider != null) {
                    tag.get().setDescription(javadocProvider.getClassDoc(cri));
                }
                if (!tags.contains(tag.get())) {
                    tags.add(tag.get());
                }
            } else {
                tag = Optional.empty();
            }
            pathItem.readOperationsMap().forEach((method, operation) -> {
                if (replaceTags && tag.isPresent()) {
                    operation.setTags(Collections.singletonList(tag.get().getName()));
                }
                Pair<String, String> key = Pair.of(method.name(), pathKey);
                if (methods.containsKey(key) && javadocProvider != null) {
                    OperationResourceInfo ori = methods.get(key);
                    if (StringUtils.isBlank(operation.getSummary())) {
                        operation.setSummary(javadocProvider.getMethodDoc(ori));
                    }
                    if (operation.getParameters() == null) {
                        List<Parameter> parameters = new ArrayList<>();
                        addParameters(parameters);
                        operation.setParameters(parameters);
                    }
                    for (int i = 0; i < operation.getParameters().size(); i++) {
                        if (StringUtils.isBlank(operation.getParameters().get(i).getDescription())) {
                            operation.getParameters().get(i).setDescription(extractJavadoc(operation, ori, i));
                        }
                    }
                    addParameters(operation.getParameters());
                    customizeResponses(operation, ori);
                }
            });
        });
        if (replaceTags && oas.getTags() != null) {
            oas.setTags(tags);
        }
    }
}
Also used : HashMap(java.util.HashMap) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) ArrayList(java.util.ArrayList) Parameter(io.swagger.v3.oas.models.parameters.Parameter) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) Tag(io.swagger.v3.oas.models.tags.Tag) Pair(org.apache.commons.lang3.tuple.Pair)

Example 22 with Tags

use of io.swagger.v3.oas.annotations.tags.Tags in project snow-owl by b2ihealthcare.

the class SnomedReferenceSetMemberRestService method searchByGet.

@Operation(summary = "Retrieve reference set members from a path", description = "Returns a list with all reference set members from a path." + "<p>The following properties can be expanded:" + "<p>" + "&bull; referencedComponent(expand(pt(),...)) &ndash; the referenced component, and any applicable nested expansions<br>")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "Branch not found") })
@GetMapping(produces = { AbstractRestService.JSON_MEDIA_TYPE })
@ResponseBody
public Promise<SnomedReferenceSetMembers> searchByGet(@Parameter(description = "The resource path", required = true) @PathVariable(value = "path") final String path, @ParameterObject final SnomedReferenceSetMemberRestSearch params, @Parameter(description = "Accepted language tags, in order of preference", example = "en-US;q=0.8,en-GB;q=0.6") @RequestHeader(value = "Accept-Language", defaultValue = "en-US;q=0.8,en-GB;q=0.6", required = false) final String acceptLanguage) {
    final SnomedRefSetMemberSearchRequestBuilder req = SnomedRequests.prepareSearchMember().setLimit(params.getLimit()).setSearchAfter(params.getSearchAfter()).filterByIds(params.getId()).filterByActive(params.getActive()).filterByModules(params.getModule()).filterByEffectiveTime(params.getEffectiveTime()).filterByRefSet(params.getRefsetId()).filterByReferencedComponent(params.getReferencedComponentId()).setExpand(params.getExpand()).setFields(params.getField()).setLocales(acceptLanguage).sortBy(extractSortFields(params.getSort()));
    Options propFilters = params.toPropsFilter();
    if (!propFilters.isEmpty()) {
        req.filterByProps(propFilters);
    }
    return req.build(path).execute(getBus());
}
Also used : Options(com.b2international.commons.options.Options) SnomedRefSetMemberSearchRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedRefSetMemberSearchRequestBuilder) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 23 with Tags

use of io.swagger.v3.oas.annotations.tags.Tags in project swagger-parser by swagger-api.

the class OpenAPIDeserializer method parseRoot.

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Server(io.swagger.v3.oas.models.servers.Server) Info(io.swagger.v3.oas.models.info.Info) Components(io.swagger.v3.oas.models.Components) ExternalDocumentation(io.swagger.v3.oas.models.ExternalDocumentation) Paths(io.swagger.v3.oas.models.Paths) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) OpenAPI(io.swagger.v3.oas.models.OpenAPI) SecurityRequirement(io.swagger.v3.oas.models.security.SecurityRequirement)

Example 24 with Tags

use of io.swagger.v3.oas.annotations.tags.Tags in project swagger-parser by swagger-api.

the class OpenAPIDeserializer method getTagList.

public List<Tag> getTagList(ArrayNode obj, String location, ParseResult result) {
    if (obj == null) {
        return null;
    }
    List<Tag> tags = new ArrayList<>();
    Set<String> tagsTracker = new HashSet<>();
    for (JsonNode item : obj) {
        if (item.getNodeType().equals(JsonNodeType.OBJECT)) {
            Tag tag = getTag((ObjectNode) item, location, result);
            if (tag != null) {
                tags.add(tag);
                if (tagsTracker.contains((String) tag.getName())) {
                    result.uniqueTags(location, tag.getName());
                }
                tagsTracker.add(tag.getName());
            }
        }
    }
    return tags;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) Tag(io.swagger.v3.oas.models.tags.Tag)

Example 25 with Tags

use of io.swagger.v3.oas.annotations.tags.Tags in project swagger-parser by swagger-api.

the class OpenAPIV3ParserTest method testPetstore.

@Test
public void testPetstore() throws Exception {
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult result = parser.readLocation("src/test/resources/petstore.yaml", null, options);
    assertNotNull(result);
    assertTrue(result.getMessages().size() == 2);
    OpenAPI openAPI = result.getOpenAPI();
    Map<String, Schema> definitions = openAPI.getComponents().getSchemas();
    Set<String> expectedDefinitions = new HashSet<String>();
    expectedDefinitions.add("User");
    expectedDefinitions.add("Category");
    expectedDefinitions.add("Pet");
    expectedDefinitions.add("Tag");
    expectedDefinitions.add("Order");
    expectedDefinitions.add("PetArray");
    assertEquals(definitions.keySet(), expectedDefinitions);
    Schema petModel = definitions.get("Pet");
    Set<String> expectedPetProps = new HashSet<String>();
    expectedPetProps.add("id");
    expectedPetProps.add("category");
    expectedPetProps.add("name");
    expectedPetProps.add("photoUrls");
    expectedPetProps.add("tags");
    expectedPetProps.add("status");
    assertEquals(petModel.getProperties().keySet(), expectedPetProps);
    ArraySchema petArrayModel = (ArraySchema) definitions.get("PetArray");
    assertEquals(petArrayModel.getType(), "array");
    Schema refProp = petArrayModel.getItems();
    assertEquals(refProp.get$ref(), "#/components/schemas/Pet");
    assertNull(petArrayModel.getProperties());
}
Also used : ByteArraySchema(io.swagger.v3.oas.models.media.ByteArraySchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) ByteArraySchema(io.swagger.v3.oas.models.media.ByteArraySchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

OpenAPI (io.swagger.v3.oas.models.OpenAPI)20 Test (org.testng.annotations.Test)15 ArrayList (java.util.ArrayList)11 Operation (io.swagger.v3.oas.models.Operation)9 PathItem (io.swagger.v3.oas.models.PathItem)8 Schema (io.swagger.v3.oas.models.media.Schema)8 Tag (io.swagger.v3.oas.models.tags.Tag)8 Paths (io.swagger.v3.oas.models.Paths)7 MediaType (io.swagger.v3.oas.models.media.MediaType)5 Parameter (io.swagger.v3.oas.models.parameters.Parameter)5 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)5 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)5 Callback (io.swagger.v3.oas.models.callbacks.Callback)4 Content (io.swagger.v3.oas.models.media.Content)4 RequestBody (io.swagger.v3.oas.models.parameters.RequestBody)4 SecurityScheme (io.swagger.v3.oas.models.security.SecurityScheme)4 List (java.util.List)4 Map (java.util.Map)4 AnnotatedType (io.swagger.v3.core.converter.AnnotatedType)3 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)3