• 请不要在回答技术问题时复制粘贴 AI 生成的内容
JasonLaw
V2EX  ›  程序员

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

  •  
  •   JasonLaw · Oct 31, 2021 · 1500 views
    This topic created in 1683 days ago, the information mentioned may be changed or developed.

    我有如下代码

    @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 呢?

    Supplement 1  ·  Nov 3, 2021

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

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

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   941 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 19:22 · PVG 03:22 · LAX 12:22 · JFK 15:22
    ♥ Do have faith in what you're doing.