Search in sources :

Example 6 with AaiChannelItem

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

the class AsyncApiParser method generateAsyncAPIDefinition.

public String generateAsyncAPIDefinition(API api) throws APIManagementException {
    Aai20Document aaiDocument = new Aai20Document();
    aaiDocument.info = aaiDocument.createInfo();
    aaiDocument.info.title = api.getId().getName();
    aaiDocument.info.version = api.getId().getVersion();
    if (!APIConstants.API_TYPE_WEBSUB.equals(api.getType())) {
        Aai20Server server = (Aai20Server) aaiDocument.createServer("production");
        JSONObject endpointConfig = new JSONObject(api.getEndpointConfig());
        server.url = endpointConfig.getJSONObject("production_endpoints").getString("url");
        server.protocol = api.getType().toLowerCase();
        aaiDocument.addServer("production", server);
    }
    Map<String, AaiChannelItem> channels = new HashMap<>();
    for (URITemplate uriTemplate : api.getUriTemplates()) {
        Aai20ChannelItem channelItem = aaiDocument.createChannelItem(uriTemplate.getUriTemplate());
        Aai20Operation subscribeOp = new Aai20Operation(channelItem, "subscribe");
        channelItem.subscribe = subscribeOp;
        if (APIConstants.API_TYPE_WS.equals(api.getType())) {
            Aai20Operation publishOp = new Aai20Operation(channelItem, "publish");
            channelItem.publish = publishOp;
        }
        channels.put(uriTemplate.getUriTemplate(), channelItem);
    }
    aaiDocument.channels = channels;
    return Library.writeDocumentToJSONString(aaiDocument);
}
Also used : AaiChannelItem(io.apicurio.datamodels.asyncapi.models.AaiChannelItem) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Aai20Document(io.apicurio.datamodels.asyncapi.v2.models.Aai20Document) URITemplate(org.wso2.carbon.apimgt.api.model.URITemplate) Aai20Server(io.apicurio.datamodels.asyncapi.v2.models.Aai20Server) Aai20ChannelItem(io.apicurio.datamodels.asyncapi.v2.models.Aai20ChannelItem) Aai20Operation(io.apicurio.datamodels.asyncapi.v2.models.Aai20Operation)

Aggregations

AaiChannelItem (io.apicurio.datamodels.asyncapi.models.AaiChannelItem)6 Aai20Document (io.apicurio.datamodels.asyncapi.v2.models.Aai20Document)5 Aai20ChannelItem (io.apicurio.datamodels.asyncapi.v2.models.Aai20ChannelItem)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 Aai20Operation (io.apicurio.datamodels.asyncapi.v2.models.Aai20Operation)2 Aai20Server (io.apicurio.datamodels.asyncapi.v2.models.Aai20Server)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 JSONObject (org.json.JSONObject)2 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)2 AaiOperation (io.apicurio.datamodels.asyncapi.models.AaiOperation)1 AaiParameter (io.apicurio.datamodels.asyncapi.models.AaiParameter)1 Extension (io.apicurio.datamodels.core.models.Extension)1 ArrayList (java.util.ArrayList)1 JSONArray (org.json.JSONArray)1 Scope (org.wso2.carbon.apimgt.api.model.Scope)1