How to declare a $ref property as readOnly in OpenAPI (Swagger)?

前端 未结 1 1334
逝去的感伤
逝去的感伤 2021-01-17 20:05

I am trying to add a read-only field for \'House\' in this example. The house is another model that I want to be read-only.

In this example, the array of Dogs can b

相关标签:
1条回答
  • 2021-01-17 20:58

    OpenAPI 3.1 (future version, not yet released)

    In OAS 3.1, schema definitions will support sibling keywords alongside $ref:

    House:
      $ref: '#/components/schemas/House'
      readOnly: true
    

    OpenAPI 3.0 and 2.0

    Sibling keywords alongside $ref are ignored. The workaround is to use allOf to combine a $ref with other attributes:

      House:
        readOnly: true
        allOf:
          - $ref: '#/definitions/House'
    
    0 讨论(0)
提交回复
热议问题