Search in sources :

Example 31 with SecurityScheme

use of io.swagger.v3.oas.models.security.SecurityScheme in project swagger-parser by swagger-api.

the class ExternalRefProcessor method processRefToExternalSecurityScheme.

public String processRefToExternalSecurityScheme(String $ref, RefFormat refFormat) {
    String renamedRef = cache.getRenamedRef($ref);
    if (renamedRef != null) {
        return renamedRef;
    }
    final SecurityScheme securityScheme = cache.loadRef($ref, refFormat, SecurityScheme.class);
    if (securityScheme == null) {
        // stop!  There's a problem.  retain the original ref
        LOGGER.warn("unable to load model reference from `" + $ref + "`.  It may not be available " + "or the reference isn't a valid model schema");
        return $ref;
    }
    String newRef;
    if (openAPI.getComponents() == null) {
        openAPI.setComponents(new Components());
    }
    Map<String, SecurityScheme> securitySchemeMap = openAPI.getComponents().getSecuritySchemes();
    if (securitySchemeMap == null) {
        securitySchemeMap = new LinkedHashMap<>();
    }
    final String possiblyConflictingDefinitionName = computeDefinitionName($ref);
    SecurityScheme existingSecurityScheme = securitySchemeMap.get(possiblyConflictingDefinitionName);
    if (existingSecurityScheme != null) {
        LOGGER.debug("A model for " + existingSecurityScheme + " already exists");
        if (existingSecurityScheme.get$ref() != null) {
            // use the new model
            existingSecurityScheme = null;
        }
    }
    newRef = possiblyConflictingDefinitionName;
    cache.putRenamedRef($ref, newRef);
    if (existingSecurityScheme == null) {
        // don't overwrite existing model reference
        openAPI.getComponents().addSecuritySchemes(newRef, securityScheme);
        cache.addReferencedKey(newRef);
        String file = $ref.split("#/")[0];
        if (securityScheme.get$ref() != null) {
            RefFormat format = computeRefFormat(securityScheme.get$ref());
            if (isAnExternalRefFormat(format)) {
                securityScheme.set$ref(processRefToExternalSecurityScheme(securityScheme.get$ref(), format));
            } else {
                processRefToExternalSecurityScheme(file + securityScheme.get$ref(), RefFormat.RELATIVE);
            }
        }
    }
    return newRef;
}
Also used : Components(io.swagger.v3.oas.models.Components) RefUtils.computeRefFormat(io.swagger.v3.parser.util.RefUtils.computeRefFormat) RefUtils.isAnExternalRefFormat(io.swagger.v3.parser.util.RefUtils.isAnExternalRefFormat) RefFormat(io.swagger.v3.parser.models.RefFormat) SecurityScheme(io.swagger.v3.oas.models.security.SecurityScheme)

Example 32 with SecurityScheme

use of io.swagger.v3.oas.models.security.SecurityScheme in project swagger-parser by swagger-api.

the class SecuritySchemeProcessor method processSecurityScheme.

public SecurityScheme processSecurityScheme(SecurityScheme securityScheme) {
    if (securityScheme.get$ref() != null) {
        RefFormat refFormat = computeRefFormat(securityScheme.get$ref());
        String $ref = securityScheme.get$ref();
        SecurityScheme newSecurityScheme = cache.loadRef($ref, refFormat, SecurityScheme.class);
        if (newSecurityScheme != null) {
            return newSecurityScheme;
        }
    }
    return securityScheme;
}
Also used : RefFormat(io.swagger.v3.parser.models.RefFormat) RefUtils.computeRefFormat(io.swagger.v3.parser.util.RefUtils.computeRefFormat) SecurityScheme(io.swagger.v3.oas.models.security.SecurityScheme)

Example 33 with SecurityScheme

use of io.swagger.v3.oas.models.security.SecurityScheme in project swagger-parser by swagger-api.

the class SwaggerConverter method convertApiKeySecurityScheme.

private SecurityScheme convertApiKeySecurityScheme(SecuritySchemeDefinition definition) {
    SecurityScheme securityScheme = new SecurityScheme();
    ApiKeyAuthDefinition apiKeyAuthDefinition = (ApiKeyAuthDefinition) definition;
    securityScheme.setType(SecurityScheme.Type.APIKEY);
    securityScheme.setName(apiKeyAuthDefinition.getName());
    securityScheme.setIn(SecurityScheme.In.valueOf(apiKeyAuthDefinition.getIn().toString()));
    return securityScheme;
}
Also used : ApiKeyAuthDefinition(io.swagger.models.auth.ApiKeyAuthDefinition) SecurityScheme(io.swagger.v3.oas.models.security.SecurityScheme)

Example 34 with SecurityScheme

use of io.swagger.v3.oas.models.security.SecurityScheme in project swagger-parser by swagger-api.

the class SwaggerConverter method convert.

private SecurityScheme convert(SecuritySchemeDefinition definition) {
    SecurityScheme securityScheme;
    switch(definition.getType()) {
        case "basic":
            securityScheme = createBasicSecurityScheme();
            break;
        case "apiKey":
            securityScheme = convertApiKeySecurityScheme(definition);
            break;
        case "oauth2":
            securityScheme = convertOauth2SecurityScheme(definition);
            break;
        default:
            securityScheme = new SecurityScheme();
    }
    securityScheme.setDescription(definition.getDescription());
    securityScheme.setExtensions(convert(definition.getVendorExtensions()));
    return securityScheme;
}
Also used : SecurityScheme(io.swagger.v3.oas.models.security.SecurityScheme)

Example 35 with SecurityScheme

use of io.swagger.v3.oas.models.security.SecurityScheme in project flow by vaadin.

the class OpenAPIObjectGenerator method createBasicModel.

private OpenAPI createBasicModel() {
    OpenAPI openAPI = new OpenAPI();
    Info info = new Info();
    info.setTitle(configuration.getApplicationTitle());
    info.setVersion(configuration.getApplicationApiVersion());
    openAPI.setInfo(info);
    Paths paths = new Paths();
    openAPI.setPaths(paths);
    Server server = new Server();
    server.setUrl(configuration.getServerUrl());
    server.setDescription(configuration.getServerDescription());
    openAPI.setServers(Collections.singletonList(server));
    Components components = new Components();
    SecurityScheme vaadinConnectOAuth2Scheme = new SecurityScheme().type(SecurityScheme.Type.OAUTH2).flows(new OAuthFlows().password(new OAuthFlow().tokenUrl(VAADIN_CONNECT_OAUTH2_TOKEN_URL).scopes(new Scopes())));
    components.addSecuritySchemes(VAADIN_CONNECT_OAUTH2_SECURITY_SCHEME, vaadinConnectOAuth2Scheme);
    openAPI.components(components);
    return openAPI;
}
Also used : Components(io.swagger.v3.oas.models.Components) Server(io.swagger.v3.oas.models.servers.Server) OAuthFlows(io.swagger.v3.oas.models.security.OAuthFlows) OAuthFlow(io.swagger.v3.oas.models.security.OAuthFlow) Scopes(io.swagger.v3.oas.models.security.Scopes) Paths(io.swagger.v3.oas.models.Paths) Info(io.swagger.v3.oas.models.info.Info) OpenAPI(io.swagger.v3.oas.models.OpenAPI) SecurityScheme(io.swagger.v3.oas.models.security.SecurityScheme)

Aggregations

SecurityScheme (io.swagger.v3.oas.models.security.SecurityScheme)35 OpenAPI (io.swagger.v3.oas.models.OpenAPI)20 Components (io.swagger.v3.oas.models.Components)15 OAuthFlow (io.swagger.v3.oas.models.security.OAuthFlow)13 Scopes (io.swagger.v3.oas.models.security.Scopes)12 OAuthFlows (io.swagger.v3.oas.models.security.OAuthFlows)11 Test (org.testng.annotations.Test)11 SecurityRequirement (io.swagger.v3.oas.models.security.SecurityRequirement)8 Operation (io.swagger.v3.oas.models.Operation)7 PathItem (io.swagger.v3.oas.models.PathItem)7 Info (io.swagger.v3.oas.models.info.Info)7 HashMap (java.util.HashMap)6 LinkedHashMap (java.util.LinkedHashMap)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 MediaType (io.swagger.v3.oas.models.media.MediaType)5 Schema (io.swagger.v3.oas.models.media.Schema)5 Parameter (io.swagger.v3.oas.models.parameters.Parameter)5 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)5 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)5 ArrayList (java.util.ArrayList)5