use of org.ballerinalang.model.tree.AnnotationAttachmentNode in project ballerina by ballerina-lang.
the class SwaggerServiceMapper method createDevelopersModel.
/**
* Creates vendor extension for developers.
* @param annotationAttributeValue The annotation attribute value for developer vendor extension.
* @param info The info definition.
*/
private void createDevelopersModel(AnnotationAttachmentAttributeValueNode annotationAttributeValue, Info info) {
if (null != annotationAttributeValue) {
List<Developer> developers = new LinkedList<>();
for (AnnotationAttachmentAttributeValueNode value : annotationAttributeValue.getValueArray()) {
AnnotationAttachmentNode developerAnnotation = (AnnotationAttachmentNode) value.getValue();
Map<String, AnnotationAttachmentAttributeValueNode> developerAttributes = this.listToMap(developerAnnotation);
Developer developer = new Developer();
if (developerAttributes.containsKey("name")) {
developer.setName(this.getStringLiteralValue(developerAttributes.get("name")));
}
if (developerAttributes.containsKey("email")) {
developer.setEmail(this.getStringLiteralValue(developerAttributes.get("email")));
}
developers.add(developer);
}
info.setVendorExtension("x-developers", Lists.reverse(developers));
}
}
use of org.ballerinalang.model.tree.AnnotationAttachmentNode in project ballerina by ballerina-lang.
the class SwaggerServiceMapper method createTagModel.
/**
* Creates tag swagger definition.
* @param annotationAttributeValue The ballerina annotation attribute value for tag.
* @param swagger The swagger definition which the tags needs to be build on.
*/
private void createTagModel(AnnotationAttachmentAttributeValueNode annotationAttributeValue, Swagger swagger) {
if (null != annotationAttributeValue) {
List<Tag> tags = new LinkedList<>();
for (AnnotationAttachmentAttributeValueNode value : annotationAttributeValue.getValueArray()) {
AnnotationAttachmentNode tagAnnotation = (AnnotationAttachmentNode) value.getValue();
Map<String, AnnotationAttachmentAttributeValueNode> tagAttributes = this.listToMap(tagAnnotation);
Tag tag = new Tag();
if (tagAttributes.containsKey("name")) {
tag.setName(this.getStringLiteralValue(tagAttributes.get("name")));
}
if (tagAttributes.containsKey("description")) {
tag.setDescription(this.getStringLiteralValue(tagAttributes.get("description")));
}
tags.add(tag);
}
swagger.setTags(Lists.reverse(tags));
}
}
use of org.ballerinalang.model.tree.AnnotationAttachmentNode 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.AnnotationAttachmentNode 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);
}
}
use of org.ballerinalang.model.tree.AnnotationAttachmentNode in project ballerina by ballerina-lang.
the class ResourceContextHolder method buildContext.
public static ResourceContextHolder buildContext(ResourceNode resource) throws CodeGeneratorException {
ResourceContextHolder context = new ResourceContextHolder();
context.name = resource.getName().getValue();
context.parameters = new ArrayList<>();
for (VariableNode node : resource.getParameters()) {
ParameterContextHolder parameter = ParameterContextHolder.buildContext(node);
if (parameter != null) {
context.parameters.add(parameter);
}
}
// Iterate through all resource level annotations and find out resource configuration information
AnnotationAttachmentNode ann = GeneratorUtils.getAnnotationFromList(GeneratorConstants.RES_CONFIG_ANNOTATION, GeneratorConstants.HTTP_PKG_ALIAS, resource.getAnnotationAttachments());
if (ann == null) {
throw new CodeGeneratorException("Incomplete resource configuration found");
}
BLangRecordLiteral bLiteral = ((BLangRecordLiteral) ((BLangAnnotationAttachment) ann).getExpression());
List<BLangRecordLiteral.BLangRecordKeyValue> list = bLiteral.getKeyValuePairs();
Map<String, String[]> attrs = GeneratorUtils.getKeyValuePairAsMap(list);
// We don't expect multiple http methods to be supported by single action
// We only consider first content type for a single resource
context.method = attrs.get(GeneratorConstants.ATTR_METHODS) != null ? attrs.get(GeneratorConstants.ATTR_METHODS)[0] : null;
context.contentType = attrs.get(GeneratorConstants.ATTR_CONSUMES) != null ? attrs.get(GeneratorConstants.ATTR_CONSUMES)[0] : null;
String path = attrs.get(GeneratorConstants.ATTR_PATH) != null ? attrs.get(GeneratorConstants.ATTR_PATH)[0] : null;
context.path = context.getTemplatePath(path);
return context;
}
Aggregations