【问题标题】:Returning an array of objects that properly defines the SDK response返回正确定义 SDK 响应的对象数组
【发布时间】:2017-07-18 19:09:23
【问题描述】:

我有一个返回模型集合的典型 RESTful 端点,但生成的 Ruby SDK 返回一个新模型 Matters 而不是模型数组。我可以破解生成的源代码以返回Array<Matter>,但这是一个令人头疼的维护问题。如何指定要在 YAML 中返回 Array<Matter>

paths:
  /matters:
    get:
    ...
    responses:
      200:
        schema:
          $ref: "#/definitions/Matters"
...
definitions:
  Matter:
    type: "object"
    properties:
      id:
        type: "string"
        description: "Database identifier of the object."
      caseId:
        type: "string"
        description: "Database identifier of the Case object."
      clientMatterNumber:
        type: "string"
        description: "Client/matter billing code."
      judge:
        type: "string"
        description: "Initials of the presiding judge."
      caseNumber:
        type: "string"
        description: "Canonical case number."
      caseTitle:
        type: "string"
        description: "Canonical case title."
      natureOfSuit:
        type: "string"
        description: "Judicial Conference designation of the case."
      docketEntries:
        type: "integer"
        description: "The count of docket entries in the case."
      activityAt:
        type: "string"
        format: "date-time"
        description: "The time of last activity in the case. "
  Matters:
    description: "A collection of matters"
    type: "array"
    items:
      $ref: "#/definitions/Matter"

【问题讨论】:

  • 如何生成 Ruby SDK - 使用 Swagger Codegen 或其他工具?
  • 顺便说一句,Matter 模型中的属性定义无效。将您的规范粘贴到 editor.swagger.io 并修复错误。
  • 海伦,是的,codegen

标签: swagger swagger-2.0 swagger-codegen


【解决方案1】:

想通了……

  responses:
    200:
      description: "200 response"
      schema: 
        type: "array"
        items:
          $ref: "#/definitions/Matter"

【讨论】:

  • 澄清一下 - 解决方案是使用内联数组模型,而不是在 definitions 中定义数组,对吧?
  • 是的,没错。
猜你喜欢
  • 2016-09-15
  • 1970-01-01
  • 2016-09-15
  • 2022-01-01
  • 1970-01-01
  • 2022-01-16
  • 1970-01-01
  • 1970-01-01
  • 2014-12-18
相关资源
最近更新 更多