How use ref example with another ref example?

939 Views Asked by At

I am trying to understand how to nest ref inside a ref..

I have 2 objects, ResponseObject and LastUpdatedAt:

ResponseObject:
  type: object
  properties:
    code:
      type: integer
      format: int32s
      minimum: 100
      maximum: 600
    message:
      type: string
    data:
      type: object
  required:
    - code
    - message

and

LastUpdatedAt:
  type: object
  properties:
    last_updated_at:
      type: long
      readOnly: true
      example: 1574933675150

What I want to achieve is making my example look like this: desired_result

I keep trying without success, this is as far as I've gotten:

LastUpdatedAtResponse:
  schema:
    $ref: "#/components/schemas/ResponseObject"
  example:
    - code: 200
      message: 'Success'
      data:
        schema:
          $ref: "#/components/schemas/LocalDataLastUpdatedAt"
        example:
          - lastUpdated: 1574933675150

but this ends up looking like this:

current_state

My end goal is to have all my objects use the ResponseObject but I can't seem to make it work. Any idea what I'm missing?

1

There are 1 best solutions below

0
On

The example keyword does not support $ref. You need to specify the whole example value inline:

LastUpdatedAtResponse:
  ...
  example:
    - code: 200
      message: 'Success'
      data:
        last_updated_at: 1574933675150


Note that $ref is supported in multiple examples, but it can only be used to reference the entire Example Object, it's impossible to $ref just a part of an example.