Search in sources :

Example 1 with B2I_OPENAPI_X_NAME

use of com.b2international.snowowl.core.rest.OpenAPIExtensions.B2I_OPENAPI_X_NAME in project snow-owl by b2ihealthcare.

the class FhirMetadataController method collectResources.

private Collection<Resource> collectResources(final OpenAPI openAPI) {
    final Paths paths = openAPI.getPaths();
    final List<io.swagger.v3.oas.models.tags.Tag> tags = openAPI.getTags();
    return tags.stream().filter(t -> t.getExtensions() != null && t.getExtensions().containsKey(B2I_OPENAPI_X_NAME)).map(t -> {
        final Map<?, ?> nameExtensionMap = (Map<?, ?>) t.getExtensions().get(B2I_OPENAPI_X_NAME);
        final String profile = (String) nameExtensionMap.get(B2I_OPENAPI_PROFILE);
        final Resource.Builder resourceBuilder = Resource.builder().type(t.getName()).profile(profile);
        // Collect the operations that belong to the same tagged class resource
        paths.values().stream().flatMap(pi -> pi.readOperations().stream()).filter(o -> o.getTags().contains(t.getName()) && o.getExtensions() != null && o.getExtensions().containsKey(B2I_OPENAPI_X_INTERACTION)).forEachOrdered(op -> {
            final Map<String, Object> operationExtensionMap = op.getExtensions();
            final Map<?, ?> interactionMap = (Map<?, ?>) operationExtensionMap.get(B2I_OPENAPI_X_INTERACTION);
            interactionMap.entrySet().forEach(e -> {
                final Interaction.Builder interactionBuilder = Interaction.builder().code((String) e.getKey());
                final String value = (String) e.getValue();
                if (!StringUtils.isEmpty(value)) {
                    interactionBuilder.documentation((String) value);
                }
                resourceBuilder.addInteraction(interactionBuilder.build());
            });
        });
        return resourceBuilder.build();
    }).sorted(Comparator.comparing(r -> r.getType().getCodeValue())).collect(Collectors.toList());
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Iterables(com.google.common.collect.Iterables) OpenApiWebMvcResource(org.springdoc.webmvc.api.OpenApiWebMvcResource) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Uri(com.b2international.snowowl.fhir.core.model.dt.Uri) SnowOwlOpenApiWebMvcResource(com.b2international.snowowl.core.rest.SnowOwlOpenApiWebMvcResource) OperationDefinition(com.b2international.snowowl.fhir.core.model.operationdefinition.OperationDefinition) Supplier(java.util.function.Supplier) FhirApiConfig(com.b2international.snowowl.core.rest.FhirApiConfig) Code(com.b2international.snowowl.fhir.core.model.dt.Code) Extension(io.swagger.v3.oas.annotations.extensions.Extension) Operation(io.swagger.v3.oas.annotations.Operation) StringUtils(com.b2international.commons.StringUtils) MvcUriComponentsBuilder(org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder) B2I_OPENAPI_PROFILE(com.b2international.snowowl.core.rest.OpenAPIExtensions.B2I_OPENAPI_PROFILE) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Map(java.util.Map) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) GetMapping(org.springframework.web.bind.annotation.GetMapping) Suppliers(com.google.common.base.Suppliers) OperationKind(com.b2international.snowowl.fhir.core.codesystems.OperationKind) Schema(io.swagger.v3.oas.models.media.Schema) SnowOwlConfiguration(com.b2international.snowowl.core.config.SnowOwlConfiguration) NotFoundException(com.b2international.commons.exceptions.NotFoundException) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Collection(java.util.Collection) RestfulCapabilityMode(com.b2international.snowowl.fhir.core.codesystems.RestfulCapabilityMode) PathItem(io.swagger.v3.oas.models.PathItem) ExtensionProperty(io.swagger.v3.oas.annotations.extensions.ExtensionProperty) Paths(io.swagger.v3.oas.models.Paths) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) List(java.util.List) Tag(io.swagger.v3.oas.annotations.tags.Tag) CoreActivator(com.b2international.snowowl.core.CoreActivator) CapabilityStatementKind(com.b2international.snowowl.fhir.core.codesystems.CapabilityStatementKind) Platform(org.eclipse.core.runtime.Platform) Parameter(com.b2international.snowowl.fhir.core.model.operationdefinition.Parameter) B2I_OPENAPI_INTERACTION_READ(com.b2international.snowowl.core.rest.OpenAPIExtensions.B2I_OPENAPI_INTERACTION_READ) B2I_OPENAPI_X_NAME(com.b2international.snowowl.core.rest.OpenAPIExtensions.B2I_OPENAPI_X_NAME) PublicationStatus(com.b2international.snowowl.fhir.core.codesystems.PublicationStatus) Comparator(java.util.Comparator) ApplicationContext(com.b2international.snowowl.core.ApplicationContext) com.b2international.snowowl.fhir.core.model.capabilitystatement(com.b2international.snowowl.fhir.core.model.capabilitystatement) B2I_OPENAPI_X_INTERACTION(com.b2international.snowowl.core.rest.OpenAPIExtensions.B2I_OPENAPI_X_INTERACTION) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses) OpenApiWebMvcResource(org.springdoc.webmvc.api.OpenApiWebMvcResource) SnowOwlOpenApiWebMvcResource(com.b2international.snowowl.core.rest.SnowOwlOpenApiWebMvcResource) Paths(io.swagger.v3.oas.models.Paths) Tag(io.swagger.v3.oas.annotations.tags.Tag) Map(java.util.Map) Maps.newHashMap(com.google.common.collect.Maps.newHashMap)

Aggregations

StringUtils (com.b2international.commons.StringUtils)1 NotFoundException (com.b2international.commons.exceptions.NotFoundException)1 ApplicationContext (com.b2international.snowowl.core.ApplicationContext)1 CoreActivator (com.b2international.snowowl.core.CoreActivator)1 SnowOwlConfiguration (com.b2international.snowowl.core.config.SnowOwlConfiguration)1 FhirApiConfig (com.b2international.snowowl.core.rest.FhirApiConfig)1 B2I_OPENAPI_INTERACTION_READ (com.b2international.snowowl.core.rest.OpenAPIExtensions.B2I_OPENAPI_INTERACTION_READ)1 B2I_OPENAPI_PROFILE (com.b2international.snowowl.core.rest.OpenAPIExtensions.B2I_OPENAPI_PROFILE)1 B2I_OPENAPI_X_INTERACTION (com.b2international.snowowl.core.rest.OpenAPIExtensions.B2I_OPENAPI_X_INTERACTION)1 B2I_OPENAPI_X_NAME (com.b2international.snowowl.core.rest.OpenAPIExtensions.B2I_OPENAPI_X_NAME)1 SnowOwlOpenApiWebMvcResource (com.b2international.snowowl.core.rest.SnowOwlOpenApiWebMvcResource)1 CapabilityStatementKind (com.b2international.snowowl.fhir.core.codesystems.CapabilityStatementKind)1 OperationKind (com.b2international.snowowl.fhir.core.codesystems.OperationKind)1 PublicationStatus (com.b2international.snowowl.fhir.core.codesystems.PublicationStatus)1 RestfulCapabilityMode (com.b2international.snowowl.fhir.core.codesystems.RestfulCapabilityMode)1 com.b2international.snowowl.fhir.core.model.capabilitystatement (com.b2international.snowowl.fhir.core.model.capabilitystatement)1 Code (com.b2international.snowowl.fhir.core.model.dt.Code)1 Uri (com.b2international.snowowl.fhir.core.model.dt.Uri)1 OperationDefinition (com.b2international.snowowl.fhir.core.model.operationdefinition.OperationDefinition)1 Parameter (com.b2international.snowowl.fhir.core.model.operationdefinition.Parameter)1