Search in sources :

Example 1 with AnnAttributeKeyValuePair

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

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

Example 3 with AnnAttributeKeyValuePair

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

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

the class SwaggerServiceMapper method createExternalDocModel.

/**
 * Creates external docs swagger definition.
 * @param annotationAttributeValue The ballerina annotation attribute value for external docs.
 * @param swagger The swagger definition which the external docs needs to be build on.
 */
private void createExternalDocModel(AnnAttributeValue annotationAttributeValue, Swagger swagger) {
    if (null != annotationAttributeValue) {
        AnnAttachmentInfo externalDocAnnotationAttachment = annotationAttributeValue.getAnnotationAttachmentValue();
        ExternalDocs externalDoc = new ExternalDocs();
        for (AnnAttributeKeyValuePair annAttributeKeyValuePair : externalDocAnnotationAttachment.getAttributeKeyValuePairs()) {
            if ("description".equals(annAttributeKeyValuePair.getAttributeName())) {
                externalDoc.setDescription(annAttributeKeyValuePair.getAttributeValue().getStringValue());
            } else if ("url".equals(annAttributeKeyValuePair.getAttributeName())) {
                externalDoc.setUrl(annAttributeKeyValuePair.getAttributeValue().getStringValue());
            }
        }
        swagger.setExternalDocs(externalDoc);
    }
}
Also used : AnnAttributeKeyValuePair(org.ballerinalang.util.codegen.AnnAttributeKeyValuePair) AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) ExternalDocs(io.swagger.models.ExternalDocs)

Example 5 with AnnAttributeKeyValuePair

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

the class SwaggerServiceMapper method createLicenseModel.

/**
 * Creates the license swagger definition.
 * @param annotationAttributeValue The ballerina annotation attribute value for license.
 * @param info The info definition which the license needs to be build on.
 */
private void createLicenseModel(AnnAttributeValue annotationAttributeValue, Info info) {
    if (null != annotationAttributeValue) {
        AnnAttachmentInfo licenseAnnotationAttachment = annotationAttributeValue.getAnnotationAttachmentValue();
        License license = new License();
        for (AnnAttributeKeyValuePair annAttributeKeyValuePair : licenseAnnotationAttachment.getAttributeKeyValuePairs()) {
            if ("name".equals(annAttributeKeyValuePair.getAttributeName())) {
                license.setName(annAttributeKeyValuePair.getAttributeValue().getStringValue());
            } else if ("url".equals(annAttributeKeyValuePair.getAttributeName())) {
                license.setUrl(annAttributeKeyValuePair.getAttributeValue().getStringValue());
            }
        }
        info.setLicense(license);
    }
}
Also used : AnnAttributeKeyValuePair(org.ballerinalang.util.codegen.AnnAttributeKeyValuePair) AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) License(io.swagger.models.License)

Aggregations

AnnAttachmentInfo (org.ballerinalang.util.codegen.AnnAttachmentInfo)7 AnnAttributeKeyValuePair (org.ballerinalang.util.codegen.AnnAttributeKeyValuePair)7 Contact (io.swagger.models.Contact)1 ExternalDocs (io.swagger.models.ExternalDocs)1 Info (io.swagger.models.Info)1 License (io.swagger.models.License)1 Tag (io.swagger.models.Tag)1 LinkedList (java.util.LinkedList)1 Developer (org.ballerinalang.swagger.code.generator.model.Developer)1 Organization (org.ballerinalang.swagger.code.generator.model.Organization)1 AnnAttributeValue (org.ballerinalang.util.codegen.AnnAttributeValue)1 ServiceInfo (org.ballerinalang.util.codegen.ServiceInfo)1