-
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.
test classes and fix for #615, inferring return type if not specified…
… in annotations
- Loading branch information
Showing
3 changed files
with
52 additions
and
1 deletion.
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
24 changes: 24 additions & 0 deletions
24
modules/swagger-jaxrs/src/test/scala/ResourceWithReturnTypesTest.scala
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,24 @@ | ||
import testresources.ResourceWithReturnTypes | ||
|
||
import com.wordnik.swagger.config.SwaggerConfig | ||
import com.wordnik.swagger.jaxrs.reader.DefaultJaxrsApiReader | ||
import com.wordnik.swagger.core.util.JsonSerializer | ||
|
||
import org.junit.runner.RunWith | ||
import org.scalatest.{Matchers, FlatSpec} | ||
import org.scalatest.junit.JUnitRunner | ||
|
||
@RunWith(classOf[JUnitRunner]) | ||
class ResourceWithReturnTypesTest extends FlatSpec with Matchers { | ||
it should "read an api and extract the return type" in { | ||
val reader = new DefaultJaxrsApiReader | ||
val config = new SwaggerConfig() | ||
val apiResource = reader.read("/api-docs", classOf[ResourceWithReturnTypes], config).getOrElse(fail("should not be None")) | ||
|
||
val operations = apiResource.apis.head.operations | ||
|
||
operations.size should be (1) | ||
val op = operations.head | ||
op.responseClass should be ("Howdy") | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
modules/swagger-jaxrs/src/test/scala/testresources/ResourceWithReturnTypes.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,27 @@ | ||
package testresources; | ||
|
||
import testmodels.*; | ||
import com.wordnik.swagger.core.*; | ||
import com.wordnik.swagger.annotations.*; | ||
|
||
import javax.ws.rs.*; | ||
import javax.ws.rs.core.Response; | ||
|
||
import javax.xml.bind.annotation.*; | ||
|
||
@Path("/basic") | ||
@Api(value = "/basic", description = "Basic resource") | ||
public class ResourceWithReturnTypes { | ||
@GET | ||
@Path("/{id}") | ||
@ApiOperation(value = "Find by ID") | ||
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"), | ||
@ApiResponse(code = 404, message = "Pet not found") }) | ||
public Sample getTest( | ||
@ApiParam(value = "sample param data", required = true, allowableValues = "range[0,10]")@DefaultValue("1") @QueryParam("id") String id) { | ||
Sample out = new Sample(); | ||
out.setName("foo"); | ||
out.setValue("bar"); | ||
return out; | ||
} | ||
} |