use of org.ballerinalang.util.codegen.AnnAttachmentInfo in project ballerina by ballerina-lang.
the class SwaggerServiceMapper method createSecurityDefinitionsModel.
/**
* Creates the security definition models for swagger definition.
* @param annotationAttributeValue The annotation attribute value for security definitions.
* @param swagger The swagger definition.
*/
private void createSecurityDefinitionsModel(AnnAttributeValue annotationAttributeValue, Swagger swagger) {
if (null != annotationAttributeValue) {
Map<String, SecuritySchemeDefinition> securitySchemeDefinitionMap = new HashMap<>();
for (AnnAttributeValue authorizationValues : annotationAttributeValue.getAttributeValueArray()) {
AnnAttachmentInfo authAnnotationAttachment = authorizationValues.getAnnotationAttachmentValue();
Map<String, AnnAttributeValue> authAnnAttributeValueMap = SwaggerUtils.convertToAttributeMap(authAnnotationAttachment);
if (null != authAnnAttributeValueMap.get("name") && null != authAnnAttributeValueMap.get("authType")) {
String name = authAnnAttributeValueMap.get("name").getStringValue();
String type = authAnnAttributeValueMap.get("authType").getStringValue();
String description = "";
if (null != authAnnAttributeValueMap.get("description")) {
description = authAnnAttributeValueMap.get("description").getStringValue();
}
if ("basic".equals(type)) {
BasicAuthDefinition basicAuthDefinition = new BasicAuthDefinition();
basicAuthDefinition.setDescription(description);
securitySchemeDefinitionMap.put(name, basicAuthDefinition);
} else if ("apiKey".equals(type)) {
ApiKeyAuthDefinition apiKeyAuthDefinition = new ApiKeyAuthDefinition();
apiKeyAuthDefinition.setName(authAnnAttributeValueMap.get("apiName").getStringValue());
apiKeyAuthDefinition.setIn(In.forValue(authAnnAttributeValueMap.get("in").getStringValue()));
apiKeyAuthDefinition.setDescription(description);
securitySchemeDefinitionMap.put(name, apiKeyAuthDefinition);
} else if ("oauth2".equals(type)) {
OAuth2Definition oAuth2Definition = new OAuth2Definition();
oAuth2Definition.setFlow(authAnnAttributeValueMap.get("flow").getStringValue());
oAuth2Definition.setAuthorizationUrl(authAnnAttributeValueMap.get("authorizationUrl").getStringValue());
oAuth2Definition.setTokenUrl(authAnnAttributeValueMap.get("tokenUrl").getStringValue());
this.createSecurityDefinitionScopesModel(authAnnAttributeValueMap.get("authorizationScopes"), oAuth2Definition);
oAuth2Definition.setDescription(description);
securitySchemeDefinitionMap.put(name, oAuth2Definition);
}
}
}
swagger.setSecurityDefinitions(securitySchemeDefinitionMap);
}
}
use of org.ballerinalang.util.codegen.AnnAttachmentInfo 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);
}
}
use of org.ballerinalang.util.codegen.AnnAttachmentInfo in project ballerina by ballerina-lang.
the class SwaggerServiceMapper method parseServiceConfigAnnotationAttachment.
/**
* Parses the 'ServiceConfig' annotation attachment.
* @param service The ballerina service which has that annotation attachment.
* @param swagger The swagger definition to build up.
*/
private void parseServiceConfigAnnotationAttachment(ServiceInfo service, Swagger swagger) {
AnnAttachmentInfo swaggerConfigAnnotation = service.getAnnotationAttachmentInfo(SwaggerConstants.SWAGGER_PACKAGE_PATH, "ServiceConfig");
if (null != swaggerConfigAnnotation) {
Map<String, AnnAttributeValue> swaggerConfigAnnAttributeValueMap = SwaggerUtils.convertToAttributeMap(swaggerConfigAnnotation);
if (null != swaggerConfigAnnAttributeValueMap.get("host")) {
swagger.setHost(swaggerConfigAnnAttributeValueMap.get("host").getStringValue());
}
if (null != swaggerConfigAnnAttributeValueMap.get("schemes")) {
if (swaggerConfigAnnAttributeValueMap.get("schemes").getAttributeValueArray().length > 0) {
List<Scheme> schemes = new LinkedList<>();
for (AnnAttributeValue schemeValue : swaggerConfigAnnAttributeValueMap.get("schemes").getAttributeValueArray()) {
if (null != Scheme.forValue(schemeValue.getStringValue())) {
schemes.add(Scheme.forValue(schemeValue.getStringValue()));
}
}
if (schemes.size() > 0) {
swagger.setSchemes(schemes);
}
}
}
this.createSecurityDefinitionsModel(swaggerConfigAnnAttributeValueMap.get("authorizations"), swagger);
}
}
use of org.ballerinalang.util.codegen.AnnAttachmentInfo 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);
}
}
use of org.ballerinalang.util.codegen.AnnAttachmentInfo 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