use of org.ballerinalang.util.codegen.AnnAttributeValue 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.AnnAttributeValue 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.AnnAttributeValue in project ballerina by ballerina-lang.
the class SwaggerServiceMapper method createTagModel.
/**
* Creates tag swagger definition.
* @param annotationAttributeValue The ballerina annotation attribute value for tag.
* @param swagger The swagger definition which the tags needs to be build on.
*/
private void createTagModel(AnnAttributeValue annotationAttributeValue, Swagger swagger) {
if (null != annotationAttributeValue && annotationAttributeValue.getAttributeValueArray().length > 0) {
List<Tag> tags = new LinkedList<>();
for (AnnAttributeValue tagAttributeValue : annotationAttributeValue.getAttributeValueArray()) {
AnnAttachmentInfo tagAnnotationAttachment = tagAttributeValue.getAnnotationAttachmentValue();
Tag tag = new Tag();
for (AnnAttributeKeyValuePair annAttributeKeyValuePair : tagAnnotationAttachment.getAttributeKeyValuePairs()) {
if ("name".equals(annAttributeKeyValuePair.getAttributeName())) {
tag.setName(annAttributeKeyValuePair.getAttributeValue().getStringValue());
} else if ("description".equals(annAttributeKeyValuePair.getAttributeName())) {
tag.setDescription(annAttributeKeyValuePair.getAttributeValue().getStringValue());
}
}
tags.add(tag);
}
swagger.setTags(tags);
}
}
Aggregations