Java Code Examples for io.swagger.models.parameters.SerializableParameter#setType()
The following examples show how to use
io.swagger.models.parameters.SerializableParameter#setType() .
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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
Source File: RestControllerProcessor.java From herd with Apache License 2.0 | 4 votes |
/** * Converts the given Java parameter type into a Swagger param type and sets it into the given Swagger param. * * @param parameterSource the parameter source. * @param swaggerParam the Swagger parameter. */ private void setParameterType(ParameterSource<JavaClassSource> parameterSource, SerializableParameter swaggerParam) throws MojoExecutionException { try { String typeName = parameterSource.getType().getQualifiedName(); if (String.class.getName().equals(typeName)) { swaggerParam.setType("string"); } else if (Integer.class.getName().equals(typeName) || Long.class.getName().equals(typeName)) { swaggerParam.setType("integer"); } else if (Boolean.class.getName().equals(typeName)) { swaggerParam.setType("boolean"); } else { // See if the type is an enum. Enum<?>[] enumValues = (Enum<?>[]) Class.forName(parameterSource.getType().getQualifiedName()).getEnumConstants(); if (enumValues != null) { swaggerParam.setType("string"); swaggerParam.setEnum(new ArrayList<>()); for (Enum<?> enumEntry : enumValues) { swaggerParam.getEnum().add(enumEntry.name()); } } else { // Assume "string" for all other types since everything is ultimately a string. swaggerParam.setType("string"); } } log.debug("Parameter \"" + parameterSource.getName() + "\" is a type \"" + swaggerParam.getType() + "\"."); } catch (ClassNotFoundException e) { throw new MojoExecutionException("Unable to instantiate class \"" + parameterSource.getType().getQualifiedName() + "\". Reason: " + e.getMessage(), e); } }