【问题标题】:Swagger(-ui) doesn't show the operationsSwagger(-ui) 不显示操作
【发布时间】:2013-11-17 09:05:18
【问题描述】:

我有一个 spring webapp,我添加了 swagger 和 swagger-ui。我添加了一个虚拟类来测试招摇:

导入 com.wordnik.swagger.annotations.Api; 导入 com.wordnik.swagger.annotations.ApiError; 导入 com.wordnik.swagger.annotations.ApiErrors; 导入 com.wordnik.swagger.annotations.ApiOperation; 导入 org.springframework.stereotype.Controller; 导入 org.springframework.web.bind.annotation.RequestBody; 导入 org.springframework.web.bind.annotation.RequestMapping; 导入 org.springframework.web.bind.annotation.RequestMethod; 导入 org.springframework.web.bind.annotation.ResponseBody; @Api(value = "DummyController", description = "控制器的虚拟描述") @控制器 @RequestMapping(value = "/dummy") 公共类 DummyClassForSwagger { @ApiOperation(value = "第一个虚拟输出", httpMethod = "GET") @ApiErrors({@ApiError(code = 404, reason = "First dummy test") }) @RequestMapping(value = "/first", method = RequestMethod.GET) @ResponseBody 公共字符串 dummyOutputOne() { 返回“虚拟输出”; } @ApiOperation(value = "第二个虚拟输出", httpMethod = "GET") @ApiErrors({@ApiError(code = 404, reason = "Second dummy test") }) @RequestMapping(value = "/second", method = RequestMethod.GET) @ResponseBody 公共字符串 dummyOutputTwo() { 返回“第二个虚拟输出”; } }

构建/部署后,我可以在 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>

我认为,问题是缺少标签“操作”或类似的东西......但我不确定(我不知道如何解决这个问题)。有什么建议吗?

【问题讨论】:

标签: java spring operation swagger swagger-ui


【解决方案1】:

我遇到了类似的问题。我收到了错误"SwaggerOperation handleIllegalArgumentsException is missing method."

调试后,我发现Controller 类中的@ExceptionHandler 方法没有任何swagger 注释,这是导致问题的原因。

我评论了我的ExceptionHandler 方法并且swagger ui 开始正常工作。

我现在正在弄清楚 spring mvc 中的 ExceptionHandler 方法使用哪些 swagger 注释。

我的控制器类中的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);
}

【讨论】:

    猜你喜欢
    • 2020-06-10
    • 1970-01-01
    • 2021-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-07
    • 1970-01-01
    • 2020-10-27
    相关资源
    最近更新 更多