OpenAPI-Specification icon indicating copy to clipboard operation
OpenAPI-Specification copied to clipboard

Advice to design POST resource with nested object with some field readOnly

Open esoni88 opened this issue 6 years ago • 2 comments

Hi All, suppose we have two model Author and Resource :

    Author:
      type: object
      properties:
        id:
          type: string
          readOnly: true
        name:
          type: string
      required: 
        - id
        - name
          
    Book:
      type: object
      properties:
        id:
          type: string
          readOnly: true
        name:
          type: string
        author:
          $ref: '#/components/schemas/Author'
      required: 
        - id
        - name
        - author

i want to define two endpoint:

  • POST /authors that allow to insert an author

  • POST /books that insert a book that refer an existing book

  • When client execute a POST to insert the book have to eval in json all the author object ? example

{
"id": "x",
"name": "title",
"author": {
 "id": "y",
"name": "paolo",
}
}

or i can eval only id of the author ? i want to be compliant to my openapi definition 2) the id of the author is declared readonly but when i post a Book, i eval the author field with id valued. i break my openapi def ?

esoni88 avatar Jan 22 '20 17:01 esoni88

If you're still interested in this, I took a look and I'm not sure I understand the question. You have to use the whole schema provided for the whole payload. If you want something to be readOnly: true in one place and not in another, you have to arrange your schemas that way. If something is only sometimes readOnly: true, then a schema can't really express that. Does that answer your question (with apologies for being years late - feel free to ignore if no longer relevant).

handrews avatar Jan 28 '24 20:01 handrews

This issue has been labeled with No recent activity because there has been no recent activity. It will be closed if no further activity occurs within 28 days. Please re-open this issue or open a new one after this delay if you need to.

github-actions[bot] avatar Feb 04 '24 20:02 github-actions[bot]