-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #1160: CollectionFormat default value for form and query parame…
…ters has been changed to multi
- Loading branch information
1 parent
ef70819
commit 0e6d817
Showing
7 changed files
with
154 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
modules/swagger-jaxrs/src/test/java/io/swagger/CollectionFormatTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package io.swagger; | ||
|
||
import io.swagger.jaxrs.Reader; | ||
import io.swagger.models.Operation; | ||
import io.swagger.models.Swagger; | ||
import io.swagger.models.parameters.AbstractSerializableParameter; | ||
import org.testng.annotations.Test; | ||
import resources.CollectionFormatResource; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertNull; | ||
|
||
public class CollectionFormatTest{ | ||
private static final String MULTI = "multi"; | ||
private static final String CSV = "csv"; | ||
private final Swagger swagger = new Reader(new Swagger()).read(CollectionFormatResource.class); | ||
|
||
@Test(testName = "check collection format for QueryParam") | ||
public void readQueryParamTest() { | ||
Operation operation = getOperation("testQueryParam"); | ||
assertEquals(getCollectionFormat(operation, 0), MULTI); | ||
assertNull(getCollectionFormat(operation, 1)); | ||
assertEquals(getCollectionFormat(operation, 2), MULTI); | ||
} | ||
|
||
@Test(testName = "check collection format for FormParam") | ||
public void readFormParamTest() { | ||
Operation operation = getOperation("testFormParam"); | ||
assertEquals(getCollectionFormat(operation, 0), MULTI); | ||
assertNull(getCollectionFormat(operation, 1)); | ||
assertEquals(getCollectionFormat(operation, 2), MULTI); | ||
} | ||
|
||
@Test(testName = "check collection format for PathParam") | ||
public void readPathParamTest() { | ||
Operation operation = getOperation("testPathParam"); | ||
assertEquals(getCollectionFormat(operation, 0), CSV); | ||
assertNull(getCollectionFormat(operation, 1)); | ||
assertEquals(getCollectionFormat(operation, 2), CSV); | ||
} | ||
|
||
@Test(testName = "check collection format for HeaderParam") | ||
public void readHeaderParamTest() { | ||
Operation operation = getOperation("testHeaderParam"); | ||
assertEquals(getCollectionFormat(operation, 0), CSV); | ||
assertNull(getCollectionFormat(operation, 1)); | ||
assertEquals(getCollectionFormat(operation, 2), CSV); | ||
} | ||
|
||
@Test(testName = "check collection format for CookieParam") | ||
public void readCookieParamTest() { | ||
Operation operation = getOperation("testCookieParam"); | ||
assertEquals(getCollectionFormat(operation, 0), CSV); | ||
assertNull(getCollectionFormat(operation, 1)); | ||
assertEquals(getCollectionFormat(operation, 2), CSV); | ||
} | ||
|
||
@Test(testName = "check collection format for Mixed Param") | ||
public void readMixedParamTest() { | ||
Operation operation = getOperation("testMixedParam"); | ||
assertEquals(getCollectionFormat(operation, 0), MULTI); | ||
assertEquals(getCollectionFormat(operation, 1), CSV); | ||
assertNull(getCollectionFormat(operation, 2)); | ||
assertEquals(getCollectionFormat(operation, 3), CSV); | ||
} | ||
|
||
private Operation getOperation(String name) { | ||
return swagger.getPath("/collectionFormat/" + name).getPost(); | ||
} | ||
|
||
private String getCollectionFormat(Operation op, int index) { | ||
return ((AbstractSerializableParameter) op.getParameters().get(index)).getCollectionFormat(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
modules/swagger-jaxrs/src/test/scala/resources/CollectionFormatResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package resources; | ||
|
||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import io.swagger.annotations.ApiParam; | ||
|
||
import javax.ws.rs.CookieParam; | ||
import javax.ws.rs.FormParam; | ||
import javax.ws.rs.HeaderParam; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.QueryParam; | ||
import java.util.List; | ||
|
||
@Api | ||
@Path("/collectionFormat") | ||
public class CollectionFormatResource { | ||
|
||
@POST | ||
@Path("/testQueryParam") | ||
@ApiOperation("Tests Query Param") | ||
public void testQueryParam(@QueryParam("list") List<Integer> list, @QueryParam("scalar") Integer scalar, | ||
@QueryParam("forced") @ApiParam(allowMultiple = true) int forced) { | ||
} | ||
|
||
@POST | ||
@Path("/testFormParam") | ||
@ApiOperation("Tests Form Param") | ||
public void testFormParam(@FormParam("list") List<Integer> list, @FormParam("scalar") Integer scalar, | ||
@FormParam("forced") @ApiParam(allowMultiple = true) int forced) { | ||
} | ||
|
||
@POST | ||
@Path("/testPathParam") | ||
@ApiOperation("Tests Path Param") | ||
public void testPathParam(@PathParam("list") List<Integer> list, @PathParam("scalar") Integer scalar, | ||
@PathParam("forced") @ApiParam(allowMultiple = true) int forced) { | ||
} | ||
|
||
@POST | ||
@Path("/testHeaderParam") | ||
@ApiOperation("Tests Header Param") | ||
public void testHeaderParam(@HeaderParam("list") List<Integer> list, @HeaderParam("scalar") Integer scalar, | ||
@HeaderParam("forced") @ApiParam(allowMultiple = true) int forced) { | ||
} | ||
|
||
@POST | ||
@Path("/testCookieParam") | ||
@ApiOperation("Tests Cookie Param") | ||
public void testCookieParam(@CookieParam("list") List<Integer> list, @CookieParam("scalar") Integer scalar, | ||
@CookieParam("forced") @ApiParam(allowMultiple = true) int forced) { | ||
} | ||
|
||
@POST | ||
@Path("/testMixedParam") | ||
@ApiOperation("Tests Mixed Param") | ||
public void testMixedParam(@QueryParam("queryList") List<Integer> queryList, | ||
@PathParam("pathList") List<Integer> pathList, @HeaderParam("scalar") Integer scalar, | ||
@CookieParam("forced") @ApiParam(allowMultiple = true) int forced) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters