io.swagger.models.parameters.QueryParameter Java Examples
The following examples show how to use
io.swagger.models.parameters.QueryParameter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JaxrsReaderTest.java From swagger-maven-plugin with Apache License 2.0 | 6 votes |
@Test public void createCommonParameters() throws Exception { reader = new JaxrsReader(new Swagger(), Mockito.mock(Log.class)); Swagger result = reader.read(CommonParametersApi.class); Parameter headerParam = result.getParameter("headerParam"); assertTrue(headerParam instanceof HeaderParameter); Parameter queryParam = result.getParameter("queryParam"); assertTrue(queryParam instanceof QueryParameter); result = reader.read(ReferenceCommonParametersApi.class); Operation get = result.getPath("/apath").getGet(); List<Parameter> parameters = get.getParameters(); for (Parameter parameter : parameters) { assertTrue(parameter instanceof RefParameter); } ObjectMapper mapper = Json.mapper(); ObjectWriter jsonWriter = mapper.writer(new DefaultPrettyPrinter()); String json = jsonWriter.writeValueAsString(result); JsonNode expectJson = mapper.readTree(this.getClass().getResourceAsStream("/expectedOutput/swagger-common-parameters.json")); JsonAssert.assertJsonEquals(expectJson, json); }
Example #2
Source File: RpcReaderExtension.java From sofa-rpc with Apache License 2.0 | 6 votes |
private Parameter readParam(Swagger swagger, Type type, Class<?> cls, ApiParam param) { PrimitiveType fromType = PrimitiveType.fromType(type); final Parameter para = null == fromType ? new BodyParameter() : new QueryParameter(); Parameter parameter = ParameterProcessor.applyAnnotations(swagger, para, type, null == param ? new ArrayList<Annotation>() : Collections.<Annotation> singletonList(param)); if (parameter instanceof AbstractSerializableParameter) { final AbstractSerializableParameter<?> p = (AbstractSerializableParameter<?>) parameter; if (p.getType() == null) { p.setType(null == fromType ? "string" : fromType.getCommonName()); } p.setRequired(p.getRequired() || cls.isPrimitive()); } else { //hack: Get the from data model paramter from BodyParameter BodyParameter bp = (BodyParameter) parameter; bp.setIn("body"); Property property = ModelConverters.getInstance().readAsProperty(type); final Map<PropertyBuilder.PropertyId, Object> args = new EnumMap<PropertyBuilder.PropertyId, Object>( PropertyBuilder.PropertyId.class); bp.setSchema(PropertyBuilder.toModel(PropertyBuilder.merge(property, args))); } return parameter; }
Example #3
Source File: MappingConverterImplTest.java From binder-swagger-java with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testMtoParameters_Single() { List<Parameter> params = converter.mToParameters("id", $(longv(required())).in("query").desc("id").$$); assertEquals(params.size(), 1); assertTrue(params.get(0) instanceof QueryParameter); QueryParameter p = (QueryParameter) params.get(0); assertEquals(p.getType(), "integer"); assertEquals(p.getFormat(), "int64"); assertEquals(p.getDescription(), "id"); assertEquals(p.getRequired(), true); /// 'in' is required!!! try { List<Parameter> params1 = converter.mToParameters("id", $(longv(required())).desc("id").$$); assertTrue("shouldn't", false); } catch (Exception e) { assertEquals(e.getMessage(), "in is required!!!"); } }
Example #4
Source File: DubboReaderExtension.java From swagger-dubbo with Apache License 2.0 | 6 votes |
private Parameter readParam(Swagger swagger, Type type,Class<?> cls, ApiParam param) { PrimitiveType fromType = PrimitiveType.fromType(type); final Parameter para = null == fromType ? new BodyParameter() : new QueryParameter(); Parameter parameter = ParameterProcessor.applyAnnotations(swagger, para, type == null ? String.class : type, null == param ? new ArrayList<Annotation>() : Collections.<Annotation> singletonList(param)); if (parameter instanceof AbstractSerializableParameter) { final AbstractSerializableParameter<?> p = (AbstractSerializableParameter<?>) parameter; if (p.getType() == null) p.setType(null == fromType ? "string" : fromType.getCommonName()); p.setRequired(p.getRequired() == true ? true : cls.isPrimitive()); }else{ //hack: Get the from data model paramter from BodyParameter BodyParameter bp = (BodyParameter)parameter; bp.setIn("formData"); } return parameter; }
Example #5
Source File: AbstractSerializableParameterExtractorTest.java From vertx-swagger with Apache License 2.0 | 6 votes |
@Test() public void testArrayMulti() { String name = "myName"; SerializableParameter parameter = new QueryParameter(); parameter.setName("myName"); parameter.setType("array"); parameter.setCollectionFormat("multi"); List<String> paramsList = new ArrayList<>(); paramsList.add("toto"); paramsList.add("tutu"); paramsList.add("titi"); MultiMap params = MultiMap.caseInsensitiveMultiMap(); params.add(name, paramsList); Object result = abstractSerializableParameterExtractor.extract(name, parameter, params); Assert.assertArrayEquals(paramsList.toArray(), ((List) result).toArray()); }
Example #6
Source File: SwaggerUtils.java From micro-integrator with Apache License 2.0 | 6 votes |
/** * This method will generate path and query parameters in the swagger document. * * @param method method of API resource. * @param operation swagger operation object. * @param parameterList list of parameters. */ private static void generatePathAndQueryParameters(String method, Operation operation, List<AxisResourceParameter> parameterList) { if (!parameterList.isEmpty()) { for (AxisResourceParameter resourceParameter : parameterList) { AxisResourceParameter.ParameterType resourceParameterType = resourceParameter.getParameterType(); if (resourceParameterType.equals(AxisResourceParameter.ParameterType.URL_PARAMETER)) { PathParameter pathParameter = new PathParameter(); pathParameter.setName(resourceParameter.getParameterName()); pathParameter.setType(resourceParameter.getParameterDataType()); pathParameter.required(true); operation.addParameter(pathParameter); } else if (resourceParameterType .equals(AxisResourceParameter.ParameterType.QUERY_PARAMETER) && "GET".equals(method)) { // Currently handling query parameter only for GET requests. QueryParameter queryParameter = new QueryParameter(); queryParameter.setName(resourceParameter.getParameterName()); queryParameter.setType(resourceParameter.getParameterDataType()); queryParameter.required(true); operation.addParameter(queryParameter); } } } }
Example #7
Source File: AbstractOperationGenerator.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
protected Parameter createParameter(HttpParameterType httpParameterType) { switch (httpParameterType) { case PATH: return new PathParameter(); case QUERY: return new QueryParameter(); case HEADER: return new HeaderParameter(); case FORM: return new FormParameter(); case COOKIE: return new CookieParameter(); case BODY: return new BodyParameter(); default: throw new IllegalStateException("not support httpParameterType " + httpParameterType); } }
Example #8
Source File: TestQueryProcessorCreator.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
@Test public void testCreate() { ParamValueProcessorCreator creator = ParamValueProcessorCreatorManager.INSTANCE.findValue(QueryProcessorCreator.PARAMTYPE); Parameter parameter = new QueryParameter(); parameter.setName("query"); ParamValueProcessor processor = creator.create(parameter, String.class); Assert.assertEquals(QueryProcessor.class, processor.getClass()); String result = (String) processor.convertValue("Hello", TypeFactory.defaultInstance().constructType(String.class)); Assert.assertEquals("Hello", result); result = (String) processor.convertValue("", TypeFactory.defaultInstance().constructType(String.class)); Assert.assertEquals("", result); result = (String) processor.convertValue(null, TypeFactory.defaultInstance().constructType(String.class)); Assert.assertEquals(null, result); }
Example #9
Source File: URLPathBuilderTest.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
@Test public void testRegexPathParam() throws Exception { Map<String, RestParam> paramMap = new LinkedHashMap<>(); addParam("p0", int.class, PathParameter::new, paramMap); addParam("p1", String.class, PathParameter::new, paramMap); addParam("q0", int.class, QueryParameter::new, paramMap); addParam("q1", String.class, QueryParameter::new, paramMap); URLPathBuilder urlPathBuilder = new URLPathBuilder("/path/{p0 : .*}/and/{p1:.*}", paramMap); Map<String, Object> parameters = new HashMap<>(); parameters.put("p0", 10); parameters.put("p1", "abcPath"); parameters.put("q0", 11); parameters.put("q1", "queryABC"); Assert.assertEquals("/path/10/and/abcPath?q0=11&q1=queryABC", urlPathBuilder.createRequestPath(parameters)); Assert.assertEquals("/path/10/and/abcPath", urlPathBuilder.createPathString(parameters)); }
Example #10
Source File: TestPath.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
@Test public void testUrlPathBuilder() throws Exception { Map<String, RestParam> paramMap = new HashMap<>(); Parameter pathParameter = new PathParameter(); pathParameter.setName("id"); RestParam oRestParam = new RestParam(pathParameter, int.class); paramMap.put(oRestParam.getParamName(), oRestParam); Parameter queryParameter = new QueryParameter(); queryParameter.setName("q"); oRestParam = new RestParam(queryParameter, String.class); paramMap.put(oRestParam.getParamName(), oRestParam); URLPathBuilder oURLPathBuilder = new URLPathBuilder("/root/{id}", paramMap); Map<String, Object> parameters = new HashMap<>(); parameters.put("id", 100); parameters.put("q", "query"); Assert.assertEquals("/root/100?q=query", oURLPathBuilder.createRequestPath(parameters)); Assert.assertEquals("/root/100", oURLPathBuilder.createPathString(parameters)); }
Example #11
Source File: URLPathBuilderTest.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
@Test public void testMultiQuery() throws Exception { Map<String, RestParam> paramMap = new LinkedHashMap<>(); addParam("strArr", String[].class, QueryParameter::new, paramMap); addParam("intArr", int[].class, QueryParameter::new, paramMap); URLPathBuilder urlPathBuilder = new URLPathBuilder("/path", paramMap); Map<String, Object> parameters = new HashMap<>(); parameters.put("strArr", new Object[] {"a", "b", "c"}); parameters.put("intArr", new Object[] {1, 2, 3}); Assert.assertEquals("/path?strArr=a&strArr=b&strArr=c&intArr=1&intArr=2&intArr=3", urlPathBuilder.createRequestPath(parameters)); parameters.put("strArr", new Object[] {}); parameters.put("intArr", new Object[] {1, 2, 3}); Assert.assertEquals("/path?intArr=1&intArr=2&intArr=3", urlPathBuilder.createRequestPath(parameters)); parameters.put("strArr", new Object[] {"a", "b", "c"}); parameters.put("intArr", new Object[] {}); Assert.assertEquals("/path?strArr=a&strArr=b&strArr=c", urlPathBuilder.createRequestPath(parameters)); parameters.put("strArr", new Object[] {}); parameters.put("intArr", new Object[] {}); Assert.assertEquals("/path", urlPathBuilder.createRequestPath(parameters)); }
Example #12
Source File: URLPathBuilderTest.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
@Test public void testNormal() throws Exception { Map<String, RestParam> paramMap = new LinkedHashMap<>(); addParam("p0", int.class, PathParameter::new, paramMap); addParam("p1", String.class, PathParameter::new, paramMap); addParam("q0", int.class, QueryParameter::new, paramMap); addParam("q1", String.class, QueryParameter::new, paramMap); URLPathBuilder urlPathBuilder = new URLPathBuilder("/path/{p0}/and/{p1}", paramMap); Map<String, Object> parameters = new HashMap<>(); parameters.put("p0", 10); parameters.put("p1", "abcPath"); parameters.put("q0", 11); parameters.put("q1", "queryABC"); Assert.assertEquals("/path/10/and/abcPath?q0=11&q1=queryABC", urlPathBuilder.createRequestPath(parameters)); Assert.assertEquals("/path/10/and/abcPath", urlPathBuilder.createPathString(parameters)); }
Example #13
Source File: AbstractSerializableParameterExtractorTest.java From vertx-swagger with Apache License 2.0 | 5 votes |
@Test(expected = IllegalArgumentException.class) public void testNullAllowEmptyValueWithEmptyParameter() { String name = "myName"; SerializableParameter parameter = new QueryParameter(); parameter.setName("myName"); MultiMap params = MultiMap.caseInsensitiveMultiMap(); params.add(name, ""); abstractSerializableParameterExtractor.extract(name, parameter, params); }
Example #14
Source File: TestQueryProcessor.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
private ParamValueProcessor createProcessor(String name, Class<?> type, String defaultValue, boolean required, String collectionFormat) { JavaType javaType = TypeFactory.defaultInstance().constructType(type); QueryParameter queryParameter = new QueryParameter(); queryParameter.name(name) .required(required) .collectionFormat(collectionFormat) .setDefaultValue(defaultValue); if (javaType.isContainerType()) { queryParameter.type(ArrayProperty.TYPE); } return new QueryProcessor(queryParameter, javaType); }
Example #15
Source File: AbstractSerializableParameterExtractorTest.java From vertx-swagger with Apache License 2.0 | 5 votes |
@Test() public void testArray() { String name = "myName"; SerializableParameter parameter = new QueryParameter(); parameter.setName("myName"); parameter.setType("array"); parameter.setCollectionFormat(null); String param = "toto,tutu,titi"; MultiMap params = MultiMap.caseInsensitiveMultiMap(); params.add(name, param); Object result = abstractSerializableParameterExtractor.extract(name, parameter, params); Assert.assertArrayEquals(new String[] { "toto", "tutu", "titi" }, ((List) result).toArray()); }
Example #16
Source File: AbstractSerializableParameterExtractorTest.java From vertx-swagger with Apache License 2.0 | 5 votes |
@Test() public void testArraySsv() { String name = "myName"; SerializableParameter parameter = new QueryParameter(); parameter.setName("myName"); parameter.setType("array"); parameter.setCollectionFormat("ssv"); String param = "toto tutu titi"; MultiMap params = MultiMap.caseInsensitiveMultiMap(); params.add(name, param); Object result = abstractSerializableParameterExtractor.extract(name, parameter, params); Assert.assertArrayEquals(new String[] { "toto", "tutu", "titi" }, ((List) result).toArray()); }
Example #17
Source File: AbstractSerializableParameterExtractorTest.java From vertx-swagger with Apache License 2.0 | 5 votes |
@Test() public void testArrayCsv() { String name = "myName"; SerializableParameter parameter = new QueryParameter(); parameter.setName("myName"); parameter.setType("array"); parameter.setCollectionFormat("csv"); String param = "toto,tutu,titi"; MultiMap params = MultiMap.caseInsensitiveMultiMap(); params.add(name, param); Object result = abstractSerializableParameterExtractor.extract(name, parameter, params); Assert.assertArrayEquals(new String[] { "toto", "tutu", "titi" }, ((List) result).toArray()); }
Example #18
Source File: AbstractSerializableParameterExtractorTest.java From vertx-swagger with Apache License 2.0 | 5 votes |
@Test() public void testArrayTsv() { String name = "myName"; SerializableParameter parameter = new QueryParameter(); parameter.setName("myName"); parameter.setType("array"); parameter.setCollectionFormat("tsv"); String param = "toto\ttutu\ttiti"; MultiMap params = MultiMap.caseInsensitiveMultiMap(); params.add(name, param); Object result = abstractSerializableParameterExtractor.extract(name, parameter, params); Assert.assertArrayEquals(new String[] { "toto", "tutu", "titi" }, ((List) result).toArray()); }
Example #19
Source File: AbstractSerializableParameterExtractorTest.java From vertx-swagger with Apache License 2.0 | 5 votes |
@Test() public void testArrayPipes() { String name = "myName"; SerializableParameter parameter = new QueryParameter(); parameter.setName("myName"); parameter.setType("array"); parameter.setCollectionFormat("pipes"); String param = "toto|tutu|titi"; MultiMap params = MultiMap.caseInsensitiveMultiMap(); params.add(name, param); Object result = abstractSerializableParameterExtractor.extract(name, parameter, params); Assert.assertArrayEquals(new String[] { "toto", "tutu", "titi" }, ((List) result).toArray()); }
Example #20
Source File: AbstractSerializableParameterExtractorTest.java From vertx-swagger with Apache License 2.0 | 5 votes |
@Test() public void testArrayOther() { String name = "myName"; SerializableParameter parameter = new QueryParameter(); parameter.setName("myName"); parameter.setType("array"); parameter.setCollectionFormat("anyOtherValue"); String param = "toto,tutu,titi"; MultiMap params = MultiMap.caseInsensitiveMultiMap(); params.add(name, param); Object result = abstractSerializableParameterExtractor.extract(name, parameter, params); Assert.assertArrayEquals(new String[] { "toto", "tutu", "titi" }, ((List) result).toArray()); }
Example #21
Source File: AbstractSerializableParameterExtractorTest.java From vertx-swagger with Apache License 2.0 | 5 votes |
@Test() public void testDefault() { String name = "myName"; SerializableParameter parameter = new QueryParameter(); parameter.setName("myName"); parameter.setType("string"); String param = "toto"; MultiMap params = MultiMap.caseInsensitiveMultiMap(); params.add(name, param); Object result = abstractSerializableParameterExtractor.extract(name, parameter, params); Assert.assertEquals("toto", result); }
Example #22
Source File: ResourceReaderExtension.java From mdw with Apache License 2.0 | 5 votes |
private Parameter createParam(String paramType) { if ("path".equals(paramType)) return new PathParameter(); else if ("query".equals(paramType)) return new QueryParameter(); else if ("form".equals(paramType)) return new FormParameter(); else if ("formData".equals(paramType)) return new FormParameter(); else if ("header".equals(paramType)) return new HeaderParameter(); else if ("body".equals(paramType)) return new BodyParameter(); return null; }
Example #23
Source File: SwaggerWorkflowReader.java From mdw with Apache License 2.0 | 5 votes |
private io.swagger.models.parameters.Parameter createParam(ParameterType paramType) { if (paramType == ParameterType.Path) return new PathParameter(); else if (paramType == ParameterType.Query) return new QueryParameter(); else if (paramType == ParameterType.Form) return new FormParameter(); else if (paramType == ParameterType.Header) return new HeaderParameter(); else if (paramType == ParameterType.Body) return new BodyParameter(); return null; }
Example #24
Source File: SwaggerDefinition.java From Web-API with MIT License | 5 votes |
private static QueryParameter constructQueryParameter(String name, String description, String... values) { QueryParameter param = new QueryParameter(); param.setName(name); param.setDescription(description); if (values != null && values.length > 0) { param.setType("string"); param.setEnum(Arrays.asList(values)); } else { param.setType("boolean"); } return param; }
Example #25
Source File: SequenceGenerator.java From carbon-apimgt with Apache License 2.0 | 5 votes |
private static void populateParametersFromOperation(Operation operation, Map<String, Model> definitions, Map<String, String> parameterJsonPathMapping, Map<String, String> queryParameters) { List<Parameter> parameters = operation.getParameters(); for (Parameter parameter : parameters) { String name = parameter.getName(); if (parameter instanceof BodyParameter) { Model schema = ((BodyParameter) parameter).getSchema(); if (schema instanceof RefModel) { String $ref = ((RefModel) schema).get$ref(); if (StringUtils.isNotBlank($ref)) { String defName = $ref.substring("#/definitions/".length()); Model model = definitions.get(defName); Example example = ExampleBuilder.fromModel(defName, model, definitions, new HashSet<String>()); String jsonExample = Json.pretty(example); try { org.json.JSONObject json = new org.json.JSONObject(jsonExample); SequenceUtils.listJson(json, parameterJsonPathMapping); } catch (JSONException e) { log.error("Error occurred while generating json mapping for the definition: " + defName, e); } } } } if (parameter instanceof QueryParameter) { String type = ((QueryParameter) parameter).getType(); queryParameters.put(name, type); } } }
Example #26
Source File: AbstractSerializableParameterExtractorTest.java From vertx-swagger with Apache License 2.0 | 5 votes |
@Test() public void testMissingNonRequiredParam() { String name = "myName"; SerializableParameter parameter = new QueryParameter(); parameter.setName("myName"); parameter.setRequired(false); Object result = abstractSerializableParameterExtractor.extract(name, parameter, MultiMap.caseInsensitiveMultiMap()); Assert.assertNull(result); }
Example #27
Source File: RpcReaderExtension.java From sofa-rpc with Apache License 2.0 | 5 votes |
private Parameter readImplicitParam(Swagger swagger, ApiImplicitParam param) { PrimitiveType fromType = PrimitiveType.fromName(param.paramType()); final Parameter p = null == fromType ? new FormParameter() : new QueryParameter(); final Type type = ReflectionUtils.typeFromString(param.dataType()); return ParameterProcessor.applyAnnotations(swagger, p, type == null ? String.class : type, Collections.<Annotation> singletonList(param)); }
Example #28
Source File: DubboReaderExtension.java From swagger-dubbo with Apache License 2.0 | 5 votes |
private Parameter readImplicitParam(Swagger swagger, ApiImplicitParam param) { PrimitiveType fromType = PrimitiveType.fromName(param.paramType()); final Parameter p = null == fromType ? new FormParameter() : new QueryParameter(); final Type type = ReflectionUtils.typeFromString(param.dataType()); return ParameterProcessor.applyAnnotations(swagger, p, type == null ? String.class : type, Collections.<Annotation> singletonList(param)); }
Example #29
Source File: TestApiParam.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Test public void springmvcQuery() { check("apiParamSpringmvc", "query"); Assert.assertTrue(parameter.getRequired()); Assert.assertTrue(parameter.isReadOnly()); Assert.assertEquals("inputEx", parameter.getName()); Assert.assertEquals(10L, ((QueryParameter) parameter).getExample()); Assert.assertNull(((QueryParameter) parameter).getCollectionFormat()); }
Example #30
Source File: TestApiParam.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Test public void springmvcQueryArray() { check("apiParamSpringmvc", "queryArr", "query"); Assert.assertTrue(parameter.getRequired()); Assert.assertTrue(parameter.isReadOnly()); Assert.assertEquals("inputEx", parameter.getName()); Assert.assertEquals("10", ((QueryParameter) parameter).getExample()); Assert.assertEquals("csv", ((QueryParameter) parameter).getCollectionFormat()); }