Java Code Examples for io.swagger.v3.oas.models.security.SecurityScheme#setIn()

The following examples show how to use io.swagger.v3.oas.models.security.SecurityScheme#setIn() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProtoOpenAPI.java    From product-microgateway with Apache License 2.0 5 votes vote down vote up
private void addAPIKeySecurityScheme() {
    SecurityScheme scheme = new SecurityScheme();
    scheme.setType(SecurityScheme.Type.APIKEY);
    scheme.setName("api_key");
    scheme.setIn(SecurityScheme.In.HEADER);
    openAPI.getComponents().addSecuritySchemes(APIKEY_SCHEME, scheme);
    isAPIKeyEnabled = true;
}
 
Example 2
Source File: SwaggerConverter.java    From swagger-parser with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 3
Source File: OpenAPIDeserializer.java    From swagger-parser with Apache License 2.0 4 votes vote down vote up
public SecurityScheme getSecurityScheme(ObjectNode node, String location, ParseResult result) {
    if (node == null) {
        return null;
    }

    SecurityScheme securityScheme = new SecurityScheme();

    JsonNode ref = node.get("$ref");
    if (ref != null) {
        if (ref.getNodeType().equals(JsonNodeType.STRING)) {
            String mungedRef = mungedRef(ref.textValue());
            if (mungedRef != null) {
                securityScheme.set$ref(mungedRef);
            }else{
                securityScheme.set$ref(ref.textValue());
            }
            return securityScheme;
        } else {
            result.invalidType(location, "$ref", "string", node);
            return null;
        }
    }

    boolean descriptionRequired, bearerFormatRequired, nameRequired, inRequired, schemeRequired, flowsRequired, openIdConnectRequired;
    descriptionRequired = bearerFormatRequired = nameRequired = inRequired = schemeRequired = flowsRequired = openIdConnectRequired = false;

    String value = getString("type", node, true, location, result);
    if (StringUtils.isNotBlank(value)) {
        if (SecurityScheme.Type.APIKEY.toString().equals(value)) {
            securityScheme.setType(SecurityScheme.Type.APIKEY);
            nameRequired = inRequired = true;
        } else if (SecurityScheme.Type.HTTP.toString().equals(value)) {
            securityScheme.setType(SecurityScheme.Type.HTTP);
            schemeRequired = true;
        } else if (SecurityScheme.Type.OAUTH2.toString().equals(value)) {
            securityScheme.setType(SecurityScheme.Type.OAUTH2);
            flowsRequired = true;
        } else if (SecurityScheme.Type.OPENIDCONNECT.toString().equals(value)) {
            securityScheme.setType(SecurityScheme.Type.OPENIDCONNECT);
            openIdConnectRequired = true;
        }else{
            result.invalidType(location + ".type", "type", "http|apiKey|oauth2|openIdConnect ", node);
        }
    }
    value = getString("description", node, descriptionRequired, location, result);
    if (StringUtils.isNotBlank(value)) {
        securityScheme.setDescription(value);
    }

    value = getString("name", node, nameRequired, location, result);
    if (StringUtils.isNotBlank(value)) {
        securityScheme.setName(value);
    }

    final String securitySchemeIn = getString("in", node, inRequired, location, result);
    final Optional<SecurityScheme.In> matchingIn = Arrays.stream(SecurityScheme.In.values())
            .filter(in -> in.toString().equals(securitySchemeIn))
            .findFirst();

    securityScheme.setIn(matchingIn.orElse(null));

    value = getString("scheme", node, schemeRequired, location, result);
    if (StringUtils.isNotBlank(value)) {
        securityScheme.setScheme(value);
    }

    value = getString("bearerFormat", node, bearerFormatRequired, location, result);
    if (StringUtils.isNotBlank(value)) {
        securityScheme.setBearerFormat(value);
    }

    ObjectNode flowsObject = getObject("flows", node, flowsRequired, location, result);
    if (flowsObject!= null) {
        securityScheme.setFlows(getOAuthFlows(flowsObject, location, result));
    }

    value = getString("openIdConnectUrl", node, openIdConnectRequired, location, result);
    if (StringUtils.isNotBlank(value)) {
        securityScheme.setOpenIdConnectUrl(value);
    }

    Map <String,Object> extensions = getExtensions(node);
    if(extensions != null && extensions.size() > 0) {
        securityScheme.setExtensions(extensions);
    }

    Set<String> securitySchemeKeys = getKeys(node);
    for(String key : securitySchemeKeys) {
        if(!SECURITY_SCHEME_KEYS.contains(key) && !key.startsWith("x-")) {
            result.extra(location, key, node.get(key));
        }
    }

    return securityScheme;
}