Search in sources :

Example 1 with Aai20OAuthFlows

use of io.apicurio.datamodels.asyncapi.v2.models.Aai20OAuthFlows in project carbon-apimgt by wso2.

the class AsyncApiParser method updateAsyncAPIDefinition.

public String updateAsyncAPIDefinition(String oldDefinition, API apiToUpdate) {
    Aai20Document document = (Aai20Document) Library.readDocumentFromJSONString(oldDefinition);
    if (document.components == null) {
        document.components = document.createComponents();
    }
    // add scopes
    if (document.components.securitySchemes == null) {
        document.components.securitySchemes = new HashMap<>();
    }
    Aai20SecurityScheme oauth2SecurityScheme = new Aai20SecurityScheme(document.components, APIConstants.DEFAULT_API_SECURITY_OAUTH2);
    oauth2SecurityScheme.type = APIConstants.DEFAULT_API_SECURITY_OAUTH2;
    if (oauth2SecurityScheme.flows == null) {
        oauth2SecurityScheme.flows = new Aai20OAuthFlows(oauth2SecurityScheme);
    }
    if (oauth2SecurityScheme.flows.implicit == null) {
        oauth2SecurityScheme.flows.implicit = new Aai20ImplicitOAuthFlow(oauth2SecurityScheme.flows);
    }
    oauth2SecurityScheme.flows.implicit.authorizationUrl = "http://localhost:9999";
    Map<String, String> scopes = new HashMap<>();
    Map<String, String> scopeBindings = new HashMap<>();
    Iterator<Scope> iterator = apiToUpdate.getScopes().iterator();
    while (iterator.hasNext()) {
        Scope scope = iterator.next();
        scopes.put(scope.getName(), scope.getDescription());
        scopeBindings.put(scope.getName(), scope.getRoles());
    }
    oauth2SecurityScheme.flows.implicit.scopes = scopes;
    Extension xScopeBindings = oauth2SecurityScheme.flows.implicit.createExtension();
    xScopeBindings.name = APIConstants.SWAGGER_X_SCOPES_BINDINGS;
    xScopeBindings.value = scopeBindings;
    oauth2SecurityScheme.flows.implicit.addExtension(APIConstants.SWAGGER_X_SCOPES_BINDINGS, xScopeBindings);
    document.components.securitySchemes.put(APIConstants.DEFAULT_API_SECURITY_OAUTH2, oauth2SecurityScheme);
    return Library.writeDocumentToJSONString(document);
}
Also used : Extension(io.apicurio.datamodels.core.models.Extension) Aai20SecurityScheme(io.apicurio.datamodels.asyncapi.v2.models.Aai20SecurityScheme) Aai20ImplicitOAuthFlow(io.apicurio.datamodels.asyncapi.v2.models.Aai20ImplicitOAuthFlow) Scope(org.wso2.carbon.apimgt.api.model.Scope) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Aai20Document(io.apicurio.datamodels.asyncapi.v2.models.Aai20Document) Aai20OAuthFlows(io.apicurio.datamodels.asyncapi.v2.models.Aai20OAuthFlows)

Aggregations

Aai20Document (io.apicurio.datamodels.asyncapi.v2.models.Aai20Document)1 Aai20ImplicitOAuthFlow (io.apicurio.datamodels.asyncapi.v2.models.Aai20ImplicitOAuthFlow)1 Aai20OAuthFlows (io.apicurio.datamodels.asyncapi.v2.models.Aai20OAuthFlows)1 Aai20SecurityScheme (io.apicurio.datamodels.asyncapi.v2.models.Aai20SecurityScheme)1 Extension (io.apicurio.datamodels.core.models.Extension)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Scope (org.wso2.carbon.apimgt.api.model.Scope)1