I've been using the swagger4spring-web library and it seems to have some peculiar bugs (like throwing an ArrayIndexOutOfBoundsException
if you forget to specify the request method of a controller method).
I'm stuck on something though and no amount of jiggling / randomly adding or removing attributes seems to fix it.
When I hit my /api/resourceList
endpoint, I get a 500 with this:
java.lang.StackOverflowError
at scala.collection.LinearSeqOptimized$class.reduceRight(LinearSeqOptimized.scala:131)
at scala.collection.immutable.List.reduceRight(List.scala:84)
at scala.collection.LinearSeqOptimized$class.reduceRight(LinearSeqOptimized.scala:131)
at scala.collection.immutable.List.reduceRight(List.scala:84)
at scala.collection.LinearSeqOptimized$class.reduceRight(LinearSeqOptimized.scala:131)
at scala.collection.immutable.List.reduceRight(List.scala:84)
... (many more lines)
Here is my controller class:
package com.onezork.frobozz.api;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.onezork.frobozz.ServiceIdentity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.time.Instant;
@Controller
@Api("healthcheck")
@RequestMapping(value = "/healthcheck")
public class HealthCheckApi {
private final Instant startTime = Instant.now();
@RequestMapping(value = "/", method = RequestMethod.GET)
@ApiOperation("/")
@ResponseBody
public String healthcheck() {
return ServiceIdentity.getMyHostname() + " running for " +
(Instant.now().getEpochSecond() -
startTime.getEpochSecond())+ " seconds";
}
}
This is the only controller class. When I comment out the swagger annotations, I just get an empty array in /api/resourceList
(as expected).
I'm using swagger4spring-web
0.3.5, spring-*
4.1.6.RELEASE, java 8, tomcat-maven-plugin 1.1 to run it.
EDIT
It does work if and only if I modify the annotation on my class like such:
@RequestMapping(value = "/healthcheck", produces = MediaType.WILDCARD)
I know not why.
EDIT #2
I think I need to more clearly state the problem:
- I am using swagger4spring-web to generate documentation for my swagger API
- I have a webapp with only one endpoint
- The swagger documentation controller exposes the endpoint
/api/resourceList
for swagger documentation - When I hit the provided endpoint, a StackOverflowError is thrown because of some infinite recursion that seems to occur within the swagger library. An error page is returned and the stack trace I pasted above (except much longer) is printed.
- I am hoping that someone who understands this library better can tell me how to properly use it.