use of io.swagger.models.Response in project java-chassis by ServiceComb.
the class AnnotationUtils method mergeResponse.
private static void mergeResponse(Operation operation, ResponseConfig responseConfig) {
if (operation.getResponses() == null) {
operation.response(responseConfig.getCode(), responseConfig.getResponse());
return;
}
Response response = operation.getResponses().get(String.valueOf(responseConfig.getCode()));
if (response == null) {
operation.response(responseConfig.getCode(), responseConfig.getResponse());
return;
}
Response sourceResp = responseConfig.getResponse();
if (StringUtils.isNotEmpty(sourceResp.getDescription()) && StringUtils.isEmpty(response.getDescription())) {
response.setDescription(sourceResp.getDescription());
}
if (sourceResp.getResponseSchema() != null && response.getResponseSchema() == null) {
response.setResponseSchema(sourceResp.getResponseSchema());
}
if (sourceResp.getExamples() != null && response.getExamples() == null) {
response.setExamples(sourceResp.getExamples());
}
if (sourceResp.getHeaders() != null && response.getHeaders() == null) {
response.setHeaders(sourceResp.getHeaders());
}
if (sourceResp.getVendorExtensions() != null && response.getVendorExtensions() == null) {
response.setVendorExtensions(sourceResp.getVendorExtensions());
}
}
use of io.swagger.models.Response in project java-chassis by ServiceComb.
the class AnnotationUtils method generateResponse.
private static void generateResponse(Swagger swagger, ResponseConfig responseConfig) {
Response response = new Response();
Property property = generateResponseProperty(swagger, responseConfig);
if (property != null) {
Model model = PropertyModelConverterExt.toModel(property);
response.setResponseSchema(model);
}
response.setDescription(responseConfig.getDescription());
addExamplesToResponse(response, responseConfig);
if (responseConfig.getResponseHeaders() != null) {
Map<String, Property> headers = generateResponseHeader(swagger, responseConfig.getResponseHeaders());
response.setHeaders(headers);
}
responseConfig.setResponse(response);
}
use of io.swagger.models.Response in project killbill by killbill.
the class KillBillApiDefinition method decorateOperation.
private void decorateOperation(final Operation op, final String pathName, final String httpMethod) {
if (op != null) {
// Bug in swagger ? somehow when we only specify a 201, swagger adds a 200 response with the schema response
if (httpMethod.equals("POST")) {
if (op.getResponses().containsKey("201") && op.getResponses().containsKey("200")) {
final Response resp200 = op.getResponses().remove("200");
final Response resp201 = op.getResponses().get("201");
if (resp201.getSchema() == null) {
resp201.setSchema(resp200.getSchema());
}
}
}
op.addSecurity(BASIC_AUTH_SCHEME, null);
if (requiresTenantInformation(pathName, httpMethod)) {
op.addSecurity(API_KEY_SCHEME, null);
op.addSecurity(API_SECRET_SCHEME, null);
}
for (Parameter p : op.getParameters()) {
if (p instanceof BodyParameter) {
p.setRequired(true);
} else if (p instanceof PathParameter) {
p.setRequired(true);
} else if (p instanceof HeaderParameter) {
if (p.getName().equals(HDR_CREATED_BY)) {
p.setRequired(true);
}
} else if (p instanceof QueryParameter) {
QueryParameter qp = (QueryParameter) p;
if (qp.getName().equals(QUERY_AUDIT)) {
qp.setRequired(false);
qp.setType("string");
final List<String> values = ImmutableList.copyOf(Iterables.transform(ImmutableList.<AuditLevel>copyOf(AuditLevel.values()), new Function<AuditLevel, String>() {
@Override
public String apply(final AuditLevel input) {
return input.toString();
}
}));
qp.setEnum(values);
} else if (qp.getName().equals(JaxrsResource.QUERY_REQUESTED_DT) || qp.getName().equals(JaxrsResource.QUERY_ENTITLEMENT_REQUESTED_DT) || qp.getName().equals(JaxrsResource.QUERY_BILLING_REQUESTED_DT) || qp.getName().equals(JaxrsResource.QUERY_ENTITLEMENT_EFFECTIVE_FROM_DT) || qp.getName().equals(JaxrsResource.QUERY_START_DATE) || qp.getName().equals(JaxrsResource.QUERY_END_DATE) || qp.getName().equals(JaxrsResource.QUERY_TARGET_DATE)) {
qp.setType("string");
// Yack... See #922
if (op.getOperationId().equals("getCatalogJson") || op.getOperationId().equals("getCatalogXml") || op.getOperationId().equals("setTestClockTime")) {
qp.setFormat("date-time");
} else {
qp.setFormat("date");
}
}
}
}
}
}
Aggregations