Search in sources :

Example 6 with FormParam

use of javax.ws.rs.FormParam 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 7 with FormParam

use of javax.ws.rs.FormParam in project tomee by apache.

the class ResourceUtils method getParameter.

// CHECKSTYLE:OFF
public static Parameter getParameter(int index, Annotation[] anns, Class<?> type) {
    Context ctx = AnnotationUtils.getAnnotation(anns, Context.class);
    if (ctx != null) {
        return new Parameter(ParameterType.CONTEXT, index, null);
    }
    boolean isEncoded = AnnotationUtils.getAnnotation(anns, Encoded.class) != null;
    BeanParam bp = AnnotationUtils.getAnnotation(anns, BeanParam.class);
    if (bp != null) {
        return new Parameter(ParameterType.BEAN, index, null, isEncoded, null);
    }
    String dValue = AnnotationUtils.getDefaultParameterValue(anns);
    PathParam a = AnnotationUtils.getAnnotation(anns, PathParam.class);
    if (a != null) {
        return new Parameter(ParameterType.PATH, index, a.value(), isEncoded, dValue);
    }
    QueryParam q = AnnotationUtils.getAnnotation(anns, QueryParam.class);
    if (q != null) {
        return new Parameter(ParameterType.QUERY, index, q.value(), isEncoded, dValue);
    }
    MatrixParam m = AnnotationUtils.getAnnotation(anns, MatrixParam.class);
    if (m != null) {
        return new Parameter(ParameterType.MATRIX, index, m.value(), isEncoded, dValue);
    }
    FormParam f = AnnotationUtils.getAnnotation(anns, FormParam.class);
    if (f != null) {
        return new Parameter(ParameterType.FORM, index, f.value(), isEncoded, dValue);
    }
    HeaderParam h = AnnotationUtils.getAnnotation(anns, HeaderParam.class);
    if (h != null) {
        return new Parameter(ParameterType.HEADER, index, h.value(), isEncoded, dValue);
    }
    CookieParam c = AnnotationUtils.getAnnotation(anns, CookieParam.class);
    if (c != null) {
        return new Parameter(ParameterType.COOKIE, index, c.value(), isEncoded, dValue);
    }
    return new Parameter(ParameterType.REQUEST_BODY, index, null);
}
Also used : Context(javax.ws.rs.core.Context) CookieParam(javax.ws.rs.CookieParam) MatrixParam(javax.ws.rs.MatrixParam) HeaderParam(javax.ws.rs.HeaderParam) Encoded(javax.ws.rs.Encoded) QueryParam(javax.ws.rs.QueryParam) Parameter(org.apache.cxf.jaxrs.model.Parameter) PathParam(javax.ws.rs.PathParam) FormParam(javax.ws.rs.FormParam) BeanParam(javax.ws.rs.BeanParam)

Example 8 with FormParam

use of javax.ws.rs.FormParam in project cxf by apache.

the class ResourceUtils method getParameter.

// CHECKSTYLE:OFF
public static Parameter getParameter(int index, Annotation[] anns, Class<?> type) {
    Context ctx = AnnotationUtils.getAnnotation(anns, Context.class);
    if (ctx != null) {
        return new Parameter(ParameterType.CONTEXT, index, null);
    }
    boolean isEncoded = AnnotationUtils.getAnnotation(anns, Encoded.class) != null;
    BeanParam bp = AnnotationUtils.getAnnotation(anns, BeanParam.class);
    if (bp != null) {
        return new Parameter(ParameterType.BEAN, index, null, isEncoded, null);
    }
    String dValue = AnnotationUtils.getDefaultParameterValue(anns);
    PathParam a = AnnotationUtils.getAnnotation(anns, PathParam.class);
    if (a != null) {
        return new Parameter(ParameterType.PATH, index, a.value(), isEncoded, dValue);
    }
    QueryParam q = AnnotationUtils.getAnnotation(anns, QueryParam.class);
    if (q != null) {
        return new Parameter(ParameterType.QUERY, index, q.value(), isEncoded, dValue);
    }
    MatrixParam m = AnnotationUtils.getAnnotation(anns, MatrixParam.class);
    if (m != null) {
        return new Parameter(ParameterType.MATRIX, index, m.value(), isEncoded, dValue);
    }
    FormParam f = AnnotationUtils.getAnnotation(anns, FormParam.class);
    if (f != null) {
        return new Parameter(ParameterType.FORM, index, f.value(), isEncoded, dValue);
    }
    HeaderParam h = AnnotationUtils.getAnnotation(anns, HeaderParam.class);
    if (h != null) {
        return new Parameter(ParameterType.HEADER, index, h.value(), isEncoded, dValue);
    }
    CookieParam c = AnnotationUtils.getAnnotation(anns, CookieParam.class);
    if (c != null) {
        return new Parameter(ParameterType.COOKIE, index, c.value(), isEncoded, dValue);
    }
    return new Parameter(ParameterType.REQUEST_BODY, index, null);
}
Also used : Context(javax.ws.rs.core.Context) CookieParam(javax.ws.rs.CookieParam) MatrixParam(javax.ws.rs.MatrixParam) HeaderParam(javax.ws.rs.HeaderParam) Encoded(javax.ws.rs.Encoded) QueryParam(javax.ws.rs.QueryParam) Parameter(org.apache.cxf.jaxrs.model.Parameter) PathParam(javax.ws.rs.PathParam) FormParam(javax.ws.rs.FormParam) BeanParam(javax.ws.rs.BeanParam)

Aggregations

FormParam (javax.ws.rs.FormParam)8 PathParam (javax.ws.rs.PathParam)7 QueryParam (javax.ws.rs.QueryParam)7 Annotation (java.lang.annotation.Annotation)6 CookieParam (javax.ws.rs.CookieParam)6 HeaderParam (javax.ws.rs.HeaderParam)6 MatrixParam (javax.ws.rs.MatrixParam)5 BeanParam (javax.ws.rs.BeanParam)3 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Consumes (javax.ws.rs.Consumes)2 DefaultValue (javax.ws.rs.DefaultValue)2 Encoded (javax.ws.rs.Encoded)2 Produces (javax.ws.rs.Produces)2 Context (javax.ws.rs.core.Context)2 MediaType (javax.ws.rs.core.MediaType)2 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)2