3

I have a spring webapp, i've aadded swagger and swagger-ui. I've added a dummy class to test swagger:

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiError;
import com.wordnik.swagger.annotations.ApiErrors;
import com.wordnik.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Api(value = "DummyController", description = "Dummy description for the controller")
@Controller
@RequestMapping(value = "/dummy")
public class DummyClassForSwagger {

    @ApiOperation(value = "First dummy output", httpMethod = "GET")
    @ApiErrors({@ApiError(code = 404, reason = "First dummy test") })
    @RequestMapping(value = "/first", method = RequestMethod.GET)
    @ResponseBody
    public String dummyOutputOne() {
        return "Dummy output";
    }

    @ApiOperation(value = "Second dummy output", httpMethod = "GET")
    @ApiErrors({@ApiError(code = 404, reason = "Second dummy test") })
    @RequestMapping(value = "/second", method = RequestMethod.GET)
    @ResponseBody
    public String dummyOutputTwo() {
        return "Second dummy output";
    }
}

After build/deploy i can see the dummy class on the swagger page (see attachment 1). The problem is, that "List operations" doesn't show anything. The raw output is as follow:

<controllerDocumentation>
<apiVersion>1.0</apiVersion>
<apis>
<description>Dummy description for the controller</description>
<operations>
<deprecated>false</deprecated>
<errorResponses>
<code>404</code>
<reason>First dummy test</reason>
</errorResponses>
<httpMethod>GET</httpMethod>
<nickname>dummyOutputOne</nickname>
<notes/>
<responseClass>String</responseClass>
<summary>First dummy output</summary>
</operations>
<path>/dummy/first</path>
</apis>
<apis>
<description>Dummy description for the controller</description>
<operations>
<deprecated>false</deprecated>
<errorResponses>
<code>404</code>
<reason>Second dummy test</reason>
</errorResponses>
<httpMethod>GET</httpMethod>
<nickname>dummyOutputTwo</nickname>
<notes/>
<responseClass>String</responseClass>
<summary>Second dummy output</summary>
</operations>
<path>/dummy/second</path>
</apis>
<basePath>http://localhost:8080/mapserver/core</basePath>
<models/>
<resourcePath>/dummy</resourcePath>
<swaggerVersion>1.0</swaggerVersion>
</controllerDocumentation>

I think, the problem is a missing tag "operation" or something like this...but i'm not sure (and i don't know, how to fix this). Any suggestions?

1

1 Answer 1

0

I had a similar issue. I was getting the error "SwaggerOperation handleIllegalArgumentsException is missing method.".

After debugging I figured out my @ExceptionHandler methods in Controller class didn't have any swagger annotations, and this was causing the issue.

I commented my ExceptionHandler methods and swagger ui started working fine.

I am now figuring out which swagger annotations to use for ExceptionHandler methods in spring mvc.

My ExceptionHandler method in my controller class was:

@ExceptionHandler({IllegalArgumentException.class})
public ResponseEntity<?> handleIllegalArgumentsException(IllegalArgumentException e)
{
    LOGGER.error("IllegalArgumentException in user controller", e);
    return new ResponseEntity<>(new ErrorResponseDTO("BAD_REQUEST", e.getMessage()), HttpStatus.BAD_REQUEST);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.