Swagger 不应同时具有 `example` 和 `examples`,因为它们是互斥的

问题描述 投票:0回答:0

我在使用 spring boot 应用程序创建的 swagger 定义时遇到了问题。该错误导致 kubernetes 部署出现问题,并且与尝试以 swagger 方式显示示例 requestBody 有关。这是我从 https://editor.swagger.io/.

得到的错误
application/json
should not have both `example` and `examples`, as they are mutually exclusive
Jump to line 31

错误来自配置的末尾 -> 示例:null

      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PromotionsRequestBody'
            examples:
              promotionsRequestBody:
                description: promotionsRequestBody
                value:
                  ncrc: '12345678'
                  divisionCd: 24
                  promoReq:
                    - unitType: 1
                      cics:
                        - 52030001
                        - 47150124
                        - 13400023
                      startDate: '2023-01-01'
                      endDate: '2023-12-21'
                  stores:
                    - 3427
                    - 3439
                  rogs: SHGN
                  storeGroup: 101
            example: null
        required: true

这是用于显示示例 requestBody 的 swagger 注释的代码片段。

    public ResponseEntity<PromotionsDTO> getPromotions(
            @Parameter(name = "requestBody", description = "requestBody") @Valid
            @io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = @Content(
                    examples = { @ExampleObject(name = "promotionsRequestBody", value = Constants.PROMOTIONS_REQUEST_EXAMPLE) })) @RequestBody PromotionsRequestBody requestBody)
    {

有人知道如何解决这个问题吗? swagger3中没有示例选项。

java spring-boot swagger swagger-ui
© www.soinside.com 2019 - 2024. All rights reserved.