V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
JasonLaw
V2EX  ›  程序员

怎么让 Swagger UI 展示 @ApiResponse 的多个 examples?

  •  
  •   JasonLaw · 2021-10-31 22:12:17 +08:00 · 1014 次点击
    这是一个创建于 907 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我有如下代码

    @ApiResponses(
            {
                    @ApiResponse(
                            code = 500, message = "业务异常", response = ErrorResponse.class,
                            examples = @Example(value = {
                                    @ExampleProperty(mediaType = MediaType.APPLICATION_JSON_VALUE, value = "{\"error\": {\"code\": \"BUSINESS_EXCEPTION\", \"message\": \"xxx\"}}"),
                                    @ExampleProperty(mediaType = MediaType.APPLICATION_JSON_VALUE, value = "{\"error\": {\"code\": \"BUSINESS_EXCEPTION\", \"message\": \"---\", \"data\": [\"item1\", \"item2\"]}}")
                            })
                    )
            }
    )
    

    但是 Swagger UI 却只展示了其中一个 example ,怎么让它展示出所有 examples 呢?

    第 1 条附言  ·  2021-11-03 17:49:18 +08:00

    已解决此问题,解决方法是“使用DocumentationType.OAS_30,而不是DocumentationType.SWAGGER_2”。

    How to define different responses for same HTTP status code in OpenAPI (Swagger)? - Stack Overflow

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5330 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 08:24 · PVG 16:24 · LAX 01:24 · JFK 04:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.