Search in sources :

Example 96 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 97 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)97 Operation (io.swagger.models.Operation)53 Property (io.swagger.models.properties.Property)31 Path (io.swagger.models.Path)30 Swagger (io.swagger.models.Swagger)30 ApiResponse (io.swagger.annotations.ApiResponse)24 Test (org.testng.annotations.Test)23 RefProperty (io.swagger.models.properties.RefProperty)22 ArrayProperty (io.swagger.models.properties.ArrayProperty)21 Test (org.junit.Test)17 BodyParameter (io.swagger.models.parameters.BodyParameter)15 Parameter (io.swagger.models.parameters.Parameter)14 MapProperty (io.swagger.models.properties.MapProperty)14 HashMap (java.util.HashMap)13 Model (io.swagger.models.Model)12 StringProperty (io.swagger.models.properties.StringProperty)12 RefModel (io.swagger.models.RefModel)11 PathParameter (io.swagger.models.parameters.PathParameter)11 QueryParameter (io.swagger.models.parameters.QueryParameter)10 IntegerProperty (io.swagger.models.properties.IntegerProperty)10