2

I am creating a swagger spec and I am stuck at the definition part, mainly to represent the PagedResult definition, see below:

definitions:
  PagedResult:
    type: "object"
    properties:
      count:
        type: "integer"
      next:
        type: "string"
      previous:
        type: "string"
      results:
        type: array
        items: <placeholder>?
  Device:
    type: "object"
    properties:
      type:
        type: "string"
      id:
        type: "string"

The results item of PagedResult definition is generic for any definition, how do I specify it in the API responses to inject the specific type into the results items? eg

paths:
  /machines:
    get:
      operationId: "getMachines"
      consumes:
      - "application/json"
      parameters:
      - name: "customer"
        in: "query"
        description: "Get machines by customer"
        required: false
        type: "string"
      responses:
        200:
          description: "successful operation"
          schema:
            type: "array"
            items:
              $ref: "#/definitions/PagedResult" <----- how to inject Device definition here?

I read about reusing definitions but it seems like my case is the opposite. And I don't really want to copy paste PagedResult for every definition.

James Lin
  • 25,028
  • 36
  • 133
  • 233

0 Answers0