0

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.
Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
  • 1
    Just to check, do you know what a StackOverflowError is? – snickers10m Oct 13 '15 at 00:59
  • Like I said, just checking. – snickers10m Oct 13 '15 at 18:15
  • Aaaand that's why I'm checking. That's *not* what a StackOverflowError is. The site was named after the error, not the other way around. You can read up on it here: http://stackoverflow.com/questions/214741/what-is-a-stackoverflowerror – snickers10m Oct 13 '15 at 18:21
  • Hey, some people don't know! If you had told me what it was in the first place you could have saved 5 comments of our time. Not to mention you're a new user and many new users are also new to programming. – snickers10m Oct 13 '15 at 18:24
  • You said: "no amount of jiggling / randomly adding or removing attributes seems to fix it." This is called debugging by brownian motion, and is one of the major sins of programming. Let me make a random change, and see if that makes it better. Nope. Repeat at step 1. That's a great recipe for the frustration you are experiencing now. The receipe I would use to try to fix this, is to do a tutorial on the malfunctioning method, reduceRight, and try to find a way to better understand that class and that method. But as it stands it looks like a buggy library. – Eric Leschinski Oct 23 '15 at 13:43

0 Answers0