1

我目前正在寻找一种将 JSON 包装在 Swagger UI 组件中的方法。

在 YAML 中,我的对象声明是:

  restException:
    properties:
      message:
        type: string

Swagger UI 生成的输出是(我同意,是正确的): { "message": "string" }

我想要的是:

"restException": {
  "message": "string"
}

我只是通过在 YAML 文件中明确声明包装器找到了一种丑陋的方法。但这非常糟糕,因为当我使用“Swagger Codegen”生成客户端或服务器代码时也会生成它。

restExceptionContainer: restException: properties: message: type: string

如果需要,我可以在 Swagger UI 文件中添加代码!需要您的帮助才能找到位置:)

4

1 回答 1

3

您应该将 restException 记录为一个对象(类型:对象)。

请参考https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml#L646为例,看看Pet如何和类别已定义。

  Pet:
    type: object
    required:
      - name
      - photoUrls
    properties:
      id:
        type: integer
        format: int64
      category:
        $ref: '#/definitions/Category'

其中类别定义为:

  Category:
    type: object
    properties:
      id:
        type: integer
        format: int64
      name:
        type: string
于 2016-04-13T13:50:57.033 回答