use of org.ballerinalang.model.tree.expressions.AnnotationAttachmentAttributeValueNode in project ballerina by ballerina-lang.
the class SwaggerResourceMapper method createTagModel.
/**
* Creates tag model for swagger operation.
* @param annotationAttributeValue The annotation attribute value which has tags.
* @param operation The swagger operation.
*/
private void createTagModel(AnnotationAttachmentAttributeValueNode annotationAttributeValue, Operation operation) {
if (null != annotationAttributeValue) {
if (annotationAttributeValue.getValueArray().size() > 0) {
List<String> tags = new LinkedList<>();
for (AnnotationAttachmentAttributeValueNode tagAttributeValue : annotationAttributeValue.getValueArray()) {
tags.add(this.getStringLiteralValue(tagAttributeValue));
}
operation.setTags(tags);
}
}
}
use of org.ballerinalang.model.tree.expressions.AnnotationAttachmentAttributeValueNode in project ballerina by ballerina-lang.
the class SwaggerResourceMapper method parseHttpResourceConfig.
/**
* Parses the 'http:resourceConfig' annotation attachment and build swagger operation.
* @param resource The ballerina resource definition.
* @param operationAdaptor The operation adaptor..
*/
private void parseHttpResourceConfig(ResourceNode resource, OperationAdaptor operationAdaptor) {
Optional<? extends AnnotationAttachmentNode> responsesAnnotation = resource.getAnnotationAttachments().stream().filter(a -> null != this.httpAlias && this.httpAlias.equals(a.getPackageAlias().getValue()) && "resourceConfig".equals(a.getAnnotationName().getValue())).findFirst();
if (responsesAnnotation.isPresent()) {
Map<String, AnnotationAttachmentAttributeValueNode> configAttributes = this.listToMap(responsesAnnotation.get());
if (configAttributes.containsKey("methods") && configAttributes.get("methods").getValueArray().size() > 0) {
List<? extends AnnotationAttachmentAttributeValueNode> methodsValues = configAttributes.get("methods").getValueArray();
// Since there is only one http method.
operationAdaptor.setHttpOperation(this.getStringLiteralValue(methodsValues.get(0)));
}
if (configAttributes.containsKey("path")) {
operationAdaptor.setPath(this.getStringLiteralValue(configAttributes.get("path")));
}
if (configAttributes.containsKey("produces") && configAttributes.get("produces").getValueArray().size() > 0) {
List<String> produces = new LinkedList<>();
List<? extends AnnotationAttachmentAttributeValueNode> producesValues = configAttributes.get("produces").getValueArray();
for (AnnotationAttachmentAttributeValueNode producesValue : producesValues) {
produces.add(this.getStringLiteralValue(producesValue));
}
operationAdaptor.getOperation().setProduces(produces);
}
if (configAttributes.containsKey("consumes") && configAttributes.get("consumes").getValueArray().size() > 0) {
List<String> consumes = new LinkedList<>();
List<? extends AnnotationAttachmentAttributeValueNode> consumesValues = configAttributes.get("consumes").getValueArray();
for (AnnotationAttachmentAttributeValueNode consumesValue : consumesValues) {
consumes.add(this.getStringLiteralValue(consumesValue));
}
operationAdaptor.getOperation().setConsumes(consumes);
}
}
}
use of org.ballerinalang.model.tree.expressions.AnnotationAttachmentAttributeValueNode in project ballerina by ballerina-lang.
the class SwaggerServiceMapper method createSecurityDefinitionsModel.
/**
* Creates the security definition models for swagger definition.
* @param annotationAttributeValue The annotation attribute value for security definitions.
* @param swagger The swagger definition.
*/
private void createSecurityDefinitionsModel(AnnotationAttachmentAttributeValueNode annotationAttributeValue, Swagger swagger) {
if (null != annotationAttributeValue) {
Map<String, SecuritySchemeDefinition> securitySchemeDefinitionMap = new HashMap<>();
for (AnnotationAttachmentAttributeValueNode authorizationValues : annotationAttributeValue.getValueArray()) {
if (authorizationValues instanceof AnnotationAttachmentNode) {
AnnotationAttachmentNode authAnnotationAttachment = (AnnotationAttachmentNode) authorizationValues;
Map<String, AnnotationAttachmentAttributeValueNode> authAttributes = this.listToMap(authAnnotationAttachment);
if (authAttributes.containsKey("name") && authAttributes.containsKey("authType")) {
String name = this.getStringLiteralValue(authAttributes.get("name"));
String type = this.getStringLiteralValue(authAttributes.get("authType"));
String description = "";
if (authAttributes.containsKey("description")) {
description = this.getStringLiteralValue(authAttributes.get("description"));
}
if ("basic".equals(type)) {
BasicAuthDefinition basicAuthDefinition = new BasicAuthDefinition();
basicAuthDefinition.setDescription(description);
securitySchemeDefinitionMap.put(name, basicAuthDefinition);
} else if ("apiKey".equals(type)) {
ApiKeyAuthDefinition apiKeyAuthDefinition = new ApiKeyAuthDefinition();
apiKeyAuthDefinition.setName(this.getStringLiteralValue(authAttributes.get("apiName")));
apiKeyAuthDefinition.setIn(In.forValue(this.getStringLiteralValue(authAttributes.get("in"))));
apiKeyAuthDefinition.setDescription(description);
securitySchemeDefinitionMap.put(name, apiKeyAuthDefinition);
} else if ("oauth2".equals(type)) {
OAuth2Definition oAuth2Definition = new OAuth2Definition();
oAuth2Definition.setFlow(this.getStringLiteralValue(authAttributes.get("flow")));
oAuth2Definition.setAuthorizationUrl(this.getStringLiteralValue(authAttributes.get("authorizationUrl")));
oAuth2Definition.setTokenUrl(this.getStringLiteralValue(authAttributes.get("tokenUrl")));
this.createSecurityDefinitionScopesModel(authAttributes.get("authorizationScopes"), oAuth2Definition);
oAuth2Definition.setDescription(description);
securitySchemeDefinitionMap.put(name, oAuth2Definition);
}
}
}
}
swagger.setSecurityDefinitions(securitySchemeDefinitionMap);
}
}
use of org.ballerinalang.model.tree.expressions.AnnotationAttachmentAttributeValueNode in project ballerina by ballerina-lang.
the class SwaggerServiceMapper method createOrganizationModel.
/**
* Creates vendor extension for organization.
* @param annotationAttributeValue The annotation attribute value for organization vendor extension.
* @param info The info definition.
*/
private void createOrganizationModel(AnnotationAttachmentAttributeValueNode annotationAttributeValue, Info info) {
if (null != annotationAttributeValue) {
AnnotationAttachmentNode organizationAnnotationAttachment = (AnnotationAttachmentNode) annotationAttributeValue.getValue();
Map<String, AnnotationAttachmentAttributeValueNode> organizationAttributes = this.listToMap(organizationAnnotationAttachment);
Organization organization = new Organization();
if (organizationAttributes.containsKey("name")) {
organization.setName(this.getStringLiteralValue(organizationAttributes.get("name")));
}
if (organizationAttributes.containsKey("url")) {
organization.setUrl(this.getStringLiteralValue(organizationAttributes.get("url")));
}
info.setVendorExtension("x-organization", organization);
}
}
use of org.ballerinalang.model.tree.expressions.AnnotationAttachmentAttributeValueNode in project ballerina by ballerina-lang.
the class SwaggerServiceMapper method createExternalDocModel.
/**
* Creates external docs swagger definition.
* @param annotationAttributeValue The ballerina annotation attribute value for external docs.
* @param swagger The swagger definition which the external docs needs to be build on.
*/
private void createExternalDocModel(AnnotationAttachmentAttributeValueNode annotationAttributeValue, Swagger swagger) {
if (null != annotationAttributeValue) {
AnnotationAttachmentNode externalDocAnnotationAttachment = (AnnotationAttachmentNode) annotationAttributeValue.getValue();
Map<String, AnnotationAttachmentAttributeValueNode> externalDocAttributes = this.listToMap(externalDocAnnotationAttachment);
ExternalDocs externalDocs = new ExternalDocs();
if (externalDocAttributes.containsKey("description")) {
externalDocs.setDescription(this.getStringLiteralValue(externalDocAttributes.get("description")));
}
if (externalDocAttributes.containsKey("url")) {
externalDocs.setUrl(this.getStringLiteralValue(externalDocAttributes.get("url")));
}
swagger.setExternalDocs(externalDocs);
}
}
Aggregations