Search in sources :

Example 6 with Extension

use of io.apicurio.datamodels.core.models.Extension in project carbon-apimgt by wso2.

the class APIMappingUtil method getScopesFromAsyncAPI.

private static List<ScopeDTO> getScopesFromAsyncAPI(String asyncAPIDefinition) {
    Aai20Document document = (Aai20Document) Library.readDocumentFromJSONString(asyncAPIDefinition);
    List<ScopeDTO> scopeDTOS = new ArrayList<>();
    if (document.components == null || document.components.securitySchemes == null || document.components.securitySchemes.get("oauth2") == null) {
        return scopeDTOS;
    }
    AaiSecurityScheme securityScheme = document.components.securitySchemes.get("oauth2");
    if (securityScheme.flows == null || securityScheme.flows.implicit == null || securityScheme.flows.implicit.scopes == null) {
        return scopeDTOS;
    }
    Map<String, String> scopes = securityScheme.flows.implicit.scopes;
    Map<String, String> scopeBindings = new HashMap<>();
    Extension xScopesBindings = securityScheme.flows.implicit.getExtension("x-scopes-bindings");
    if (xScopesBindings != null) {
        scopeBindings = (Map<String, String>) xScopesBindings.value;
    }
    for (Map.Entry<String, String> aScope : scopes.entrySet()) {
        ScopeDTO scopeDTO = new ScopeDTO();
        scopeDTO.setName(aScope.getKey());
        scopeDTO.setDisplayName(aScope.getKey());
        scopeDTO.setDescription(aScope.getValue());
        String roles = scopeBindings.get(aScope.getKey());
        if (roles == null || roles.isEmpty()) {
            scopeDTO.setBindings(Collections.emptyList());
        } else {
            scopeDTO.setBindings(Arrays.asList((roles).split(",")));
        }
        scopeDTOS.add(scopeDTO);
    }
    return scopeDTOS;
}
Also used : Extension(io.apicurio.datamodels.core.models.Extension) AaiSecurityScheme(io.apicurio.datamodels.asyncapi.models.AaiSecurityScheme) HashMap(java.util.HashMap) ScopeDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeDTO) APIScopeDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIScopeDTO) Aai20Document(io.apicurio.datamodels.asyncapi.v2.models.Aai20Document) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Extension (io.apicurio.datamodels.core.models.Extension)6 Aai20Document (io.apicurio.datamodels.asyncapi.v2.models.Aai20Document)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 LinkedHashMap (java.util.LinkedHashMap)3 Scope (org.wso2.carbon.apimgt.api.model.Scope)3 Aai20SecurityScheme (io.apicurio.datamodels.asyncapi.v2.models.Aai20SecurityScheme)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AaiChannelItem (io.apicurio.datamodels.asyncapi.models.AaiChannelItem)1 AaiOperation (io.apicurio.datamodels.asyncapi.models.AaiOperation)1 AaiSecurityScheme (io.apicurio.datamodels.asyncapi.models.AaiSecurityScheme)1 Aai20ImplicitOAuthFlow (io.apicurio.datamodels.asyncapi.v2.models.Aai20ImplicitOAuthFlow)1 Aai20OAuthFlows (io.apicurio.datamodels.asyncapi.v2.models.Aai20OAuthFlows)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)1 APIScopeDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIScopeDTO)1 ScopeDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeDTO)1