Search in sources :

Example 6 with AnnAttachmentInfo

use of org.ballerinalang.util.codegen.AnnAttachmentInfo 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 7 with AnnAttachmentInfo

use of org.ballerinalang.util.codegen.AnnAttachmentInfo 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 8 with AnnAttachmentInfo

use of org.ballerinalang.util.codegen.AnnAttachmentInfo 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 9 with AnnAttachmentInfo

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

the class SwaggerServiceMapper method createDevelopersModel.

/**
 * Creates vendor extension for developers.
 * @param annotationAttributeValue The annotation attribute value for developer vendor extension.
 * @param info The info definition.
 */
private void createDevelopersModel(AnnAttributeValue annotationAttributeValue, Info info) {
    if (null != annotationAttributeValue && annotationAttributeValue.getAttributeValueArray().length > 0) {
        Developer[] developers = new Developer[annotationAttributeValue.getAttributeValueArray().length];
        for (int i = 0; i < annotationAttributeValue.getAttributeValueArray().length; i++) {
            AnnAttachmentInfo developerAnnotation = annotationAttributeValue.getAttributeValueArray()[i].getAnnotationAttachmentValue();
            Developer developer = new Developer();
            for (AnnAttributeKeyValuePair annAttributeKeyValuePair : developerAnnotation.getAttributeKeyValuePairs()) {
                if ("name".equals(annAttributeKeyValuePair.getAttributeName())) {
                    developer.setName(annAttributeKeyValuePair.getAttributeValue().getStringValue());
                } else if ("email".equals(annAttributeKeyValuePair.getAttributeName())) {
                    developer.setEmail(annAttributeKeyValuePair.getAttributeValue().getStringValue());
                }
            }
            developers[i] = developer;
        }
        info.setVendorExtension("x-developers", developers);
    }
}
Also used : AnnAttributeKeyValuePair(org.ballerinalang.util.codegen.AnnAttributeKeyValuePair) AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) Developer(org.ballerinalang.swagger.code.generator.model.Developer)

Example 10 with AnnAttachmentInfo

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

the class SwaggerServiceMapper method parseServiceInfoAnnotationAttachment.

/**
 * Parses the 'ServiceInfo' annotation and build the swagger definition for it.
 * @param service The ballerina service which has the 'ServiceInfo' annotation attachment.
 * @param swagger The swagger definition to be built up.
 */
private void parseServiceInfoAnnotationAttachment(ServiceInfo service, Swagger swagger) {
    AnnAttachmentInfo swaggerInfoAnnotation = service.getAnnotationAttachmentInfo(SwaggerConstants.SWAGGER_PACKAGE_PATH, "ServiceInfo");
    Info info = new Info().version("1.0.0").title(service.getName());
    if (null != swaggerInfoAnnotation) {
        for (AnnAttributeKeyValuePair annAttributeKeyValuePair : swaggerInfoAnnotation.getAttributeKeyValuePairs()) {
            if ("version".equals(annAttributeKeyValuePair.getAttributeName())) {
                info.version(annAttributeKeyValuePair.getAttributeValue().getStringValue());
            } else if ("title".equals(annAttributeKeyValuePair.getAttributeName())) {
                info.title(annAttributeKeyValuePair.getAttributeValue().getStringValue());
            } else if ("description".equals(annAttributeKeyValuePair.getAttributeName())) {
                info.description(annAttributeKeyValuePair.getAttributeValue().getStringValue());
            } else if ("termsOfService".equals(annAttributeKeyValuePair.getAttributeName())) {
                info.termsOfService(annAttributeKeyValuePair.getAttributeValue().getStringValue());
            } else if ("contact".equals(annAttributeKeyValuePair.getAttributeName())) {
                this.createContactModel(annAttributeKeyValuePair.getAttributeValue(), info);
            } else if ("license".equals(annAttributeKeyValuePair.getAttributeName())) {
                this.createLicenseModel(annAttributeKeyValuePair.getAttributeValue(), info);
            } else if ("externalDoc".equals(annAttributeKeyValuePair.getAttributeName())) {
                this.createExternalDocModel(annAttributeKeyValuePair.getAttributeValue(), swagger);
            } else if ("tags".equals(annAttributeKeyValuePair.getAttributeName())) {
                this.createTagModel(annAttributeKeyValuePair.getAttributeValue(), swagger);
            } else if ("organization".equals(annAttributeKeyValuePair.getAttributeName())) {
                this.createOrganizationModel(annAttributeKeyValuePair.getAttributeValue(), info);
            } else if ("developers".equals(annAttributeKeyValuePair.getAttributeName())) {
                this.createDevelopersModel(annAttributeKeyValuePair.getAttributeValue(), info);
            }
        }
    }
    swagger.setInfo(info);
}
Also used : AnnAttributeKeyValuePair(org.ballerinalang.util.codegen.AnnAttributeKeyValuePair) AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) Info(io.swagger.models.Info) AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) ServiceInfo(org.ballerinalang.util.codegen.ServiceInfo)

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