use of io.swagger.models.Response in project ballerina by ballerina-lang.
the class SwaggerResourceMapper method convertResourceToOperation.
/**
* This method will convert ballerina @Resource to ballerina @OperationAdaptor.
*
* @param resource Resource array to be convert.
* @return @OperationAdaptor of string and swagger path objects.
*/
private OperationAdaptor convertResourceToOperation(ResourceNode resource, String httpMethod) {
OperationAdaptor op = new OperationAdaptor();
if (resource != null) {
// Setting default values.
op.setHttpOperation(HttpConstants.HTTP_METHOD_GET);
op.setPath('/' + resource.getName().getValue());
Response response = new Response().description("Successful").example(MediaType.APPLICATION_JSON, "Ok");
op.getOperation().response(200, response);
op.getOperation().setOperationId(resource.getName().getValue());
op.getOperation().setParameters(null);
// Parsing annotations.
this.parseHttpResourceConfig(resource, op);
if (null != httpMethod) {
op.setHttpOperation(httpMethod);
}
this.parseResourceConfigAnnotationAttachment(resource, op.getOperation());
this.parseResourceInfoAnnotationAttachment(resource, op.getOperation());
this.addResourceParameters(resource, op);
this.parseParametersInfoAnnotationAttachment(resource, op.getOperation());
this.parseResponsesAnnotationAttachment(resource, op.getOperation());
}
return op;
}
use of io.swagger.models.Response in project ballerina by ballerina-lang.
the class SwaggerResourceMapper method convertResourceToOperation.
/**
* This method will convert ballerina @Resource to ballerina @OperationAdaptor
*
* @param resource Resource array to be convert.
* @return @OperationAdaptor of string and swagger path objects.
*/
private OperationAdaptor convertResourceToOperation(ResourceInfo resource) {
OperationAdaptor op = new OperationAdaptor();
if (resource != null) {
// Setting default values.
op.setHttpOperation(HttpConstants.HTTP_METHOD_GET);
op.setPath('/' + resource.getName());
Response response = new Response().description("Successful").example("application/json", "Ok");
op.getOperation().response(200, response);
op.getOperation().setOperationId(resource.getName());
op.getOperation().setParameters(null);
// Parsing annotations.
this.parsePathAnnotationAttachment(resource, op);
this.parseHttpMethodAnnotationAttachment(resource, op);
this.parseResourceConfigAnnotationAttachment(resource, op.getOperation());
this.parseConsumesAnnotationAttachment(resource, op.getOperation());
this.parseProducesAnnotationAttachment(resource, op.getOperation());
this.parseResourceInfoAnnotationAttachment(resource, op.getOperation());
this.addResourceParameters(resource, op);
this.parseParametersInfoAnnotationAttachment(resource, op.getOperation());
this.parseResponsesAnnotationAttachment(resource, op.getOperation());
}
return op;
}
use of io.swagger.models.Response 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 io.swagger.models.Response in project java-chassis by ServiceComb.
the class TestSwaggerUtils method correctResponsesOperationNotChangeExistDescription.
@Test
public void correctResponsesOperationNotChangeExistDescription() {
Response response = new Response();
response.setDescription("description");
Operation operation = new Operation();
operation.addResponse("200", response);
SwaggerUtils.correctResponses(operation);
Assert.assertEquals("description", response.getDescription());
}
use of io.swagger.models.Response in project java-chassis by ServiceComb.
the class TestSwaggerUtils method correctResponsesOperationFixEmptyDescription.
@Test
public void correctResponsesOperationFixEmptyDescription() {
Response response = new Response();
Operation operation = new Operation();
operation.addResponse("200", response);
SwaggerUtils.correctResponses(operation);
Assert.assertEquals("response of 200", response.getDescription());
}
Aggregations