use of org.ballerinalang.util.codegen.AnnAttributeValue in project ballerina by ballerina-lang.
the class AnnotationTest method testFunctionAnnotation.
@Test(description = "Test function annotation", enabled = false)
public void testFunctionAnnotation() {
AnnotationAttributeInfo annotationInfo = (AnnotationAttributeInfo) compileResult.getProgFile().getEntryPackage().getFunctionInfo("foo").getAttributeInfo(AttributeInfo.Kind.ANNOTATIONS_ATTRIBUTE);
AnnAttachmentInfo[] attachmentInfos = annotationInfo.getAttachmentInfoEntries();
String attributeValue = attachmentInfos[0].getAttributeValue("value").getStringValue();
Assert.assertEquals(attributeValue, "This is a test function");
AnnAttributeValue firstElement = attachmentInfos[0].getAttributeValue("queryParamValue").getAttributeValueArray()[0];
attributeValue = firstElement.getAnnotationAttachmentValue().getAttributeValue("name").getStringValue();
Assert.assertEquals(attributeValue, "paramName3");
AnnAttributeValue secondElement = attachmentInfos[0].getAttributeValue("queryParamValue").getAttributeValueArray()[1];
attributeValue = secondElement.getAnnotationAttachmentValue().getAttributeValue("name").getStringValue();
Assert.assertEquals(attributeValue, "paramName2");
AnnAttributeValue thirdElement = attachmentInfos[0].getAttributeValue("queryParamValue").getAttributeValueArray()[2];
attributeValue = thirdElement.getAnnotationAttachmentValue().getAttributeValue("name").getStringValue();
Assert.assertEquals(attributeValue, "paramName");
Assert.assertEquals(attachmentInfos[1].getAttributeValue("value").getStringValue(), "test @Args annotation");
}
use of org.ballerinalang.util.codegen.AnnAttributeValue 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(AnnAttributeValue annotationAttributeValue, Operation operation) {
if (null != annotationAttributeValue) {
if (annotationAttributeValue.getAttributeValueArray().length > 0) {
List<String> tags = new LinkedList<>();
for (AnnAttributeValue tagAttributeValue : annotationAttributeValue.getAttributeValueArray()) {
tags.add(tagAttributeValue.getStringValue());
}
operation.setTags(tags);
}
}
}
use of org.ballerinalang.util.codegen.AnnAttributeValue in project ballerina by ballerina-lang.
the class SwaggerResourceMapper method parseProducesAnnotationAttachment.
/**
* Parses the produces annotation attachments and updates the swagger operation.
*
* @param resource The ballerina resource definition.
* @param operation The swagger operation.
*/
private void parseProducesAnnotationAttachment(ResourceInfo resource, Operation operation) {
AnnAttachmentInfo rConfigAnnAtchmnt = resource.getAnnotationAttachmentInfo(HttpConstants.HTTP_PACKAGE_PATH, HttpConstants.ANN_NAME_RESOURCE_CONFIG);
if (rConfigAnnAtchmnt == null) {
return;
}
AnnAttributeValue producesAttrVal = rConfigAnnAtchmnt.getAttributeValue(HttpConstants.ANN_RESOURCE_ATTR_PRODUCES);
if (producesAttrVal == null) {
return;
}
List<String> produces = getStringList(producesAttrVal.getAttributeValueArray());
operation.setProduces(produces);
}
use of org.ballerinalang.util.codegen.AnnAttributeValue in project ballerina by ballerina-lang.
the class SwaggerResourceMapper method parseResourceInfoAnnotationAttachment.
/**
* Parses the 'ResourceInfo' annotation and builds swagger operation.
*
* @param resource The resource definition.
* @param operation The swagger operation.
*/
private void parseResourceInfoAnnotationAttachment(ResourceInfo resource, Operation operation) {
AnnAttachmentInfo resourceConfigAnnotationAttachment = resource.getAnnotationAttachmentInfo(SwaggerConstants.SWAGGER_PACKAGE_PATH, "ResourceInfo");
if (null != resourceConfigAnnotationAttachment) {
Map<String, AnnAttributeValue> resourceConfigAnnAttributeValueMap = SwaggerUtils.convertToAttributeMap(resourceConfigAnnotationAttachment);
this.createTagModel(resourceConfigAnnAttributeValueMap.get("tag"), operation);
if (null != resourceConfigAnnAttributeValueMap.get("summary")) {
operation.setSummary(resourceConfigAnnAttributeValueMap.get("summary").getStringValue());
}
if (null != resourceConfigAnnAttributeValueMap.get("description")) {
operation.setDescription(resourceConfigAnnAttributeValueMap.get("description").getStringValue());
}
this.createExternalDocsModel(resourceConfigAnnAttributeValueMap.get("externalDoc"), operation);
}
}
use of org.ballerinalang.util.codegen.AnnAttributeValue in project ballerina by ballerina-lang.
the class SwaggerResourceMapper method parseParametersInfoAnnotationAttachment.
/**
* Parses the 'ParametersInfo' annotation and build swagger operation.
*
* @param resource The ballerina resource definition.
* @param operation The swagger operation.
*/
private void parseParametersInfoAnnotationAttachment(ResourceInfo resource, Operation operation) {
AnnAttachmentInfo parametersInfoAnnotationAttachment = resource.getAnnotationAttachmentInfo(SwaggerConstants.SWAGGER_PACKAGE_PATH, "ParametersInfo");
if (null != parametersInfoAnnotationAttachment) {
Map<String, AnnAttributeValue> parametersInfoAnnAttributeValueMap = SwaggerUtils.convertToAttributeMap(parametersInfoAnnotationAttachment);
if (null != parametersInfoAnnAttributeValueMap.get("value")) {
AnnAttributeValue[] parametersInfoValues = parametersInfoAnnAttributeValueMap.get("value").getAttributeValueArray();
for (AnnAttributeValue parametersInfoValue : parametersInfoValues) {
AnnAttachmentInfo parameterInfoAnnotation = parametersInfoValue.getAnnotationAttachmentValue();
Map<String, AnnAttributeValue> parameterInfoAnnAttributeValueMap = SwaggerUtils.convertToAttributeMap(parameterInfoAnnotation);
if (null != parameterInfoAnnAttributeValueMap.get("name")) {
if (null != operation.getParameters()) {
for (Parameter parameter : operation.getParameters()) {
if (parameter.getName().equals(parameterInfoAnnAttributeValueMap.get("name").getStringValue())) {
if (null != parameterInfoAnnAttributeValueMap.get("description")) {
parameter.setDescription(parameterInfoAnnAttributeValueMap.get("description").getStringValue());
}
}
}
}
}
}
}
}
}
Aggregations