Search in sources :

Example 16 with Tag

use of io.swagger.v3.jaxrs2.resources.model.Tag in project flow by vaadin.

the class OpenAPIObjectGenerator method addTagsInformation.

private void addTagsInformation() {
    for (Map.Entry<ClassOrInterfaceDeclaration, String> endpointJavadoc : endpointsJavadoc.entrySet()) {
        Tag tag = new Tag();
        ClassOrInterfaceDeclaration endpointDeclaration = endpointJavadoc.getKey();
        String simpleClassName = endpointDeclaration.getNameAsString();
        tag.name(simpleClassName);
        tag.description(endpointJavadoc.getValue());
        tag.addExtension(EXTENSION_VAADIN_FILE_PATH, qualifiedNameToPath.get(endpointDeclaration.getFullyQualifiedName().orElse(simpleClassName)));
        openApiModel.addTagsItem(tag);
    }
}
Also used : ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) Tag(io.swagger.v3.oas.models.tags.Tag) JavadocBlockTag(com.github.javaparser.javadoc.JavadocBlockTag) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) ResolvedTypeParametersMap(com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametersMap)

Example 17 with Tag

use of io.swagger.v3.jaxrs2.resources.model.Tag in project flow by vaadin.

the class CodeGenerator method postProcessOperations.

@Override
@SuppressWarnings("unchecked")
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
    Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
    String classname = (String) operations.get("classname");
    for (Tag tag : tags) {
        if (tag.getName().equals(classname)) {
            objs.put(VAADIN_CONNECT_CLASS_DESCRIPTION, tag.getDescription());
            setVaadinFilePath(objs, tag);
            break;
        }
    }
    if (objs.get(VAADIN_CONNECT_CLASS_DESCRIPTION) == null) {
        logger.debug("The class '{}' doesn't have JavaDoc or it is invalid. This results in no TsDoc for the generated module '{}'.", classname, classname);
    }
    if ((operations.get(OPERATION) instanceof List)) {
        List<CodegenOperation> codegenOperations = (List<CodegenOperation>) operations.get(OPERATION);
        setShouldShowTsDoc(codegenOperations);
    }
    Map<String, Object> postProcessOperations = super.postProcessOperations(objs);
    List<Map<String, Object>> imports = (List<Map<String, Object>>) objs.get("imports");
    adjustImportInformationForEndpoints(imports);
    printDebugMessage(postProcessOperations, "=== All operations data ===");
    return postProcessOperations;
}
Also used : CodegenOperation(io.swagger.codegen.v3.CodegenOperation) ArrayList(java.util.ArrayList) List(java.util.List) Tag(io.swagger.v3.oas.models.tags.Tag) Map(java.util.Map)

Example 18 with Tag

use of io.swagger.v3.jaxrs2.resources.model.Tag 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 19 with Tag

use of io.swagger.v3.jaxrs2.resources.model.Tag in project snow-owl by b2ihealthcare.

the class VersionRestService method createVersion.

@Operation(summary = "Create a new resource version", description = "Creates a new resource version. " + "The version tag (represented by an empty branch) is created on the resource's current working branch. " + "Where applicable, effective times are set on the unpublished content as part of this operation.")
@ApiResponses({ @ApiResponse(responseCode = "201", description = "Created"), @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "409", description = "Code system version conflicts with existing branch") })
@PostMapping(consumes = { AbstractRestService.JSON_MEDIA_TYPE })
@ResponseStatus(value = HttpStatus.CREATED)
public ResponseEntity<Void> createVersion(@Parameter(description = "Version parameters") @RequestBody final ResourceRequest<VersionRestInput> input) {
    final VersionRestInput change = input.getChange();
    ApiValidation.checkInput(change);
    String newVersionUri = String.join(Branch.SEPARATOR, change.getResource().toString(), change.getVersion());
    String jobId = ResourceRequests.prepareNewVersion().setResource(change.getResource()).setVersion(change.getVersion()).setDescription(change.getDescription()).setEffectiveTime(change.getEffectiveTime()).setForce(change.isForce()).setCommitComment(input.getCommitComment()).buildAsync().runAsJobWithRestart(ResourceRequests.versionJobKey(change.getResource()), "Creating version " + newVersionUri).execute(getBus()).getSync(1, TimeUnit.MINUTES);
    RemoteJobEntry job = JobRequests.waitForJob(getBus(), jobId, 500);
    if (job.isSuccessful()) {
        final URI location = MvcUriComponentsBuilder.fromMethodName(VersionRestService.class, "getVersion", newVersionUri).build().toUri();
        return ResponseEntity.created(location).build();
    } else if (!Strings.isNullOrEmpty(job.getResult())) {
        ApiError error = job.getResultAs(ApplicationContext.getServiceForClass(ObjectMapper.class), ApiError.class);
        throw new ApiErrorException(error.withMessage(error.getMessage().replace("Branch name", "Version")));
    } else {
        throw new SnowowlRuntimeException("Version creation failed.");
    }
}
Also used : ApiError(com.b2international.commons.exceptions.ApiError) URI(java.net.URI) ApiErrorException(com.b2international.commons.exceptions.ApiErrorException) RemoteJobEntry(com.b2international.snowowl.core.jobs.RemoteJobEntry) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 20 with Tag

use of io.swagger.v3.jaxrs2.resources.model.Tag in project swagger-parser by swagger-api.

the class OpenAPIDeserializerTest method readTagObject.

@Test(dataProvider = "data")
public void readTagObject(JsonNode rootNode) throws Exception {
    final OpenAPIDeserializer deserializer = new OpenAPIDeserializer();
    final SwaggerParseResult result = deserializer.deserialize(rootNode);
    Assert.assertNotNull(result);
    final OpenAPI openAPI = result.getOpenAPI();
    Assert.assertNotNull(openAPI);
    final List<Tag> Tag = openAPI.getTags();
    Assert.assertNotNull(Tag);
    Assert.assertNotNull(Tag.get(0));
    Assert.assertNotNull(Tag.get(0).getName());
    Assert.assertEquals(Tag.get(0).getName(), "pet");
    Assert.assertNotNull(Tag.get(0).getDescription());
    Assert.assertEquals(Tag.get(0).getDescription(), "Everything about your Pets");
    Assert.assertNotNull(Tag.get(0).getExternalDocs());
    Assert.assertNotNull(Tag.get(1));
    Assert.assertNotNull(Tag.get(1).getName());
    Assert.assertNotNull(Tag.get(1).getDescription());
    Assert.assertEquals(Tag.get(1).getName(), "store");
    Assert.assertEquals(Tag.get(1).getDescription(), "Access to Petstore orders");
}
Also used : SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) Tag(io.swagger.v3.oas.models.tags.Tag) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Aggregations

OpenAPI (io.swagger.v3.oas.models.OpenAPI)18 Schema (io.swagger.v3.oas.models.media.Schema)14 ArrayList (java.util.ArrayList)13 Tag (io.swagger.v3.oas.models.tags.Tag)12 Test (org.testng.annotations.Test)12 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)11 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)11 StringSchema (io.swagger.v3.oas.models.media.StringSchema)11 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)10 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)10 Operation (io.swagger.v3.oas.models.Operation)9 Components (io.swagger.v3.oas.models.Components)7 PathItem (io.swagger.v3.oas.models.PathItem)7 OpenAPIResolver (io.swagger.v3.parser.OpenAPIResolver)7 MediaType (io.swagger.v3.oas.models.media.MediaType)6 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)6 Content (io.swagger.v3.oas.models.media.Content)5 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)5 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)5 HashMap (java.util.HashMap)5