use of io.swagger.models.Contact 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 io.swagger.models.Contact 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(AnnAttributeValue annotationAttributeValue, Info info) {
if (null != annotationAttributeValue) {
AnnAttachmentInfo contactAnnotationAttachment = annotationAttributeValue.getAnnotationAttachmentValue();
Contact contact = new Contact();
for (AnnAttributeKeyValuePair annAttributeKeyValuePair : contactAnnotationAttachment.getAttributeKeyValuePairs()) {
if ("name".equals(annAttributeKeyValuePair.getAttributeName())) {
contact.setName(annAttributeKeyValuePair.getAttributeValue().getStringValue());
} else if ("email".equals(annAttributeKeyValuePair.getAttributeName())) {
contact.setEmail(annAttributeKeyValuePair.getAttributeValue().getStringValue());
} else if ("url".equals(annAttributeKeyValuePair.getAttributeName())) {
contact.setUrl(annAttributeKeyValuePair.getAttributeValue().getStringValue());
}
}
info.setContact(contact);
}
}
Aggregations