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