【问题标题】:How do I wrap JSON objects?如何包装 JSON 对象?
【发布时间】:2016-08-01 10:06:13
【问题描述】:

我目前正在寻找一种将 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 文件中添加代码!需要您的帮助才能找到位置:)

【问题讨论】:

    标签: json swagger swagger-ui swagger-2.0 swagger-editor


    【解决方案1】:

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

    请以https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml#L646为例,看看Pet和Category是如何定义的。

      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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-17
      • 1970-01-01
      • 2016-03-22
      • 2018-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多