use of org.ballerinalang.model.tree.AnnotationAttachmentNode in project ballerina by ballerina-lang.
the class SwaggerResourceMapper method createHeadersModel.
/**
* Creates headers definitions for swagger response.
* @param annotationAttributeValue The annotation attribute value which has the headers.
* @param response The swagger response.
*/
private void createHeadersModel(AnnotationAttachmentAttributeValueNode annotationAttributeValue, Response response) {
if (null != annotationAttributeValue) {
List<? extends AnnotationAttachmentAttributeValueNode> headersValueArray = annotationAttributeValue.getValueArray();
for (AnnotationAttachmentAttributeValueNode headersValue : headersValueArray) {
if (headersValue instanceof AnnotationAttachmentNode) {
AnnotationAttachmentNode headerAnnotationAttachment = (AnnotationAttachmentNode) headersValue;
Map<String, Property> headers = new HashMap<>();
Map<String, AnnotationAttachmentAttributeValueNode> headersAttributes = this.listToMap(headerAnnotationAttachment);
if (headersAttributes.containsKey("name") && headersAttributes.containsKey("headerType")) {
String headerName = this.getStringLiteralValue(headersAttributes.get("name"));
String type = this.getStringLiteralValue(headersAttributes.get("headerType"));
Property property = null;
if ("string".equals(type)) {
property = new StringProperty();
} else if ("number".equals(type) || "integer".equals(type)) {
property = new IntegerProperty();
} else if ("boolean".equals(type)) {
property = new BooleanProperty();
} else if ("array".equals(type)) {
property = new ArrayProperty();
}
if (null != property) {
if (headersAttributes.containsKey("description")) {
property.setDescription(this.getStringLiteralValue(headersAttributes.get("description")));
}
headers.put(headerName, property);
}
}
response.setHeaders(headers);
}
}
}
}
use of org.ballerinalang.model.tree.AnnotationAttachmentNode in project ballerina by ballerina-lang.
the class SwaggerServiceMapper method createContactModel.
/**
* Creates the contact swagger definition.
* @param annotationAttributeValue The ballerina annotation attribute value for contact.
* @param info The info definition which the contact needs to be build on.
*/
private void createContactModel(AnnotationAttachmentAttributeValueNode annotationAttributeValue, Info info) {
if (null != annotationAttributeValue) {
AnnotationAttachmentNode contactAnnotationAttachment = (AnnotationAttachmentNode) annotationAttributeValue.getValue();
Map<String, AnnotationAttachmentAttributeValueNode> contactAttributes = this.listToMap(contactAnnotationAttachment);
Contact contact = new Contact();
if (contactAttributes.containsKey("name")) {
contact.setName(this.getStringLiteralValue(contactAttributes.get("name")));
}
if (contactAttributes.containsKey("email")) {
contact.setEmail(this.getStringLiteralValue(contactAttributes.get("email")));
}
if (contactAttributes.containsKey("url")) {
contact.setUrl(this.getStringLiteralValue(contactAttributes.get("url")));
}
info.setContact(contact);
}
}
use of org.ballerinalang.model.tree.AnnotationAttachmentNode 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(ServiceNode service, Swagger swagger) {
Optional<? extends AnnotationAttachmentNode> swaggerInfoAnnotation = service.getAnnotationAttachments().stream().filter(a -> null != swaggerAlias && this.swaggerAlias.equals(a.getPackageAlias().getValue()) && "ServiceInfo".equals(a.getAnnotationName().getValue())).findFirst();
Info info = new Info().version("1.0.0").title(service.getName().getValue());
if (swaggerInfoAnnotation.isPresent()) {
Map<String, AnnotationAttachmentAttributeValueNode> attributes = this.listToMap(swaggerInfoAnnotation.get());
if (attributes.containsKey("serviceVersion")) {
info.version(this.getStringLiteralValue(attributes.get("serviceVersion")));
}
if (attributes.containsKey("title")) {
info.title(this.getStringLiteralValue(attributes.get("title")));
}
if (attributes.containsKey("description")) {
info.description(this.getStringLiteralValue(attributes.get("description")));
}
if (attributes.containsKey("termsOfService")) {
info.termsOfService(this.getStringLiteralValue(attributes.get("termsOfService")));
}
this.createContactModel(attributes.get("contact"), info);
this.createLicenseModel(attributes.get("license"), info);
this.createExternalDocModel(attributes.get("externalDoc"), swagger);
this.createTagModel(attributes.get("tags"), swagger);
this.createOrganizationModel(attributes.get("organization"), info);
this.createDevelopersModel(attributes.get("developers"), info);
}
swagger.setInfo(info);
}
use of org.ballerinalang.model.tree.AnnotationAttachmentNode 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(AnnotationAttachmentAttributeValueNode authorizationScopes, OAuth2Definition oAuth2Definition) {
Map<String, String> scopes = new HashMap<>();
for (AnnotationAttachmentAttributeValueNode authScopeValue : authorizationScopes.getValueArray()) {
if (authScopeValue instanceof AnnotationAttachmentNode) {
AnnotationAttachmentNode authScopeAnnotationAttachment = (AnnotationAttachmentNode) authScopeValue;
Map<String, AnnotationAttachmentAttributeValueNode> authScopeAttributes = this.listToMap(authScopeAnnotationAttachment);
String name = this.getStringLiteralValue(authScopeAttributes.get("name"));
String description = this.getStringLiteralValue(authScopeAttributes.get("description"));
scopes.put(name, description);
}
}
oAuth2Definition.setScopes(scopes);
}
use of org.ballerinalang.model.tree.AnnotationAttachmentNode 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(AnnotationAttachmentAttributeValueNode annotationAttributeValue, Info info) {
if (null != annotationAttributeValue) {
AnnotationAttachmentNode licenseAnnotationAttachment = (AnnotationAttachmentNode) annotationAttributeValue.getValue();
Map<String, AnnotationAttachmentAttributeValueNode> licenseAttributes = this.listToMap(licenseAnnotationAttachment);
License license = new License();
if (licenseAttributes.containsKey("name")) {
license.setName(this.getStringLiteralValue(licenseAttributes.get("name")));
}
if (licenseAttributes.containsKey("url")) {
license.setUrl(this.getStringLiteralValue(licenseAttributes.get("url")));
}
info.setLicense(license);
}
}
Aggregations