Search in sources :

Example 11 with AnnAttachmentInfo

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);
    }
}
Also used : AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) HashMap(java.util.HashMap) AnnAttributeValue(org.ballerinalang.util.codegen.AnnAttributeValue)

Example 12 with AnnAttachmentInfo

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);
    }
}
Also used : AnnAttributeKeyValuePair(org.ballerinalang.util.codegen.AnnAttributeKeyValuePair) AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) Organization(org.ballerinalang.swagger.code.generator.model.Organization)

Example 13 with AnnAttachmentInfo

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);
}
Also used : AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) CompileResult(org.ballerinalang.launcher.util.CompileResult) AnnotationAttributeInfo(org.ballerinalang.util.codegen.attributes.AnnotationAttributeInfo) Test(org.testng.annotations.Test)

Example 14 with AnnAttachmentInfo

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");
}
Also used : AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) AnnotationAttributeInfo(org.ballerinalang.util.codegen.attributes.AnnotationAttributeInfo) Test(org.testng.annotations.Test)

Example 15 with AnnAttachmentInfo

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");
}
Also used : AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) AnnAttributeValue(org.ballerinalang.util.codegen.AnnAttributeValue) AnnotationAttributeInfo(org.ballerinalang.util.codegen.attributes.AnnotationAttributeInfo) Test(org.testng.annotations.Test)

Aggregations

AnnAttachmentInfo (org.ballerinalang.util.codegen.AnnAttachmentInfo)31 AnnAttributeValue (org.ballerinalang.util.codegen.AnnAttributeValue)17 ParamAnnAttachmentInfo (org.ballerinalang.util.codegen.ParamAnnAttachmentInfo)10 AnnotationAttributeInfo (org.ballerinalang.util.codegen.attributes.AnnotationAttributeInfo)10 Test (org.testng.annotations.Test)10 AnnAttributeKeyValuePair (org.ballerinalang.util.codegen.AnnAttributeKeyValuePair)7 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)3 ExternalDocs (io.swagger.models.ExternalDocs)2 Scheme (io.swagger.models.Scheme)2 BodyParameter (io.swagger.models.parameters.BodyParameter)2 PathParameter (io.swagger.models.parameters.PathParameter)2 QueryParameter (io.swagger.models.parameters.QueryParameter)2 Contact (io.swagger.models.Contact)1 Info (io.swagger.models.Info)1 License (io.swagger.models.License)1 Model (io.swagger.models.Model)1 ModelImpl (io.swagger.models.ModelImpl)1 RefModel (io.swagger.models.RefModel)1 Response (io.swagger.models.Response)1