Search code examples
swaggerswagger-2.0swagger-codegen

Returning an array of objects that properly defines the SDK response


I have a typical RESTful endpoint that returns a collection of models, but the generated Ruby SDK returns a new model, Matters instead of an array of models. I can hack at the generated source code to return Array<Matter> but that is a maintenance headache. How do I specify that I want to return Array<Matter> in the YAML?

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"

Solution

  • Figured it out...

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