我有一个春天的网络应用程序,我已经加入了招摇和招摇 - ui。我添加了一个虚拟类来测试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"; } }
在构建/部署之后,我可以在swagger页面上看到虚拟类(请参阅附件1)。问题是,“列表操作”没有显示任何内容。原始输出如下:
<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>
我认为,问题是缺少标签“操作”或类似的东西......但我不确定(我不知道,如何解决这个问题)。有什么建议吗?
答案 0 :(得分:0)
我有类似的问题。我收到错误"SwaggerOperation handleIllegalArgumentsException is missing method."
。
经过调试后,我发现@ExceptionHandler
课程中的Controller
个方法没有任何swagger
注释,这导致了这个问题。
我评论了我的ExceptionHandler
方法,并且swagger ui开始正常工作。
我现在正在计算在spring mvc中用于ExceptionHandler
方法的哪些招摇注释。
我的控制器类中的ExceptionHandler
方法是:
@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);
}