use of org.ballerinalang.util.codegen.AnnAttributeValue in project ballerina by ballerina-lang.
the class SwaggerResourceMapper method parseConsumesAnnotationAttachment.
/**
* Parses the consumes annotation attachments and updates the swagger operation.
*
* @param resource The ballerina resource definition.
* @param operation The swagger operation.
*/
private void parseConsumesAnnotationAttachment(ResourceInfo resource, Operation operation) {
AnnAttachmentInfo rConfigAnnAtchmnt = resource.getAnnotationAttachmentInfo(HttpConstants.HTTP_PACKAGE_PATH, HttpConstants.ANN_NAME_RESOURCE_CONFIG);
if (rConfigAnnAtchmnt == null) {
return;
}
AnnAttributeValue consumesAttrVal = rConfigAnnAtchmnt.getAttributeValue(HttpConstants.ANN_RESOURCE_ATTR_CONSUMES);
if (consumesAttrVal == null) {
return;
}
List<String> consumes = getStringList(consumesAttrVal.getAttributeValueArray());
operation.setConsumes(consumes);
}
use of org.ballerinalang.util.codegen.AnnAttributeValue 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.AnnAttributeValue 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.AnnAttributeValue 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.AnnAttributeValue 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(AnnAttributeValue authorizationScopes, OAuth2Definition oAuth2Definition) {
if (null != authorizationScopes) {
Map<String, String> scopes = new HashMap<>();
for (AnnAttributeValue authScopeValue : authorizationScopes.getAttributeValueArray()) {
AnnAttachmentInfo authScopeAnnotationAttachment = authScopeValue.getAnnotationAttachmentValue();
Map<String, AnnAttributeValue> authScopeAnnAttributeValueMap = SwaggerUtils.convertToAttributeMap(authScopeAnnotationAttachment);
String name = authScopeAnnAttributeValueMap.get("name").getStringValue();
String description = authScopeAnnAttributeValueMap.get("description").getStringValue();
scopes.put(name, description);
}
oAuth2Definition.setScopes(scopes);
}
}
Aggregations