Search in sources :

Example 1 with ApiDescription

use of io.swagger.v3.core.model.ApiDescription in project swagger-core by swagger-api.

the class SpecFilter method filterResponse.

protected ApiResponse filterResponse(OpenAPISpecFilter filter, Operation operation, ApiResponse response, String resourcePath, String key, Map<String, List<String>> params, Map<String, String> cookies, Map<String, List<String>> headers) {
    if (response != null) {
        ApiDescription description = new ApiDescription(resourcePath, key);
        Optional<ApiResponse> filteredResponse = filter.filterResponse(response, operation, description, params, cookies, headers);
        if (filteredResponse.isPresent()) {
            return filteredResponse.get();
        }
    }
    return null;
}
Also used : ApiDescription(io.swagger.v3.core.model.ApiDescription) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse)

Example 2 with ApiDescription

use of io.swagger.v3.core.model.ApiDescription in project swagger-core by swagger-api.

the class SpecFilter method filterRequestBody.

protected RequestBody filterRequestBody(OpenAPISpecFilter filter, Operation operation, RequestBody requestBody, String resourcePath, String key, Map<String, List<String>> params, Map<String, String> cookies, Map<String, List<String>> headers) {
    if (requestBody != null) {
        ApiDescription description = new ApiDescription(resourcePath, key);
        Optional<RequestBody> filteredRequestBody = filter.filterRequestBody(requestBody, operation, description, params, cookies, headers);
        if (filteredRequestBody.isPresent()) {
            return filteredRequestBody.get();
        }
    }
    return null;
}
Also used : ApiDescription(io.swagger.v3.core.model.ApiDescription) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody)

Example 3 with ApiDescription

use of io.swagger.v3.core.model.ApiDescription in project swagger-core by swagger-api.

the class SpecFilter method filterParameter.

protected Parameter filterParameter(OpenAPISpecFilter filter, Operation operation, Parameter parameter, String resourcePath, String key, Map<String, List<String>> params, Map<String, String> cookies, Map<String, List<String>> headers) {
    if (parameter != null) {
        ApiDescription description = new ApiDescription(resourcePath, key);
        Optional<Parameter> filteredParameter = filter.filterParameter(parameter, operation, description, params, cookies, headers);
        if (filteredParameter.isPresent()) {
            return filteredParameter.get();
        }
    }
    return null;
}
Also used : Parameter(io.swagger.v3.oas.models.parameters.Parameter) ApiDescription(io.swagger.v3.core.model.ApiDescription)

Example 4 with ApiDescription

use of io.swagger.v3.core.model.ApiDescription 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)

Example 5 with ApiDescription

use of io.swagger.v3.core.model.ApiDescription in project swagger-core by swagger-api.

the class SpecFilter method filterOperation.

protected Operation filterOperation(OpenAPISpecFilter filter, Operation operation, String resourcePath, String key, Map<String, List<String>> params, Map<String, String> cookies, Map<String, List<String>> headers) {
    if (operation != null) {
        ApiDescription description = new ApiDescription(resourcePath, key);
        Optional<Operation> filteredOperation = filter.filterOperation(operation, description, params, cookies, headers);
        if (filteredOperation.isPresent()) {
            List<Parameter> filteredParameters = new ArrayList<>();
            Operation filteredOperationGet = filteredOperation.get();
            Operation clone = new Operation();
            clone.setCallbacks(filteredOperationGet.getCallbacks());
            clone.setDeprecated(filteredOperationGet.getDeprecated());
            clone.setDescription(filteredOperationGet.getDescription());
            clone.setExtensions(filteredOperationGet.getExtensions());
            clone.setExternalDocs(filteredOperationGet.getExternalDocs());
            clone.setOperationId(filteredOperationGet.getOperationId());
            clone.setSecurity(filteredOperationGet.getSecurity());
            clone.setServers(filteredOperationGet.getServers());
            clone.setSummary(filteredOperationGet.getSummary());
            clone.setTags(filteredOperationGet.getTags());
            List<Parameter> parameters = filteredOperationGet.getParameters();
            if (parameters != null) {
                for (Parameter parameter : parameters) {
                    Parameter filteredParameter = filterParameter(filter, operation, parameter, resourcePath, key, params, cookies, headers);
                    if (filteredParameter != null) {
                        filteredParameters.add(filteredParameter);
                    }
                }
                clone.setParameters(filteredParameters);
            }
            RequestBody requestBody = filteredOperation.get().getRequestBody();
            if (requestBody != null) {
                RequestBody filteredRequestBody = filterRequestBody(filter, operation, requestBody, resourcePath, key, params, cookies, headers);
                clone.setRequestBody(filteredRequestBody);
            }
            ApiResponses responses = filteredOperation.get().getResponses();
            ApiResponses clonedResponses = responses;
            if (responses != null) {
                responses.forEach((responseKey, response) -> {
                    ApiResponse filteredResponse = filterResponse(filter, operation, response, resourcePath, key, params, cookies, headers);
                    if (filteredResponse != null) {
                        clonedResponses.addApiResponse(responseKey, filteredResponse);
                    }
                });
                clone.setResponses(clonedResponses);
            }
            return clone;
        }
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) Parameter(io.swagger.v3.oas.models.parameters.Parameter) Operation(io.swagger.v3.oas.models.Operation) ApiDescription(io.swagger.v3.core.model.ApiDescription) ApiResponses(io.swagger.v3.oas.models.responses.ApiResponses) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody)

Aggregations

ApiDescription (io.swagger.v3.core.model.ApiDescription)5 Parameter (io.swagger.v3.oas.models.parameters.Parameter)2 RequestBody (io.swagger.v3.oas.models.parameters.RequestBody)2 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)2 Operation (io.swagger.v3.oas.models.Operation)1 PathItem (io.swagger.v3.oas.models.PathItem)1 Contact (io.swagger.v3.oas.models.info.Contact)1 Info (io.swagger.v3.oas.models.info.Info)1 License (io.swagger.v3.oas.models.info.License)1 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)1 SecurityRequirement (io.swagger.v3.oas.models.security.SecurityRequirement)1 SecurityScheme (io.swagger.v3.oas.models.security.SecurityScheme)1 In (io.swagger.v3.oas.models.security.SecurityScheme.In)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GroupedOpenApi (org.springdoc.core.GroupedOpenApi)1 Bean (org.springframework.context.annotation.Bean)1 ComponentScan (org.springframework.context.annotation.ComponentScan)1 Configuration (org.springframework.context.annotation.Configuration)1 AnnotationUtils (org.springframework.core.annotation.AnnotationUtils)1