Search in sources :

Example 96 with BodyParameter

use of io.swagger.models.parameters.BodyParameter 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

BodyParameter (io.swagger.models.parameters.BodyParameter)96 Test (org.testng.annotations.Test)42 Parameter (io.swagger.models.parameters.Parameter)34 Model (io.swagger.models.Model)30 Operation (io.swagger.models.Operation)28 QueryParameter (io.swagger.models.parameters.QueryParameter)26 ModelImpl (io.swagger.models.ModelImpl)23 Swagger (io.swagger.models.Swagger)23 PathParameter (io.swagger.models.parameters.PathParameter)23 RefModel (io.swagger.models.RefModel)22 ArrayModel (io.swagger.models.ArrayModel)21 Property (io.swagger.models.properties.Property)21 Path (io.swagger.models.Path)20 RefProperty (io.swagger.models.properties.RefProperty)19 StringProperty (io.swagger.models.properties.StringProperty)18 ArrayProperty (io.swagger.models.properties.ArrayProperty)13 HeaderParameter (io.swagger.models.parameters.HeaderParameter)12 Response (io.swagger.models.Response)10 SerializableParameter (io.swagger.models.parameters.SerializableParameter)10 ArrayList (java.util.ArrayList)9