Search in sources :

Example 11 with AnnAttributeValue

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");
}
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 12 with AnnAttributeValue

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

Example 13 with AnnAttributeValue

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

Example 14 with AnnAttributeValue

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

Example 15 with AnnAttributeValue

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());
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
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

AnnAttributeValue (org.ballerinalang.util.codegen.AnnAttributeValue)18 AnnAttachmentInfo (org.ballerinalang.util.codegen.AnnAttachmentInfo)17 ParamAnnAttachmentInfo (org.ballerinalang.util.codegen.ParamAnnAttachmentInfo)10 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)4 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 AnnotationAttributeInfo (org.ballerinalang.util.codegen.attributes.AnnotationAttributeInfo)2 Test (org.testng.annotations.Test)2 ExternalDocs (io.swagger.models.ExternalDocs)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 Tag (io.swagger.models.Tag)1 ApiKeyAuthDefinition (io.swagger.models.auth.ApiKeyAuthDefinition)1 BasicAuthDefinition (io.swagger.models.auth.BasicAuthDefinition)1 OAuth2Definition (io.swagger.models.auth.OAuth2Definition)1