use of org.ballerinalang.util.codegen.AnnAttachmentInfo in project ballerina by ballerina-lang.
the class SwaggerServiceMapper method createSecurityDefinitionScopesModel.
/**
* Creates the security definition scopes for oAuth2.
* @param authorizationScopes The annotation attribute value of authorization scopes.
* @param oAuth2Definition The oAuth2 definition.
*/
private void createSecurityDefinitionScopesModel(AnnAttributeValue authorizationScopes, OAuth2Definition oAuth2Definition) {
if (null != authorizationScopes) {
Map<String, String> scopes = new HashMap<>();
for (AnnAttributeValue authScopeValue : authorizationScopes.getAttributeValueArray()) {
AnnAttachmentInfo authScopeAnnotationAttachment = authScopeValue.getAnnotationAttachmentValue();
Map<String, AnnAttributeValue> authScopeAnnAttributeValueMap = SwaggerUtils.convertToAttributeMap(authScopeAnnotationAttachment);
String name = authScopeAnnAttributeValueMap.get("name").getStringValue();
String description = authScopeAnnAttributeValueMap.get("description").getStringValue();
scopes.put(name, description);
}
oAuth2Definition.setScopes(scopes);
}
}
use of org.ballerinalang.util.codegen.AnnAttachmentInfo 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(AnnAttributeValue annotationAttributeValue, Info info) {
if (null != annotationAttributeValue) {
AnnAttachmentInfo organizationAnnotationAttachment = annotationAttributeValue.getAnnotationAttachmentValue();
Organization organization = new Organization();
for (AnnAttributeKeyValuePair annAttributeKeyValuePair : organizationAnnotationAttachment.getAttributeKeyValuePairs()) {
if ("name".equals(annAttributeKeyValuePair.getAttributeName())) {
organization.setName(annAttributeKeyValuePair.getAttributeValue().getStringValue());
} else if ("url".equals(annAttributeKeyValuePair.getAttributeName())) {
organization.setUrl(annAttributeKeyValuePair.getAttributeValue().getStringValue());
}
}
info.setVendorExtension("x-organization", organization);
}
}
use of org.ballerinalang.util.codegen.AnnAttachmentInfo in project ballerina by ballerina-lang.
the class AnnotationTest method testDefaultValues.
@Test(description = "Test default values for annotation", enabled = false)
public void testDefaultValues() {
CompileResult compileResult = BCompileUtil.compile("test-src/lang/annotations/default-values.bal");
AnnotationAttributeInfo annotationInfo = (AnnotationAttributeInfo) compileResult.getProgFile().getEntryPackage().getFunctionInfo("foo").getAttributeInfo(AttributeInfo.Kind.ANNOTATIONS_ATTRIBUTE);
AnnAttachmentInfo[] attachmentInfos = annotationInfo.getAttachmentInfoEntries();
// check for default values for basic literal attributes
Assert.assertEquals(attachmentInfos[0].getAttributeValue("value").getStringValue(), "Description of the service/function");
// check for default values for non-literal attributes
Assert.assertEquals(attachmentInfos[0].getAttributeValue("queryParamValue"), null);
// check for default values for nested annotations
AnnAttachmentInfo nestedArgAnnot = attachmentInfos[0].getAttributeValue("args").getAnnotationAttachmentValue();
Assert.assertEquals(nestedArgAnnot.getAttributeValue("value").getStringValue(), "default value for 'Args' annotation in doc package");
// check for default values for nested annotations arrays
AnnAttachmentInfo nestedAnnot = attachmentInfos[0].getAttributeValue("queryParamValue2").getAttributeValueArray()[0].getAnnotationAttachmentValue();
Assert.assertEquals(nestedAnnot.getAttributeValue("name").getStringValue(), "default name");
Assert.assertEquals(nestedAnnot.getAttributeValue("value").getStringValue(), "default value");
// check for default values for a local annotations
Assert.assertEquals(attachmentInfos[1].getAttributeValue("value").getStringValue(), "default value for local 'Args' annotation");
long status = attachmentInfos[3].getAttributeValue("status").getIntValue();
Assert.assertEquals(status, 200);
}
use of org.ballerinalang.util.codegen.AnnAttachmentInfo in project ballerina by ballerina-lang.
the class AnnotationTest method testActionAnnotation.
@Test(description = "Test action annotation", enabled = false)
public void testActionAnnotation() {
AnnotationAttributeInfo annotationInfo = (AnnotationAttributeInfo) compileResult.getProgFile().getEntryPackage().getConnectorInfoEntries()[0].getActionInfoEntries()[1].getAttributeInfo(AttributeInfo.Kind.ANNOTATIONS_ATTRIBUTE);
AnnAttachmentInfo[] attachmentInfos = annotationInfo.getAttachmentInfoEntries();
String attributeValue = attachmentInfos[0].getAttributeValue("value").getStringValue();
Assert.assertEquals(attributeValue, "Test action of test connector");
}
use of org.ballerinalang.util.codegen.AnnAttachmentInfo in project ballerina by ballerina-lang.
the class AnnotationTest method testAnnotationArray.
@Test(description = "Test annotation array", enabled = false)
public void testAnnotationArray() {
AnnotationAttributeInfo annotationInfo = (AnnotationAttributeInfo) compileResult.getProgFile().getEntryPackage().getFunctionInfo("foo").getAttributeInfo(AttributeInfo.Kind.ANNOTATIONS_ATTRIBUTE);
AnnAttachmentInfo[] attachmentInfos = annotationInfo.getAttachmentInfoEntries();
AnnAttributeValue[] annotationArray = attachmentInfos[0].getAttributeValue("queryParamValue").getAttributeValueArray();
Assert.assertEquals(annotationArray.length, 3, "Wrong annotation array length");
String attributeValue = annotationArray[2].getAnnotationAttachmentValue().getAttributeValue("name").getStringValue();
Assert.assertEquals(attributeValue, "paramName");
attributeValue = annotationArray[1].getAnnotationAttachmentValue().getAttributeValue("name").getStringValue();
Assert.assertEquals(attributeValue, "paramName2");
attributeValue = annotationArray[0].getAnnotationAttachmentValue().getAttributeValue("name").getStringValue();
Assert.assertEquals(attributeValue, "paramName3");
}
Aggregations