use of io.apicurio.datamodels.asyncapi.v2.models.Aai20Operation in project carbon-apimgt by wso2.
the class AsyncApiParser method getURITemplates.
public Set<URITemplate> getURITemplates(String apiDefinition, boolean includePublish) throws APIManagementException {
Set<URITemplate> uriTemplates = new HashSet<>();
Set<Scope> scopes = getScopes(apiDefinition);
Aai20Document document = (Aai20Document) Library.readDocumentFromJSONString(apiDefinition);
if (document.channels != null && document.channels.size() > 0) {
for (Map.Entry<String, AaiChannelItem> entry : document.channels.entrySet()) {
Aai20ChannelItem channel = (Aai20ChannelItem) entry.getValue();
if (includePublish && channel.publish != null) {
uriTemplates.add(buildURITemplate(entry.getKey(), APIConstants.HTTP_VERB_PUBLISH, (Aai20Operation) channel.publish, scopes, channel));
}
if (channel.subscribe != null) {
uriTemplates.add(buildURITemplate(entry.getKey(), APIConstants.HTTP_VERB_SUBSCRIBE, (Aai20Operation) channel.subscribe, scopes, channel));
}
}
}
return uriTemplates;
}
use of io.apicurio.datamodels.asyncapi.v2.models.Aai20Operation 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);
}
Aggregations