Search in sources :

Example 71 with Parameter

use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.

the class SimpleReaderTest method scanClassWithImplicitExampleClassQuery.

@Test(description = "scan a resource with implicit operation query example (dataTypeClass)")
public void scanClassWithImplicitExampleClassQuery() {
    Swagger swagger = getSwagger(ClassWithExamplePostClass.class);
    Parameter param = swagger.getPaths().get("/external/info2").getGet().getParameters().get(0);
    QueryParameter bp = (QueryParameter) param;
    assertNotNull(bp.getExample());
    Object value = bp.getExample();
    assertEquals("77", value);
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) Swagger(io.swagger.models.Swagger) SerializableParameter(io.swagger.models.parameters.SerializableParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Test(org.testng.annotations.Test)

Example 72 with Parameter

use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.

the class SimpleReaderTest method verifyTopLevelPathParams.

@Test(description = "verify top-level path params per #1085")
public void verifyTopLevelPathParams() {
    Swagger swagger = getSwagger(Resource1085.class);
    Parameter param = getGetParameters(swagger, "/external/info/{id}").get(0);
    assertEquals(param.getName(), "id");
    assertTrue(param instanceof PathParameter);
}
Also used : Swagger(io.swagger.models.Swagger) SerializableParameter(io.swagger.models.parameters.SerializableParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Test(org.testng.annotations.Test)

Example 73 with Parameter

use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.

the class ReaderTest method scanImplicitParam.

@Test(description = "scan implicit params")
public void scanImplicitParam() {
    Swagger swagger = getSwagger(ResourceWithImplicitParams.class);
    List<Parameter> params = swagger.getPath("/testString").getPost().getParameters();
    assertNotNull(params);
    assertEquals(params.size(), 7);
    assertEquals(params.get(0).getName(), "sort");
    assertEquals(params.get(0).getIn(), "query");
    PathParameter pathParam = (PathParameter) params.get(1);
    assertEquals(pathParam.getName(), "type");
    assertEquals(pathParam.getIn(), "path");
    assertEquals(pathParam.getEnum().size(), 3);
    assertEquals(pathParam.getType(), "string");
    HeaderParameter headerParam = (HeaderParameter) params.get(2);
    assertEquals(headerParam.getName(), "size");
    assertEquals(headerParam.getIn(), "header");
    assertEquals(headerParam.getMinimum(), new BigDecimal(1.0));
    FormParameter formParam = (FormParameter) params.get(3);
    assertEquals(formParam.getName(), "width");
    assertEquals(formParam.getIn(), "formData");
    assertEquals(formParam.getMaximum(), new BigDecimal(1.0));
    assertEquals(params.get(4).getName(), "width");
    assertEquals(params.get(4).getIn(), "formData");
    QueryParameter queryParam = (QueryParameter) params.get(5);
    assertEquals(queryParam.getName(), "height");
    assertEquals(queryParam.getIn(), "query");
    assertEquals(queryParam.getMinimum(), new BigDecimal(3.0));
    assertEquals(queryParam.getMaximum(), new BigDecimal(4.0));
    BodyParameter bodyParam = (BodyParameter) params.get(6);
    assertEquals(bodyParam.getName(), "body");
    assertEquals(bodyParam.getIn(), "body");
    assertTrue(bodyParam.getRequired());
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) Swagger(io.swagger.models.Swagger) FormParameter(io.swagger.models.parameters.FormParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) FormParameter(io.swagger.models.parameters.FormParameter) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 74 with Parameter

use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.

the class ReaderTest method scanClassAndFieldLevelAnnotations.

@Test(description = "scan class level and field level annotations")
public void scanClassAndFieldLevelAnnotations() {
    Swagger swagger = getSwagger(ResourceWithKnownInjections.class);
    List<Parameter> resourceParameters = getGet(swagger, "/resource/{id}").getParameters();
    assertNotNull(resourceParameters);
    assertEquals(resourceParameters.size(), 3);
    assertEquals(resourceParameters.get(0).getName(), "id");
    assertEquals(resourceParameters.get(1).getName(), "fieldParam");
    assertEquals(resourceParameters.get(2).getName(), "methodParam");
    List<Parameter> subResourceParameters = getGet(swagger, "/resource/{id}/subresource1").getParameters();
    assertNotNull(subResourceParameters);
    assertEquals(subResourceParameters.size(), 3);
    assertEquals(subResourceParameters.get(0).getName(), "id");
    assertEquals(subResourceParameters.get(1).getName(), "fieldParam");
    assertEquals(subResourceParameters.get(2).getName(), "subResourceParam");
}
Also used : Swagger(io.swagger.models.Swagger) FormParameter(io.swagger.models.parameters.FormParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Test(org.testng.annotations.Test)

Example 75 with Parameter

use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.

the class SwaggerJersey2JaxrsTest method returnProperFormDataParam.

@Test(description = "return the proper @FormDataParam Parameters based on the call to extractParameters")
public void returnProperFormDataParam() throws NoSuchMethodException {
    final Method method = getClass().getDeclaredMethod("testFormDataParamRoute", InputStream.class, FormDataContentDisposition.class);
    final List<Pair<Type, Annotation[]>> parameters = getParameters(method.getGenericParameterTypes(), method.getParameterAnnotations());
    for (Pair<Type, Annotation[]> parameter : parameters) {
        Type parameterType = parameter.first();
        List<Parameter> swaggerParams = new SwaggerJersey2Jaxrs().extractParameters(Arrays.asList(parameter.second()), parameterType, new HashSet<Type>(), SwaggerExtensions.chain());
        if (parameterType.equals(InputStream.class)) {
            assertEquals(((FormParameter) swaggerParams.get(0)).getType(), "file");
        } else {
            assertEquals(swaggerParams.size(), 0);
        }
    }
}
Also used : Type(java.lang.reflect.Type) SwaggerJersey2Jaxrs(io.swagger.jersey.SwaggerJersey2Jaxrs) HeaderParameter(io.swagger.models.parameters.HeaderParameter) FormParameter(io.swagger.models.parameters.FormParameter) Parameter(io.swagger.models.parameters.Parameter) Method(java.lang.reflect.Method) Annotation(java.lang.annotation.Annotation) Pair(org.testng.internal.collections.Pair) Test(org.testng.annotations.Test)

Aggregations

Parameter (io.swagger.models.parameters.Parameter)92 BodyParameter (io.swagger.models.parameters.BodyParameter)54 QueryParameter (io.swagger.models.parameters.QueryParameter)53 PathParameter (io.swagger.models.parameters.PathParameter)51 Test (org.testng.annotations.Test)51 HeaderParameter (io.swagger.models.parameters.HeaderParameter)38 Swagger (io.swagger.models.Swagger)33 FormParameter (io.swagger.models.parameters.FormParameter)27 Operation (io.swagger.models.Operation)20 SerializableParameter (io.swagger.models.parameters.SerializableParameter)15 Type (java.lang.reflect.Type)14 ArrayList (java.util.ArrayList)14 Annotation (java.lang.annotation.Annotation)10 Path (io.swagger.models.Path)9 Method (java.lang.reflect.Method)9 JavaType (com.fasterxml.jackson.databind.JavaType)7 ContextParameter (io.servicecomb.swagger.extend.parameter.ContextParameter)6 Property (io.swagger.models.properties.Property)6 HashMap (java.util.HashMap)6 AnnotatedParameter (com.fasterxml.jackson.databind.introspect.AnnotatedParameter)5