Search in sources :

Example 11 with Link

use of io.swagger.v3.oas.models.links.Link in project swagger-core by swagger-api.

the class ReaderTest method testLinkWithRef.

@Test(description = "Link with Ref")
public void testLinkWithRef() {
    Components components = new Components();
    components.addLinks("Link", new Link().description("Link Description").operationId("id"));
    OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
    Reader reader = new Reader(oas);
    OpenAPI openAPI = reader.read(RefLinksResource.class);
    String yaml = "openapi: 3.0.1\n" + "info:\n" + "  description: info\n" + "paths:\n" + "  /links:\n" + "    get:\n" + "      operationId: getUserWithAddress\n" + "      parameters:\n" + "      - name: userId\n" + "        in: query\n" + "        schema:\n" + "          type: string\n" + "      responses:\n" + "        default:\n" + "          description: test description\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                $ref: '#/components/schemas/User'\n" + "          links:\n" + "            address:\n" + "              operationId: getAddress\n" + "              parameters:\n" + "                userId: $request.query.userId\n" + "              $ref: '#/components/links/Link'\n" + "components:\n" + "  links:\n" + "    Link:\n" + "      operationId: id\n" + "      description: Link Description\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : Components(io.swagger.v3.oas.models.Components) Info(io.swagger.v3.oas.models.info.Info) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Link(io.swagger.v3.oas.models.links.Link) Test(org.testng.annotations.Test)

Example 12 with Link

use of io.swagger.v3.oas.models.links.Link in project swagger-core by swagger-api.

the class OperationParser method getApiResponses.

public static Optional<ApiResponses> getApiResponses(final io.swagger.v3.oas.annotations.responses.ApiResponse[] responses, Produces classProduces, Produces methodProduces, Components components, JsonView jsonViewAnnotation) {
    if (responses == null) {
        return Optional.empty();
    }
    ApiResponses apiResponsesObject = new ApiResponses();
    for (io.swagger.v3.oas.annotations.responses.ApiResponse response : responses) {
        ApiResponse apiResponseObject = new ApiResponse();
        if (StringUtils.isNotBlank(response.ref())) {
            apiResponseObject.set$ref(response.ref());
            if (StringUtils.isNotBlank(response.responseCode())) {
                apiResponsesObject.addApiResponse(response.responseCode(), apiResponseObject);
            } else {
                apiResponsesObject._default(apiResponseObject);
            }
            continue;
        }
        if (StringUtils.isNotBlank(response.description())) {
            apiResponseObject.setDescription(response.description());
        }
        if (response.extensions().length > 0) {
            Map<String, Object> extensions = AnnotationsUtils.getExtensions(response.extensions());
            if (extensions != null) {
                extensions.forEach(apiResponseObject::addExtension);
            }
        }
        AnnotationsUtils.getContent(response.content(), classProduces == null ? new String[0] : classProduces.value(), methodProduces == null ? new String[0] : methodProduces.value(), null, components, jsonViewAnnotation).ifPresent(apiResponseObject::content);
        AnnotationsUtils.getHeaders(response.headers(), jsonViewAnnotation).ifPresent(apiResponseObject::headers);
        if (StringUtils.isNotBlank(apiResponseObject.getDescription()) || apiResponseObject.getContent() != null || apiResponseObject.getHeaders() != null) {
            Map<String, Link> links = AnnotationsUtils.getLinks(response.links());
            if (links.size() > 0) {
                apiResponseObject.setLinks(links);
            }
            if (StringUtils.isNotBlank(response.responseCode())) {
                apiResponsesObject.addApiResponse(response.responseCode(), apiResponseObject);
            } else {
                apiResponsesObject._default(apiResponseObject);
            }
        }
    }
    if (apiResponsesObject.isEmpty()) {
        return Optional.empty();
    }
    return Optional.of(apiResponsesObject);
}
Also used : ApiResponses(io.swagger.v3.oas.models.responses.ApiResponses) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Link(io.swagger.v3.oas.models.links.Link)

Example 13 with Link

use of io.swagger.v3.oas.models.links.Link in project swagger-core by swagger-api.

the class AnnotationsUtils method getLink.

public static Optional<Link> getLink(io.swagger.v3.oas.annotations.links.Link link) {
    if (link == null) {
        return Optional.empty();
    }
    boolean isEmpty = true;
    Link linkObject = new Link();
    if (StringUtils.isNotBlank(link.description())) {
        linkObject.setDescription(link.description());
        isEmpty = false;
    }
    if (StringUtils.isNotBlank(link.operationId())) {
        linkObject.setOperationId(link.operationId());
        isEmpty = false;
        if (StringUtils.isNotBlank(link.operationRef())) {
            LOGGER.debug("OperationId and OperatonRef are mutually exclusive, there must be only one setted");
        }
    } else {
        if (StringUtils.isNotBlank(link.operationRef())) {
            linkObject.setOperationRef(link.operationRef());
            isEmpty = false;
        }
    }
    if (StringUtils.isNotBlank(link.ref())) {
        linkObject.set$ref(link.ref());
        isEmpty = false;
    }
    if (link.extensions() != null && link.extensions().length > 0) {
        Map<String, Object> extensions = AnnotationsUtils.getExtensions(link.extensions());
        if (extensions != null) {
            extensions.forEach(linkObject::addExtension);
            isEmpty = false;
        }
    }
    if (isEmpty) {
        return Optional.empty();
    }
    Map<String, String> linkParameters = getLinkParameters(link.parameters());
    if (linkParameters.size() > 0) {
        linkObject.setParameters(linkParameters);
    }
    if (StringUtils.isNotBlank(link.requestBody())) {
        JsonNode processedValue = null;
        try {
            processedValue = Json.mapper().readTree(link.requestBody());
        } catch (Exception e) {
        // not a json string
        }
        if (processedValue == null) {
            linkObject.requestBody(link.requestBody());
        } else {
            linkObject.requestBody(processedValue);
        }
    }
    return Optional.of(linkObject);
}
Also used : ExampleObject(io.swagger.v3.oas.annotations.media.ExampleObject) JsonNode(com.fasterxml.jackson.databind.JsonNode) Link(io.swagger.v3.oas.models.links.Link) IOException(java.io.IOException)

Example 14 with Link

use of io.swagger.v3.oas.models.links.Link in project snow-owl by b2ihealthcare.

the class FhirMetadataController method operationDefinition.

/**
 * Returns the {@link OperationDefinition} for a given operation.
 * @param operation
 * @return
 */
@Operation(summary = "Retrieve an operation definition by its name", description = "Retrieves an operation definition by its compound name (resource$operation).")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "Operation definition not found") })
@GetMapping(value = "/OperationDefinition/{operation}")
public OperationDefinition operationDefinition(@PathVariable(value = "operation") final String operation) {
    final Map<String, OperationDefinition> operationMap = capabilityStatementSupplier.get().operationMap;
    final OperationDefinition operationDefinition = operationMap.get(operation);
    if (operationDefinition == null) {
        throw new NotFoundException("OperationDefinition", operation);
    }
    return operationDefinition;
}
Also used : NotFoundException(com.b2international.commons.exceptions.NotFoundException) OperationDefinition(com.b2international.snowowl.fhir.core.model.operationdefinition.OperationDefinition) GetMapping(org.springframework.web.bind.annotation.GetMapping) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 15 with Link

use of io.swagger.v3.oas.models.links.Link in project snow-owl by b2ihealthcare.

the class FhirConceptMapTranslateOperationController method translate.

/**
 * HTTP Get request to translate a code that could belongs to any {@link ConceptMap} in the system.
 * @return translation of the code
 */
@Operation(summary = "Translate a code", description = "Translate a code from one value set to another, based on the existing value set and concept maps resources, and/or other additional knowledge available to the server.")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "Bad request"), @ApiResponse(responseCode = "404", description = "Concept map not found") })
@GetMapping(value = "/$translate")
public Promise<Parameters.Fhir> translate(@Parameter(description = "The code to translate") @RequestParam(value = "code") final String code, @Parameter(description = "The code system's uri") @RequestParam(value = "system") final String system, @Parameter(description = "The code system's version, if null latest is used") @RequestParam(value = "version") final Optional<String> version, @Parameter(description = "The source value set") @RequestParam(value = "source") final Optional<String> source, @Parameter(description = "Value set in which a translation is sought") @RequestParam(value = "target") final Optional<String> target, @Parameter(description = "Target code system") @RequestParam(value = "targetsystem") final Optional<String> targetSystem, @Parameter(description = "If true, the mapping is reversed") @RequestParam(value = "reverse") final Optional<Boolean> isReverse) {
    // validation is triggered by builder.build()
    Builder builder = TranslateRequest.builder().code(code).system(system);
    version.ifPresent(builder::version);
    if (source.isPresent()) {
        builder.source(source.get());
    }
    if (target.isPresent()) {
        builder.target(target.get());
    }
    if (targetSystem.isPresent()) {
        builder.targetSystem(targetSystem.get());
    }
    if (isReverse.isPresent()) {
        builder.isReverse(isReverse.get());
    }
    return doTranslate(builder.build());
}
Also used : Builder(com.b2international.snowowl.fhir.core.model.conceptmap.TranslateRequest.Builder) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Aggregations

OpenAPI (io.swagger.v3.oas.models.OpenAPI)8 Test (org.testng.annotations.Test)8 Link (io.swagger.v3.oas.models.links.Link)7 Operation (io.swagger.v3.oas.annotations.Operation)5 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)5 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)5 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)5 Components (io.swagger.v3.oas.models.Components)4 Operation (io.swagger.v3.oas.models.Operation)4 PathItem (io.swagger.v3.oas.models.PathItem)4 Info (io.swagger.v3.oas.models.info.Info)3 Content (io.swagger.v3.oas.models.media.Content)3 MediaType (io.swagger.v3.oas.models.media.MediaType)3 Schema (io.swagger.v3.oas.models.media.Schema)3 StringSchema (io.swagger.v3.oas.models.media.StringSchema)3 ValidateCodeRequest (com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest)2 Fhir (com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir)2 Json (com.b2international.snowowl.fhir.core.model.dt.Parameters.Json)2 Paths (io.swagger.v3.oas.models.Paths)2 Contact (io.swagger.v3.oas.models.info.Contact)2