Search in sources :

Example 6 with AnnAttributeValue

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

the class SwaggerResourceMapper method parseConsumesAnnotationAttachment.

/**
 * Parses the consumes annotation attachments and updates the swagger operation.
 *
 * @param resource  The ballerina resource definition.
 * @param operation The swagger operation.
 */
private void parseConsumesAnnotationAttachment(ResourceInfo resource, Operation operation) {
    AnnAttachmentInfo rConfigAnnAtchmnt = resource.getAnnotationAttachmentInfo(HttpConstants.HTTP_PACKAGE_PATH, HttpConstants.ANN_NAME_RESOURCE_CONFIG);
    if (rConfigAnnAtchmnt == null) {
        return;
    }
    AnnAttributeValue consumesAttrVal = rConfigAnnAtchmnt.getAttributeValue(HttpConstants.ANN_RESOURCE_ATTR_CONSUMES);
    if (consumesAttrVal == null) {
        return;
    }
    List<String> consumes = getStringList(consumesAttrVal.getAttributeValueArray());
    operation.setConsumes(consumes);
}
Also used : ParamAnnAttachmentInfo(org.ballerinalang.util.codegen.ParamAnnAttachmentInfo) AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) AnnAttributeValue(org.ballerinalang.util.codegen.AnnAttributeValue)

Example 7 with AnnAttributeValue

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

the class SwaggerResourceMapper method parseResponsesAnnotationAttachment.

/**
 * Parses the 'Responses' annotation attachment and build swagger operation.
 *
 * @param resource The ballerina resource definition.
 * @param op       The swagger operation.
 */
private void parseResponsesAnnotationAttachment(ResourceInfo resource, Operation op) {
    AnnAttachmentInfo responsesAnnotationAttachment = resource.getAnnotationAttachmentInfo(SwaggerConstants.SWAGGER_PACKAGE_PATH, "Responses");
    if (null != responsesAnnotationAttachment) {
        Map<String, AnnAttributeValue> responsesAnnAttributeValueMap = SwaggerUtils.convertToAttributeMap(responsesAnnotationAttachment);
        if (null != responsesAnnAttributeValueMap.get("value")) {
            AnnAttributeValue[] responsesValues = responsesAnnAttributeValueMap.get("value").getAttributeValueArray();
            if (responsesValues.length > 0) {
                Map<String, Response> responses = new HashMap<>();
                for (AnnAttributeValue responsesValue : responsesValues) {
                    AnnAttachmentInfo responseAnnotationAttachment = responsesValue.getAnnotationAttachmentValue();
                    Map<String, AnnAttributeValue> responseAnnAttributeValueMap = SwaggerUtils.convertToAttributeMap(responseAnnotationAttachment);
                    if (null != responseAnnAttributeValueMap.get("code")) {
                        String code = responseAnnAttributeValueMap.get("code").getStringValue();
                        Response response = new Response();
                        if (null != responseAnnAttributeValueMap.get("description")) {
                            response.setDescription(responseAnnAttributeValueMap.get("description").getStringValue());
                        }
                        // TODO: Parse 'response' attribute for $.paths./resource-path.responses[*]["code"].schema
                        this.createHeadersModel(responseAnnAttributeValueMap.get("headers"), response);
                        responses.put(code, response);
                    }
                }
                op.setResponses(responses);
            }
        }
    }
}
Also used : Response(io.swagger.models.Response) ParamAnnAttachmentInfo(org.ballerinalang.util.codegen.ParamAnnAttachmentInfo) AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) HashMap(java.util.HashMap) AnnAttributeValue(org.ballerinalang.util.codegen.AnnAttributeValue)

Example 8 with AnnAttributeValue

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

the class SwaggerResourceMapper method parseResourceConfigAnnotationAttachment.

/**
 * Parse 'ResourceConfig' annotation attachment and build a resource operation.
 *
 * @param resource  The ballerina resource definition.
 * @param operation The swagger operation.
 */
private void parseResourceConfigAnnotationAttachment(ResourceInfo resource, Operation operation) {
    AnnAttachmentInfo resourceConfigAnnotation = resource.getAnnotationAttachmentInfo(SwaggerConstants.SWAGGER_PACKAGE_PATH, "ResourceConfig");
    if (null != resourceConfigAnnotation) {
        Map<String, AnnAttributeValue> resourceConfigAnnAttributeValueMap = SwaggerUtils.convertToAttributeMap(resourceConfigAnnotation);
        if (null != resourceConfigAnnAttributeValueMap.get("schemes")) {
            List<Scheme> schemes = new LinkedList<>();
            AnnAttributeValue[] schemesValues = resourceConfigAnnAttributeValueMap.get("schemes").getAttributeValueArray();
            for (AnnAttributeValue schemesValue : schemesValues) {
                schemes.add(Scheme.forValue(schemesValue.getStringValue()));
            }
            operation.setSchemes(schemes);
        }
    // TODO: Implement security definitions.
    // this.createSecurityDefinitions(resourceConfigAnnotation.get().getAttributeNameValuePairs()
    // .get("authorizations"), operation);
    }
}
Also used : ParamAnnAttachmentInfo(org.ballerinalang.util.codegen.ParamAnnAttachmentInfo) AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) Scheme(io.swagger.models.Scheme) AnnAttributeValue(org.ballerinalang.util.codegen.AnnAttributeValue) LinkedList(java.util.LinkedList)

Example 9 with AnnAttributeValue

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

the class SwaggerResourceMapper method parsePathAnnotationAttachment.

/**
 * Parses the 'ballerina.net.http@path' annotation and update the operation adaptor.
 *
 * @param resource         The ballerina resource definition.
 * @param operationAdaptor The operation adaptor.
 */
private void parsePathAnnotationAttachment(ResourceInfo resource, OperationAdaptor operationAdaptor) {
    AnnAttachmentInfo rConfigAnnAtchmnt = resource.getAnnotationAttachmentInfo(HttpConstants.HTTP_PACKAGE_PATH, HttpConstants.ANN_NAME_RESOURCE_CONFIG);
    if (rConfigAnnAtchmnt == null) {
        return;
    }
    AnnAttributeValue pathAttrVal = rConfigAnnAtchmnt.getAttributeValue(HttpConstants.ANN_RESOURCE_ATTR_PATH);
    if (null != pathAttrVal && pathAttrVal.getStringValue() != null) {
        operationAdaptor.setPath(pathAttrVal.getStringValue());
    }
}
Also used : ParamAnnAttachmentInfo(org.ballerinalang.util.codegen.ParamAnnAttachmentInfo) AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) AnnAttributeValue(org.ballerinalang.util.codegen.AnnAttributeValue)

Example 10 with AnnAttributeValue

use of org.ballerinalang.util.codegen.AnnAttributeValue 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)

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