Java Code Examples for io.swagger.v3.oas.models.security.OAuthFlows#setImplicit()

The following examples show how to use io.swagger.v3.oas.models.security.OAuthFlows#setImplicit() . 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: SwaggerConverter.java    From swagger-parser with Apache License 2.0 4 votes vote down vote up
private SecurityScheme convertOauth2SecurityScheme(SecuritySchemeDefinition definition) {
    SecurityScheme securityScheme = new SecurityScheme();
    OAuth2Definition oAuth2Definition = (OAuth2Definition) definition;
    OAuthFlows oAuthFlows = new OAuthFlows();
    OAuthFlow oAuthFlow = new OAuthFlow();

    securityScheme.setType(SecurityScheme.Type.OAUTH2);
    String flow = oAuth2Definition.getFlow();

    if (flow != null) {
        switch (flow) {
            case "implicit":
                oAuthFlow.setAuthorizationUrl(oAuth2Definition.getAuthorizationUrl());
                oAuthFlows.setImplicit(oAuthFlow);
                break;
            case "password":
                oAuthFlow.setTokenUrl(oAuth2Definition.getTokenUrl());
                oAuthFlows.setPassword(oAuthFlow);
                break;
            case "application":
                oAuthFlow.setTokenUrl(oAuth2Definition.getTokenUrl());
                oAuthFlows.setClientCredentials(oAuthFlow);
                break;
            case "accessCode":
                oAuthFlow.setAuthorizationUrl(oAuth2Definition.getAuthorizationUrl());
                oAuthFlow.setTokenUrl(oAuth2Definition.getTokenUrl());
                oAuthFlows.setAuthorizationCode(oAuthFlow);
                break;
        }
    }

    Scopes scopes = new Scopes();
    Map<String, String> oAuth2Scopes = oAuth2Definition.getScopes();
    if (oAuth2Scopes != null) {
        oAuth2Scopes.forEach((k, v) -> scopes.addString(k, v));
    }
    oAuthFlow.setScopes(scopes);

    securityScheme.setFlows(oAuthFlows);

    return securityScheme;
}
 
Example 2
Source File: OpenAPIDeserializer.java    From swagger-parser with Apache License 2.0 4 votes vote down vote up
public OAuthFlows getOAuthFlows(ObjectNode node, String location, ParseResult result) {
    if (node == null) {
        return null;
    }

    OAuthFlows oAuthFlows = new OAuthFlows();

    ObjectNode objectNode = getObject("implicit", node, false, location, result);
    if(objectNode!= null) {
        oAuthFlows.setImplicit(getOAuthFlow("implicit", objectNode, location, result));
    }

    objectNode = getObject("password", node, false, location, result);
    if(objectNode!= null) {
        oAuthFlows.setPassword(getOAuthFlow("password", objectNode, location, result));
    }

    objectNode = getObject("clientCredentials", node, false, location, result);
    if(objectNode!= null) {
        oAuthFlows.setClientCredentials(getOAuthFlow("clientCredentials", objectNode, location, result));
    }

    objectNode = getObject("authorizationCode", node, false, location, result);
    if(objectNode!= null) {
        oAuthFlows.setAuthorizationCode(getOAuthFlow("authorizationCode", objectNode, location, result));
    }

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

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


    return oAuthFlows;
}