Search in sources :

Example 91 with In

use of io.swagger.v3.oas.models.security.SecurityScheme.In in project snow-owl by b2ihealthcare.

the class FhirCodeSystemValidateCodeOperationController method validateCode.

/**
 * POST-based $validate-code end-point.
 * All parameters are in the request body, except the codeSystemId
 * @param body - FHIR parameters
 * @return out - FHIR parameters
 */
@Operation(summary = "Validate a code in a code system", description = "Validate that a coded value is in a code system.")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "400", description = "Bad request") })
@PostMapping(value = "/{codeSystemId:**}/$validate-code", consumes = AbstractFhirController.APPLICATION_FHIR_JSON)
public Promise<Parameters.Fhir> validateCode(@Parameter(description = "The id of the code system to validate against") @PathVariable("codeSystemId") String codeSystemId, @Parameter(description = "The validate-code request parameters") @RequestBody Parameters.Fhir body) {
    final ValidateCodeRequest request = toRequest(body, ValidateCodeRequest.class);
    // Validate for parameters that are not allowed on the instance level
    if (request.getUrl() != null) {
        throw new BadRequestException("Parameter 'url' cannot be specified when the code system ID is set.", "ValidateCodeRequest.url");
    }
    if (request.getCoding() != null) {
        throw new BadRequestException("Parameter 'coding' cannot be specified when the code system ID is set.", "ValidateCodeRequest.coding");
    }
    if (request.getCodeableConcept() != null) {
        throw new BadRequestException("Parameter 'codeableConcept' cannot be specified when the code system ID is set.", "ValidateCodeRequest.codeableConcept");
    }
    if (request.getCodeSystem() != null) {
        throw new BadRequestException("Validation against external code systems is not supported", "ValidateCodeRequest.codeSystem");
    }
    // before execution set the codesystem to the path variable
    request.setUrl(new Uri(codeSystemId));
    return FhirRequests.codeSystems().prepareValidateCode().setRequest(request).buildAsync().execute(getBus()).then(this::toResponse);
}
Also used : BadRequestException(com.b2international.snowowl.fhir.core.exceptions.BadRequestException) ValidateCodeRequest(com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest) Uri(com.b2international.snowowl.fhir.core.model.dt.Uri) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 92 with In

use of io.swagger.v3.oas.models.security.SecurityScheme.In in project snow-owl by b2ihealthcare.

the class FhirCodeSystemValidateCodeOperationController method validateCodeByUrl.

/**
 * HTTP Get request to validate that a coded value is in the code system specified by the URI parameter
 * The code system is identified by its Code System ID within the path
 * If the operation is not called at the instance level, one of the parameters "url" or "codeSystem" must be provided.
 * The operation returns a result (true / false), an error message, and the recommended display for the code.
 * When invoking this operation, a client SHALL provide one (and only one) of the parameters (code+system, coding, or codeableConcept).
 * Other parameters (including version and display) are optional.
 *
 * @param url the code system to validate against
 * @param code to code to validate
 * @param version the version of the code system to validate against
 * @param date the date for which the validation should be checked
 * @param isAbstract If this parameter has a value of true, the client is stating that the validation is being performed in a context
 * 			where a concept designated as 'abstract' is appropriate/allowed.
 *
 * @return validation results as {@link OperationOutcome}
 */
@Operation(summary = "Validate a code in a code system", description = "Validate that a coded value is in a code system.")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "Bad request"), @ApiResponse(responseCode = "404", description = "Code system not found") })
@GetMapping("/$validate-code")
public Promise<Parameters.Fhir> validateCodeByUrl(@Parameter(description = "The uri of the code system to validate against") @RequestParam("url") String url, @Parameter(description = "The code to be validated") @RequestParam(value = "code") final String code, @Parameter(description = "The version of the code system") @RequestParam(value = "version") final Optional<String> version, @Parameter(description = "The display string of the code") @RequestParam(value = "display") final Optional<String> display, @Parameter(description = "The date stamp of the code system to validate against") @RequestParam(value = "date") final Optional<String> date, @Parameter(description = "The abstract status of the code") @RequestParam(value = "abstract") final Optional<Boolean> isAbstract) {
    ValidateCodeRequest.Builder builder = ValidateCodeRequest.builder().url(url).code(code).version(version.orElse(null)).display(display.orElse(null)).isAbstract(isAbstract.orElse(null));
    if (date.isPresent()) {
        builder.date(date.get());
    }
    // Convert to FHIR parameters and delegate to the POST call
    Json json = new Parameters.Json(builder.build());
    Fhir fhir = new Parameters.Fhir(json.parameters());
    return validateCode(fhir);
}
Also used : Fhir(com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir) Json(com.b2international.snowowl.fhir.core.model.dt.Parameters.Json) ValidateCodeRequest(com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 93 with In

use of io.swagger.v3.oas.models.security.SecurityScheme.In in project snow-owl by b2ihealthcare.

the class FhirCodeSystemSubsumesOperationController method subsumes.

/*
	 * Subsumes POST method without codeSystemId and body
	 */
@Operation(summary = "Subsumption testing", description = "Test the subsumption relationship between code/Coding A and code/Coding B given the semantics of subsumption in the underlying code system (see hierarchyMeaning).")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "400", description = "Bad request") })
@PostMapping(value = "/$subsumes", consumes = AbstractFhirController.APPLICATION_FHIR_JSON)
public Promise<Parameters.Fhir> subsumes(@Parameter(description = "The lookup request parameters") @RequestBody Parameters.Fhir body) {
    SubsumptionRequest request = toRequest(body, SubsumptionRequest.class);
    validateSubsumptionRequest(request);
    return FhirRequests.codeSystems().prepareSubsumes().setRequest(request).buildAsync().execute(getBus()).then(this::toResponse);
}
Also used : SubsumptionRequest(com.b2international.snowowl.fhir.core.model.codesystem.SubsumptionRequest) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 94 with In

use of io.swagger.v3.oas.models.security.SecurityScheme.In in project snow-owl by b2ihealthcare.

the class FhirBundleController method getBatchResponse.

@Operation(summary = "Perform batch operations", description = "Executes the FHIR requests included in the bundle provided.")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "Bad Request") })
@RequestMapping(value = "/", method = RequestMethod.POST, consumes = AbstractFhirController.APPLICATION_FHIR_JSON)
public Promise<Bundle> getBatchResponse(@Parameter(name = "bundle", description = "The bundle including the list of requests to perform") @RequestBody final Bundle bundle, HttpServletRequest request) throws JsonProcessingException {
    Collection<Entry> entries = bundle.getEntry();
    Bundle responseBundle = Bundle.builder().language("en").type(BundleType.BATCH_RESPONSE).build();
    ObjectNode rootNode = (ObjectNode) objectMapper.valueToTree(responseBundle);
    ArrayNode arrayNode = rootNode.putArray("entry");
    for (Entry entry : entries) {
        FhirBatchRequestProcessor requestProcessor = FhirBatchRequestProcessor.getInstance(entry, objectMapper, this);
        requestProcessor.process(arrayNode, request);
    }
    Bundle treeToValue = objectMapper.treeToValue(rootNode, Bundle.class);
    return Promise.immediate(treeToValue);
}
Also used : Entry(com.b2international.snowowl.fhir.core.model.Entry) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Bundle(com.b2international.snowowl.fhir.core.model.Bundle) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 95 with In

use of io.swagger.v3.oas.models.security.SecurityScheme.In in project snow-owl by b2ihealthcare.

the class BaseApiConfig method docs.

/**
 * Expose this as @Bean annotated component in the implementation configuration class.
 * @return a configured docket for this API module
 */
protected final GroupedOpenApi docs(final String apiBaseUrl, final String apiGroup, final String apiVersion, final String apiTitle, final String apiTermsOfServiceUrl, final String apiContact, final String apiLicense, final String apiLicenseUrl, final String apiDescription) {
    return GroupedOpenApi.builder().group(apiGroup).pathsToMatch(apiBaseUrl.endsWith("/") ? apiBaseUrl + "**" : apiBaseUrl + "/**").packagesToScan(getApiBasePackages()).addOpenApiCustomiser(api -> {
        Info apiInfo = api.getInfo();
        apiInfo.setTitle(apiTitle);
        apiInfo.setDescription(apiDescription);
        apiInfo.setVersion(apiVersion);
        apiInfo.setTermsOfService(apiTermsOfServiceUrl);
        Contact contact = new Contact();
        contact.setName("B2i Healthcare");
        contact.setEmail(apiContact);
        contact.setUrl(apiLicenseUrl);
        apiInfo.setContact(contact);
        License license = new License();
        license.setName(apiLicense);
        license.setUrl(apiLicenseUrl);
        apiInfo.setLicense(license);
        // configure global security
        api.getComponents().addSecuritySchemes("basic", new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")).addSecuritySchemes("bearer", new SecurityScheme().type(SecurityScheme.Type.APIKEY).scheme("bearer").in(In.HEADER).bearerFormat("JWT"));
        // disable servers prop
        api.setServers(List.of());
    }).addOperationCustomizer((operation, method) -> {
        return operation.addSecurityItem(new SecurityRequirement().addList("basic").addList("bearer"));
    }).build();
// .useDefaultResponseMessages(false)
// .alternateTypeRules(getAlternateTypeRules(resolver));
}
Also used : Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) License(io.swagger.v3.oas.models.info.License) SecurityScheme(io.swagger.v3.oas.models.security.SecurityScheme) Contact(io.swagger.v3.oas.models.info.Contact) In(io.swagger.v3.oas.models.security.SecurityScheme.In) GroupedOpenApi(org.springdoc.core.GroupedOpenApi) AnnotationUtils(org.springframework.core.annotation.AnnotationUtils) Info(io.swagger.v3.oas.models.info.Info) SecurityRequirement(io.swagger.v3.oas.models.security.SecurityRequirement) Bean(org.springframework.context.annotation.Bean) ComponentScan(org.springframework.context.annotation.ComponentScan) License(io.swagger.v3.oas.models.info.License) Info(io.swagger.v3.oas.models.info.Info) SecurityScheme(io.swagger.v3.oas.models.security.SecurityScheme) Contact(io.swagger.v3.oas.models.info.Contact) SecurityRequirement(io.swagger.v3.oas.models.security.SecurityRequirement)

Aggregations

Test (org.testng.annotations.Test)130 OpenAPI (io.swagger.v3.oas.models.OpenAPI)108 Parameter (io.swagger.v3.oas.models.parameters.Parameter)51 Schema (io.swagger.v3.oas.models.media.Schema)49 StringSchema (io.swagger.v3.oas.models.media.StringSchema)44 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)40 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)39 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)39 Operation (io.swagger.v3.oas.annotations.Operation)36 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)36 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)31 Operation (io.swagger.v3.oas.models.Operation)28 PathItem (io.swagger.v3.oas.models.PathItem)27 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)27 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)25 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)25 Map (java.util.Map)25 HashMap (java.util.HashMap)23 PathParameter (io.swagger.v3.oas.models.parameters.PathParameter)22 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)21