Search in sources :

Example 6 with HeaderParameter

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

the class ParameterProcessorTest method resourceWithArrayParamTest.

@Test
public void resourceWithArrayParamTest() throws NoSuchMethodException {
    final Method method = getClass().getDeclaredMethod("arrayParametrizedMethod", List.class);
    final Type[] genericParameterTypes = method.getGenericParameterTypes();
    final Annotation[][] paramAnnotations = method.getParameterAnnotations();
    final HeaderParameter param = (HeaderParameter) ParameterProcessor.applyAnnotations(null, new HeaderParameter(), genericParameterTypes[0], Arrays.asList(paramAnnotations[0]));
    assertNotNull(param);
    assertEquals((int) param.getMinItems(), 5);
    assertEquals((int) param.getMaxItems(), 10);
}
Also used : Type(java.lang.reflect.Type) Method(java.lang.reflect.Method) HeaderParameter(io.swagger.models.parameters.HeaderParameter) Test(org.testng.annotations.Test)

Example 7 with HeaderParameter

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

the class TestRestCodec method beforeClass.

@BeforeClass
public static void beforeClass() {
    restOperation = Mockito.mock(RestOperationMeta.class);
    //        clientRequest = Mockito.mock(RestClientRequest.class);
    paramList = new ArrayList<>();
    Parameter hp = new HeaderParameter();
    hp.setName("header");
    paramList.add(new RestParam(0, hp, int.class));
    when(restOperation.getParamList()).thenReturn(paramList);
}
Also used : RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) Parameter(io.swagger.models.parameters.Parameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) RestParam(io.servicecomb.common.rest.definition.RestParam) BeforeClass(org.junit.BeforeClass)

Example 8 with HeaderParameter

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

the class ParameterProcessorTest method beanValidationArrayParametrizedMethodTest.

@Test
public void beanValidationArrayParametrizedMethodTest() throws NoSuchMethodException {
    final Method method = getClass().getDeclaredMethod("beanValidationArrayParametrizedMethod", List.class, List.class, List.class, String.class);
    final Type[] genericParameterTypes = method.getGenericParameterTypes();
    final Annotation[][] paramAnnotations = method.getParameterAnnotations();
    //First param - items specified
    HeaderParameter headerParam1 = new HeaderParameter().type(ArrayProperty.TYPE).items(new LongProperty());
    HeaderParameter param1 = (HeaderParameter) ParameterProcessor.applyAnnotations(null, headerParam1, genericParameterTypes[0], Arrays.asList(paramAnnotations[0]));
    assertNotNull(param1);
    assertEquals((int) param1.getMinItems(), 5);
    assertEquals((int) param1.getMaxItems(), 10);
    Property items1 = param1.getItems();
    assertTrue(items1 instanceof LongProperty);
    LongProperty longItems = (LongProperty) items1;
    assertEquals(longItems.getMinimum(), new BigDecimal(5));
    assertNull(longItems.getExclusiveMinimum());
    assertEquals(longItems.getMaximum(), new BigDecimal(10));
    assertNull(longItems.getExclusiveMaximum());
    //Second param - items specified
    HeaderParameter headerParam2 = new HeaderParameter().type(ArrayProperty.TYPE).items(new DoubleProperty());
    HeaderParameter param2 = (HeaderParameter) ParameterProcessor.applyAnnotations(null, headerParam2, genericParameterTypes[1], Arrays.asList(paramAnnotations[1]));
    assertNotNull(param2);
    assertEquals((int) param2.getMinItems(), 5);
    assertEquals((int) param2.getMaxItems(), 10);
    Property items2 = param2.getItems();
    assertTrue(items2 instanceof DoubleProperty);
    DoubleProperty doubleItems = (DoubleProperty) items2;
    assertEquals(doubleItems.getMinimum(), new BigDecimal(5.5));
    assertTrue(doubleItems.getExclusiveMinimum());
    assertEquals(doubleItems.getMaximum(), new BigDecimal(10.5));
    assertTrue(doubleItems.getExclusiveMaximum());
    //Third param - items specified
    HeaderParameter headerParam3 = new HeaderParameter().type(ArrayProperty.TYPE).items(new StringProperty());
    HeaderParameter param3 = (HeaderParameter) ParameterProcessor.applyAnnotations(null, headerParam3, genericParameterTypes[2], Arrays.asList(paramAnnotations[2]));
    assertNotNull(param3);
    assertEquals((int) param3.getMinItems(), 5);
    assertEquals((int) param3.getMaxItems(), 10);
    Property items3 = param3.getItems();
    assertTrue(items3 instanceof StringProperty);
    StringProperty stringItems = (StringProperty) items3;
    assertEquals(stringItems.getPattern(), TEST_PATTERN_REGXP);
    //Fourth param - items specified
    HeaderParameter headerParam4 = new HeaderParameter().type(StringProperty.TYPE);
    HeaderParameter param4 = (HeaderParameter) ParameterProcessor.applyAnnotations(null, headerParam4, genericParameterTypes[3], Arrays.asList(paramAnnotations[3]));
    assertNotNull(param4);
    assertEquals(param4.getType(), ArrayProperty.TYPE);
    assertEquals((int) param4.getMinItems(), 5);
    assertEquals((int) param4.getMaxItems(), 10);
    Property items4 = param4.getItems();
    assertTrue(items4 instanceof StringProperty);
}
Also used : Type(java.lang.reflect.Type) LongProperty(io.swagger.models.properties.LongProperty) StringProperty(io.swagger.models.properties.StringProperty) Method(java.lang.reflect.Method) HeaderParameter(io.swagger.models.parameters.HeaderParameter) DoubleProperty(io.swagger.models.properties.DoubleProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) LongProperty(io.swagger.models.properties.LongProperty) Property(io.swagger.models.properties.Property) DoubleProperty(io.swagger.models.properties.DoubleProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 9 with HeaderParameter

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

the class DefaultParameterExtension method extractParameters.

@Override
public List<Parameter> extractParameters(List<Annotation> annotations, Type type, Set<Type> typesToSkip, Iterator<SwaggerExtension> chain) {
    if (shouldIgnoreType(type, typesToSkip)) {
        return new ArrayList<Parameter>();
    }
    List<Parameter> parameters = new ArrayList<Parameter>();
    Parameter parameter = null;
    for (Annotation annotation : annotations) {
        if (annotation instanceof QueryParam) {
            QueryParam param = (QueryParam) annotation;
            QueryParameter qp = new QueryParameter().name(param.value());
            Property schema = createProperty(type);
            if (schema != null) {
                qp.setProperty(schema);
            }
            parameter = qp;
        } else if (annotation instanceof PathParam) {
            PathParam param = (PathParam) annotation;
            PathParameter pp = new PathParameter().name(param.value());
            Property schema = createProperty(type);
            if (schema != null) {
                pp.setProperty(schema);
            }
            parameter = pp;
        } else if (annotation instanceof HeaderParam) {
            HeaderParam param = (HeaderParam) annotation;
            HeaderParameter hp = new HeaderParameter().name(param.value());
            Property schema = createProperty(type);
            if (schema != null) {
                hp.setProperty(schema);
            }
            parameter = hp;
        } else if (annotation instanceof CookieParam) {
            CookieParam param = (CookieParam) annotation;
            CookieParameter cp = new CookieParameter().name(param.value());
            Property schema = createProperty(type);
            if (schema != null) {
                cp.setProperty(schema);
            }
            parameter = cp;
        } else if (annotation instanceof FormParam) {
            FormParam param = (FormParam) annotation;
            FormParameter fp = new FormParameter().name(param.value());
            Property schema = createProperty(type);
            if (schema != null) {
                fp.setProperty(schema);
            }
            parameter = fp;
        } else {
            handleAdditionalAnnotation(parameters, annotation, type, typesToSkip);
        }
    }
    if (parameter != null) {
        parameters.add(parameter);
    }
    return parameters;
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParam(javax.ws.rs.HeaderParam) ArrayList(java.util.ArrayList) PathParameter(io.swagger.models.parameters.PathParameter) FormParameter(io.swagger.models.parameters.FormParameter) Annotation(java.lang.annotation.Annotation) CookieParam(javax.ws.rs.CookieParam) QueryParam(javax.ws.rs.QueryParam) HeaderParameter(io.swagger.models.parameters.HeaderParameter) CookieParameter(io.swagger.models.parameters.CookieParameter) FormParameter(io.swagger.models.parameters.FormParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) CookieParameter(io.swagger.models.parameters.CookieParameter) PathParam(javax.ws.rs.PathParam) HeaderParameter(io.swagger.models.parameters.HeaderParameter) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) FormParam(javax.ws.rs.FormParam)

Example 10 with HeaderParameter

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

the class Reader method readImplicitParam.

protected Parameter readImplicitParam(ApiImplicitParam param) {
    final Parameter p;
    if (param.paramType().equalsIgnoreCase("path")) {
        p = new PathParameter();
    } else if (param.paramType().equalsIgnoreCase("query")) {
        p = new QueryParameter();
    } else if (param.paramType().equalsIgnoreCase("form") || param.paramType().equalsIgnoreCase("formData")) {
        p = new FormParameter();
    } else if (param.paramType().equalsIgnoreCase("body")) {
        p = null;
    } else if (param.paramType().equalsIgnoreCase("header")) {
        p = new HeaderParameter();
    } else {
        LOGGER.warn("Unknown implicit parameter type: [{}]", param.paramType());
        return null;
    }
    final Type type = param.dataTypeClass() == Void.class ? ReflectionUtils.typeFromString(param.dataType()) : param.dataTypeClass();
    return ParameterProcessor.applyAnnotations(swagger, p, (type == null) ? String.class : type, Arrays.<Annotation>asList(param));
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) Type(java.lang.reflect.Type) JavaType(com.fasterxml.jackson.databind.JavaType) ParameterizedType(java.lang.reflect.ParameterizedType) 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) AnnotatedParameter(com.fasterxml.jackson.databind.introspect.AnnotatedParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) PathParameter(io.swagger.models.parameters.PathParameter) FormParameter(io.swagger.models.parameters.FormParameter)

Aggregations

HeaderParameter (io.swagger.models.parameters.HeaderParameter)14 Parameter (io.swagger.models.parameters.Parameter)10 Test (org.testng.annotations.Test)10 QueryParameter (io.swagger.models.parameters.QueryParameter)7 FormParameter (io.swagger.models.parameters.FormParameter)6 PathParameter (io.swagger.models.parameters.PathParameter)6 BodyParameter (io.swagger.models.parameters.BodyParameter)5 StringProperty (io.swagger.models.properties.StringProperty)5 Type (java.lang.reflect.Type)5 Method (java.lang.reflect.Method)4 ArrayProperty (io.swagger.models.properties.ArrayProperty)3 Property (io.swagger.models.properties.Property)3 Annotation (java.lang.annotation.Annotation)3 Swagger (io.swagger.models.Swagger)2 DoubleProperty (io.swagger.models.properties.DoubleProperty)2 IntegerProperty (io.swagger.models.properties.IntegerProperty)2 LongProperty (io.swagger.models.properties.LongProperty)2 RefProperty (io.swagger.models.properties.RefProperty)2 ChildBean (io.swagger.params.ChildBean)2 EnumBean (io.swagger.params.EnumBean)2