Search in sources :

Example 91 with Response

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());
    }
}
Also used : Response(io.swagger.models.Response) ApiResponse(io.swagger.annotations.ApiResponse)

Example 92 with Response

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);
}
Also used : Response(io.swagger.models.Response) ApiResponse(io.swagger.annotations.ApiResponse) Model(io.swagger.models.Model) MapProperty(io.swagger.models.properties.MapProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) ExampleProperty(io.swagger.annotations.ExampleProperty) Property(io.swagger.models.properties.Property)

Example 93 with 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");
                    }
                }
            }
        }
    }
}
Also used : Response(io.swagger.models.Response) QueryParameter(io.swagger.models.parameters.QueryParameter) AuditLevel(org.killbill.billing.util.api.AuditLevel) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) BodyParameter(io.swagger.models.parameters.BodyParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) PathParameter(io.swagger.models.parameters.PathParameter)

Aggregations

Response (io.swagger.models.Response)93 Operation (io.swagger.models.Operation)51 Property (io.swagger.models.properties.Property)30 Path (io.swagger.models.Path)29 Swagger (io.swagger.models.Swagger)29 ApiResponse (io.swagger.annotations.ApiResponse)24 Test (org.testng.annotations.Test)23 RefProperty (io.swagger.models.properties.RefProperty)21 ArrayProperty (io.swagger.models.properties.ArrayProperty)20 Test (org.junit.Test)17 MapProperty (io.swagger.models.properties.MapProperty)14 Parameter (io.swagger.models.parameters.Parameter)13 Model (io.swagger.models.Model)12 BodyParameter (io.swagger.models.parameters.BodyParameter)12 StringProperty (io.swagger.models.properties.StringProperty)12 HashMap (java.util.HashMap)12 RefModel (io.swagger.models.RefModel)10 PathParameter (io.swagger.models.parameters.PathParameter)10 IntegerProperty (io.swagger.models.properties.IntegerProperty)10 QueryParameter (io.swagger.models.parameters.QueryParameter)9