Skip to content

Commit

Permalink
test classes and fix for #615, inferring return type if not specified…
Browse files Browse the repository at this point in the history
… in annotations
  • Loading branch information
fehguy committed Dec 21, 2014
1 parent 2f2caca commit e4506a6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ trait JaxrsApiReader extends ClassReader with ClassReaderUtils {
) = {
val api = method.getAnnotation(classOf[Api])
val responseClass = {
if(apiOperation != null){
if(apiOperation != null && !classOf[Void].equals(apiOperation.response)){
val baseName = processDataType(apiOperation.response, apiOperation.response)
val output = apiOperation.responseContainer match {
case "" => baseName
Expand Down
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")
}
}
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;
}
}

0 comments on commit e4506a6

Please sign in to comment.