How to declare a $ref property as readOnly in Open

2019-07-07 17:12发布

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 be set to readOnly without an error, but when I set the single definition of House to readOnly I get the following warning in the Swagger Editor:

Sibling values are not allowed alongside $refs

I understand that this is because everything in the model is inherited here. So how do I define that the write API calls cannot define a 'House' in this endpoint whilst also allowing House to be created and updated in another API endpoints?

Pets:
  properties:
    id:
      type: string
      example: AAAAE12-1123AEF-1122312123
      readOnly: true
    name:
      type: string
      example: My Default Name
    text:
      type: string
      example: My Default Text
  Dogs:
    type: array
    readOnly: true
    items:
      $ref: '#/definitions/Dog'    
  House:
    readOnly: true
    $ref: '#/definitions/House'

1条回答
狗以群分
2楼-- · 2019-07-07 17:30

You need allOf to combine a $ref with other attributes:

  House:
    readOnly: true
    allOf:
      - $ref: '#/definitions/House'
查看更多
登录 后发表回答