Search in sources :

Example 76 with Parameter

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

Example 77 with Parameter

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

the class PathTest method testParameters.

@Test
public void testParameters() {
    // given
    Path path = new Path();
    Parameter parameter = Mockito.mock(Parameter.class);
    path.setParameters(null);
    // when
    path.addParameter(parameter);
    // then
    assertTrue(path.getParameters().contains(parameter), "The parameters list must contain the newly added one");
}
Also used : Parameter(io.swagger.models.parameters.Parameter) Test(org.testng.annotations.Test)

Example 78 with Parameter

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

the class ImplicitParametersTest method detailedTest.

@Test
public void detailedTest() throws NoSuchMethodException {
    final Operation operation = new Operation();
    final ReaderContext context = createDefaultContext();
    extension.applyImplicitParameters(context, operation, findMethod(context, "testMethod3"));
    final List<Parameter> parameters = operation.getParameters();
    final Parameter parameter1 = parameters.get(0);
    Assert.assertNotNull(parameter1);
    Assert.assertTrue(parameter1 instanceof PathParameter);
    Assert.assertEquals(parameter1.getName(), "param1");
    Assert.assertEquals(parameter1.getIn(), "path");
    Assert.assertEquals(parameter1.getDescription(), "Param 1");
    Assert.assertTrue(parameter1.getRequired());
    final Parameter parameter5 = parameters.get(4);
    Assert.assertNotNull(parameter5);
    Assert.assertTrue(parameter5 instanceof BodyParameter);
    Assert.assertEquals(parameter5.getName(), "param5");
    Assert.assertEquals(parameter5.getIn(), "body");
    Assert.assertEquals(parameter5.getDescription(), "Param 5");
    Assert.assertFalse(parameter5.getRequired());
}
Also used : ReaderContext(io.swagger.servlet.ReaderContext) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) Operation(io.swagger.models.Operation) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Test(org.testng.annotations.Test)

Example 79 with Parameter

use of io.swagger.models.parameters.Parameter in project java-chassis by ServiceComb.

the class ApiImplicitParamMethodProcessor method process.

@Override
public void process(Object annotation, OperationGenerator operationGenerator) {
    ApiImplicitParam paramAnnotation = (ApiImplicitParam) annotation;
    Parameter parameter = AnnotationUtils.createParameter(operationGenerator.getSwagger(), paramAnnotation);
    operationGenerator.addMethodAnnotationParameter(parameter);
}
Also used : Parameter(io.swagger.models.parameters.Parameter) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam)

Example 80 with Parameter

use of io.swagger.models.parameters.Parameter in project java-chassis by ServiceComb.

the class OperationGenerator method processBodyBasedParameter.

protected void processBodyBasedParameter() {
    List<BodyParameter> bodyParameters = collectBodyBasedParameters();
    if (bodyParameters.isEmpty()) {
        return;
    }
    if (bodyParameters.size() == 1) {
        Parameter bodyParameter = bodyParameters.get(0);
        replaceBodyBasedParameter(bodyParameter);
        return;
    }
    // 将多个pending合并成一个body
    mergeBodyBasedParameters(bodyParameters);
}
Also used : PendingBodyParameter(io.servicecomb.swagger.extend.parameter.PendingBodyParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) ContextParameter(io.servicecomb.swagger.extend.parameter.ContextParameter) PendingBodyParameter(io.servicecomb.swagger.extend.parameter.PendingBodyParameter) BodyParameter(io.swagger.models.parameters.BodyParameter)

Aggregations

Parameter (io.swagger.models.parameters.Parameter)86 BodyParameter (io.swagger.models.parameters.BodyParameter)50 Test (org.testng.annotations.Test)50 QueryParameter (io.swagger.models.parameters.QueryParameter)48 PathParameter (io.swagger.models.parameters.PathParameter)47 HeaderParameter (io.swagger.models.parameters.HeaderParameter)38 Swagger (io.swagger.models.Swagger)30 FormParameter (io.swagger.models.parameters.FormParameter)23 Operation (io.swagger.models.Operation)17 SerializableParameter (io.swagger.models.parameters.SerializableParameter)15 Type (java.lang.reflect.Type)13 ArrayList (java.util.ArrayList)10 Annotation (java.lang.annotation.Annotation)9 Method (java.lang.reflect.Method)9 JavaType (com.fasterxml.jackson.databind.JavaType)7 ContextParameter (io.servicecomb.swagger.extend.parameter.ContextParameter)6 Path (io.swagger.models.Path)6 AnnotatedParameter (com.fasterxml.jackson.databind.introspect.AnnotatedParameter)5 Reader (io.swagger.jaxrs.Reader)5 Response (io.swagger.models.Response)4