Search in sources :

Example 1 with SwaggerJersey2Jaxrs

use of io.swagger.jersey.SwaggerJersey2Jaxrs 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)

Example 2 with SwaggerJersey2Jaxrs

use of io.swagger.jersey.SwaggerJersey2Jaxrs in project swagger-core by swagger-api.

the class SwaggerJersey2JaxrsTest method testAllTypes.

@Test(description = "not skip all types passed to extension")
public void testAllTypes() {
    for (Class cls : Arrays.asList(BaseBean.class, ChildBean.class, RefBean.class)) {
        Set<Type> typesToSkip = new java.util.HashSet<Type>();
        new SwaggerJersey2Jaxrs().extractParameters(new ArrayList<Annotation>(), cls, typesToSkip, SwaggerExtensions.chain());
        assertEquals(typesToSkip.size(), 0);
    }
}
Also used : Type(java.lang.reflect.Type) SwaggerJersey2Jaxrs(io.swagger.jersey.SwaggerJersey2Jaxrs) Annotation(java.lang.annotation.Annotation) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 3 with SwaggerJersey2Jaxrs

use of io.swagger.jersey.SwaggerJersey2Jaxrs in project swagger-core by swagger-api.

the class SwaggerJersey2JaxrsTest method returnProperBeanParam.

@Test(description = "return the proper @BeanParam Parameters based on the call to extractParameters")
public void returnProperBeanParam() throws NoSuchMethodException {
    final Method method = getClass().getDeclaredMethod("testRoute", BaseBean.class, ChildBean.class, RefBean.class, EnumBean.class, Integer.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());
        // Ensure proper number of parameters returned
        if (parameterType.equals(BaseBean.class)) {
            assertEquals(swaggerParams.size(), 2);
        } else if (parameterType.equals(ChildBean.class)) {
            assertEquals(swaggerParams.size(), 5);
        } else if (parameterType.equals(RefBean.class)) {
            assertEquals(swaggerParams.size(), 5);
        } else if (parameterType.equals(EnumBean.class)) {
            assertEquals(swaggerParams.size(), 1);
            HeaderParameter enumParam = (HeaderParameter) swaggerParams.get(0);
            assertEquals(enumParam.getType(), "string");
            final Set<String> enumValues = Sets.newHashSet(Collections2.transform(Arrays.asList(TestEnum.values()), Functions.toStringFunction()));
            assertEquals(enumParam.getEnum(), enumValues);
        } else if (parameterType.equals(Integer.class)) {
            assertEquals(swaggerParams.size(), 0);
        } else {
            fail(String.format("Parameter of type %s was not expected", parameterType));
        }
        // Ensure the proper parameter type and name is returned (The rest is handled by pre-existing logic)
        for (Parameter param : swaggerParams) {
            assertEquals(param.getName(), param.getClass().getSimpleName().replace("eter", ""));
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Method(java.lang.reflect.Method) Annotation(java.lang.annotation.Annotation) ChildBean(io.swagger.params.ChildBean) Type(java.lang.reflect.Type) SwaggerJersey2Jaxrs(io.swagger.jersey.SwaggerJersey2Jaxrs) EnumBean(io.swagger.params.EnumBean) HeaderParameter(io.swagger.models.parameters.HeaderParameter) FormParameter(io.swagger.models.parameters.FormParameter) Parameter(io.swagger.models.parameters.Parameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) Pair(org.testng.internal.collections.Pair) Test(org.testng.annotations.Test)

Aggregations

SwaggerJersey2Jaxrs (io.swagger.jersey.SwaggerJersey2Jaxrs)3 Annotation (java.lang.annotation.Annotation)3 Type (java.lang.reflect.Type)3 Test (org.testng.annotations.Test)3 FormParameter (io.swagger.models.parameters.FormParameter)2 HeaderParameter (io.swagger.models.parameters.HeaderParameter)2 Parameter (io.swagger.models.parameters.Parameter)2 Method (java.lang.reflect.Method)2 HashSet (java.util.HashSet)2 Pair (org.testng.internal.collections.Pair)2 ChildBean (io.swagger.params.ChildBean)1 EnumBean (io.swagger.params.EnumBean)1 Set (java.util.Set)1