Search in sources :

Example 21 with AnnAttachmentInfo

use of org.ballerinalang.util.codegen.AnnAttachmentInfo 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");
}
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)

Example 22 with AnnAttachmentInfo

use of org.ballerinalang.util.codegen.AnnAttachmentInfo in project ballerina by ballerina-lang.

the class AnnotationTest method testServiceAnnotation.

@Test(description = "Test service annotation", enabled = false)
public void testServiceAnnotation() {
    AnnotationAttributeInfo annotationInfo = (AnnotationAttributeInfo) compileResult.getProgFile().getEntryPackage().getServiceInfo("PizzaService").getAttributeInfo(AttributeInfo.Kind.ANNOTATIONS_ATTRIBUTE);
    AnnAttachmentInfo[] attachmentInfos = annotationInfo.getAttachmentInfoEntries();
    String attributeValue = attachmentInfos[0].getAttributeValue("value").getStringValue();
    Assert.assertEquals(attributeValue, "Pizza service");
}
Also used : AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) AnnotationAttributeInfo(org.ballerinalang.util.codegen.attributes.AnnotationAttributeInfo) Test(org.testng.annotations.Test)

Example 23 with AnnAttachmentInfo

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

Example 24 with AnnAttachmentInfo

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

Example 25 with AnnAttachmentInfo

use of org.ballerinalang.util.codegen.AnnAttachmentInfo 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());
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : ParamAnnAttachmentInfo(org.ballerinalang.util.codegen.ParamAnnAttachmentInfo) AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) AnnAttributeValue(org.ballerinalang.util.codegen.AnnAttributeValue)

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