use of org.ballerinalang.model.tree.ServiceNode in project ballerina by ballerina-lang.
the class SwaggerServiceMapper method parseConfigAnnotationAttachment.
/**
* Parses the ballerina.net.http@config annotation and builds swagger definition. Also create the consumes and
* produces annotations.
* @param service The ballerina service which has the annotation.
* @param swagger The swagger to build up.
*/
private void parseConfigAnnotationAttachment(ServiceNode service, Swagger swagger) {
Optional<? extends AnnotationAttachmentNode> httpConfigAnnotationAttachment = service.getAnnotationAttachments().stream().filter(a -> null != this.httpAlias && this.httpAlias.equals(a.getPackageAlias().getValue()) && "configuration".equals(a.getAnnotationName().getValue())).findFirst();
if (httpConfigAnnotationAttachment.isPresent()) {
Map<String, AnnotationAttachmentAttributeValueNode> configAttributes = this.listToMap(httpConfigAnnotationAttachment.get());
if (configAttributes.containsKey("basePath")) {
swagger.setBasePath(this.getStringLiteralValue(configAttributes.get("basePath")));
}
if (configAttributes.containsKey("host") && configAttributes.containsKey("port")) {
swagger.setHost(this.getStringLiteralValue(configAttributes.get("host")) + ":" + this.getStringLiteralValue(configAttributes.get("port")));
}
}
Optional<? extends AnnotationAttachmentNode> consumesAnnotationAttachment = service.getAnnotationAttachments().stream().filter(a -> null != this.httpAlias && this.httpAlias.equals(a.getPackageAlias().getValue()) && "Consumes".equals(a.getAnnotationName().getValue())).findFirst();
if (consumesAnnotationAttachment.isPresent()) {
Map<String, AnnotationAttachmentAttributeValueNode> consumesAttributes = this.listToMap(consumesAnnotationAttachment.get());
List<String> consumes = new LinkedList<>();
for (AnnotationAttachmentAttributeValueNode consumesValue : consumesAttributes.get("value").getValueArray()) {
consumes.add(this.getStringLiteralValue(consumesValue));
}
swagger.setConsumes(consumes);
}
Optional<? extends AnnotationAttachmentNode> producesAnnotationAttachment = service.getAnnotationAttachments().stream().filter(a -> null != this.httpAlias && this.httpAlias.equals(a.getPackageAlias().getValue()) && "Produces".equals(a.getAnnotationName().getValue())).findFirst();
if (producesAnnotationAttachment.isPresent()) {
Map<String, AnnotationAttachmentAttributeValueNode> consumesAttributes = this.listToMap(producesAnnotationAttachment.get());
List<String> produces = new LinkedList<>();
for (AnnotationAttachmentAttributeValueNode consumesValue : consumesAttributes.get("value").getValueArray()) {
produces.add(this.getStringLiteralValue(consumesValue));
}
swagger.setProduces(produces);
}
}
use of org.ballerinalang.model.tree.ServiceNode in project ballerina by ballerina-lang.
the class SwaggerServiceMapper method parseServiceConfigAnnotationAttachment.
/**
* Parses the 'ServiceConfig' annotation attachment.
* @param service The ballerina service which has that annotation attachment.
* @param swagger The swagger definition to build up.
*/
private void parseServiceConfigAnnotationAttachment(ServiceNode service, Swagger swagger) {
Optional<? extends AnnotationAttachmentNode> swaggerConfigAnnotation = service.getAnnotationAttachments().stream().filter(a -> null != swaggerAlias && this.swaggerAlias.equals(a.getPackageAlias().getValue()) && "ServiceConfig".equals(a.getAnnotationName().getValue())).findFirst();
if (swaggerConfigAnnotation.isPresent()) {
Map<String, AnnotationAttachmentAttributeValueNode> serviceConfigAttributes = this.listToMap(swaggerConfigAnnotation.get());
if (serviceConfigAttributes.containsKey("host")) {
swagger.setHost(this.getStringLiteralValue(serviceConfigAttributes.get("host")));
}
if (serviceConfigAttributes.containsKey("schemes") && serviceConfigAttributes.get("schemes").getValueArray().size() > 0) {
List<Scheme> schemes = new LinkedList<>();
for (AnnotationAttachmentAttributeValueNode schemesNodes : serviceConfigAttributes.get("schemes").getValueArray()) {
String schemeStringValue = this.getStringLiteralValue(schemesNodes);
if (null != Scheme.forValue(schemeStringValue)) {
schemes.add(Scheme.forValue(schemeStringValue));
}
}
if (schemes.size() > 0) {
schemes = Lists.reverse(schemes);
swagger.setSchemes(schemes);
}
}
this.createSecurityDefinitionsModel(serviceConfigAttributes.get("authorizations"), swagger);
}
}
Aggregations