use of org.wso2.carbon.apimgt.api.model.API in project carbon-apimgt by wso2.
the class APIDefinitionFromSwagger20 method setApiResourceBuilderProperties.
/**
* Extract properties in Operation entry and assign them to api resource builder properties.
*
* @param operationEntry Map entry to be extracted properties
* @param uriTemplateBuilder Uri template builder to assign related properties
* @param resourcePath resource path
* @return APIResource.Builder object
*/
private APIResource.Builder setApiResourceBuilderProperties(Map.Entry<HttpMethod, Operation> operationEntry, UriTemplate.UriTemplateBuilder uriTemplateBuilder, String resourcePath) {
Operation operation = operationEntry.getValue();
APIResource.Builder apiResourceBuilder = new APIResource.Builder();
List<String> producesList = operation.getProduces();
if (producesList != null) {
String produceSeparatedString = "\"";
produceSeparatedString += String.join("\",\"", producesList) + "\"";
apiResourceBuilder.produces(produceSeparatedString);
}
List<String> consumesList = operation.getConsumes();
if (consumesList != null) {
String consumesSeparatedString = "\"";
consumesSeparatedString += String.join("\",\"", consumesList) + "\"";
apiResourceBuilder.consumes(consumesSeparatedString);
}
if (operation.getOperationId() != null) {
uriTemplateBuilder.templateId(operation.getOperationId());
} else {
uriTemplateBuilder.templateId(APIUtils.generateOperationIdFromPath(resourcePath, operationEntry.getKey().name()));
}
uriTemplateBuilder.httpVerb(operationEntry.getKey().name());
apiResourceBuilder.uriTemplate(uriTemplateBuilder.build());
return apiResourceBuilder;
}
use of org.wso2.carbon.apimgt.api.model.API in project carbon-apimgt by wso2.
the class APIDefinitionFromSwagger20 method generateSwaggerFromResources.
@Override
public String generateSwaggerFromResources(CompositeAPI.Builder api) {
Swagger swagger = new Swagger();
Info info = new Info();
info.setTitle(api.getName());
info.setDescription(api.getDescription());
info.setVersion(api.getVersion());
swagger.setInfo(info);
Map<String, Path> stringPathMap = new HashMap();
for (UriTemplate uriTemplate : api.getUriTemplates().values()) {
String uriTemplateString = uriTemplate.getUriTemplate();
List<Parameter> parameterList = getParameters(uriTemplateString);
if (!HttpMethod.GET.toString().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.DELETE.toString().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.OPTIONS.toString().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.HEAD.toString().equalsIgnoreCase(uriTemplate.getHttpVerb())) {
parameterList.add(getDefaultBodyParameter());
}
Operation operation = new Operation();
operation.setParameters(parameterList);
operation.setOperationId(uriTemplate.getTemplateId());
operation.addResponse("200", getDefaultResponse());
if (stringPathMap.containsKey(uriTemplateString)) {
Path path = stringPathMap.get(uriTemplateString);
path.set(uriTemplate.getHttpVerb().toLowerCase(), operation);
} else {
Path path = new Path();
path.set(uriTemplate.getHttpVerb().toLowerCase(), operation);
stringPathMap.put(uriTemplateString, path);
}
}
swagger.setPaths(stringPathMap);
swagger.setPaths(stringPathMap);
return Json.pretty(swagger);
}
use of org.wso2.carbon.apimgt.api.model.API in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method addCompositeAPI.
/**
* @see APIGateway#addCompositeAPI(CompositeAPI api)
*/
@Override
public void addCompositeAPI(CompositeAPI api) throws GatewayException {
// build the message to send
APIEvent gatewayDTO = new APIEvent(APIMgtConstants.GatewayEventTypes.API_CREATE);
gatewayDTO.setLabels(api.getLabels());
APISummary apiSummary = new APISummary();
apiSummary.setName(api.getName());
apiSummary.setVersion(api.getVersion());
apiSummary.setContext(api.getContext());
apiSummary.setThreatProtectionPolicies(api.getThreatProtectionPolicies());
gatewayDTO.setApiSummary(apiSummary);
publishToPublisherTopic(gatewayDTO);
}
use of org.wso2.carbon.apimgt.api.model.API in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method addAPI.
@Override
public void addAPI(API api) throws GatewayException {
// build the message to send
APIEvent apiCreateEvent = new APIEvent(APIMgtConstants.GatewayEventTypes.API_CREATE);
apiCreateEvent.setLabels(api.getLabels());
apiCreateEvent.setApiSummary(toAPISummary(api));
publishToPublisherTopic(apiCreateEvent);
if (log.isDebugEnabled()) {
log.debug("API : " + api.getName() + " created event has been successfully published to broker");
}
}
use of org.wso2.carbon.apimgt.api.model.API in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method toAPISummary.
/**
* Convert API definition into APISummary
*
* @param api API definition
* @return The summary of the API
*/
private APISummary toAPISummary(API api) {
APISummary apiSummary = new APISummary();
apiSummary.setId(api.getId());
apiSummary.setName(api.getName());
apiSummary.setVersion(api.getVersion());
apiSummary.setContext(api.getContext());
apiSummary.setLifeCycleStatus(api.getLifeCycleStatus());
apiSummary.setLifeCycleStatus(api.getLifeCycleStatus());
apiSummary.setCreatedTime(api.getCreatedTime());
apiSummary.setLastUpdatedTime(api.getLastUpdatedTime());
apiSummary.setSecurityScheme(api.getSecurityScheme());
apiSummary.setThreatProtectionPolicies(api.getThreatProtectionPolicies());
return apiSummary;
}
Aggregations