Forum Discussion

MaximVasilenko's avatar
MaximVasilenko
New Contributor
5 years ago

Partial use of model attributes

Good afternoon!

Please tell me what to do if in requestBody or response it is necessary to transfer not all attributes of the entity, but only the necessary ones. For example, there is a certain entity:

Entity:
      title: Entity
      type: object
      properties:
        id:
          type: integer
          format: int 64
          example: 6421
        attributes2:
          type: string
          description: text
        attributes3:
          type: string
          description: "text"
        attributes4:
          type: array
          description: "text"
          items: 
            $ref: '#/components/schemas/Schema'            
        attributes5:
           type: boolean
           description: "text"

For the post method, you need to pass only part of this entity in the request, for example:

Entity:
      title: Entity
      type: object
      properties:
        attributes2:
          type: string
          description: text
        attributes3:
          type: string
          description: "text"

How to do this so that requestBody does not specify completely, but only with the necessary attributes?

Now it turns out to me that the whole entity is indicated, for example:

post:
     tags:
     - Entities
     summary: ""
     description: "text"
     operationId: addEntity
     requestBody:
       description: "text"
       required: true
       content:
         application/json:
           schema:
             $ref: '#/components/schemas/Entity'        
     responses:
        '201':
           description: Created
           content:
               application/json:
                schema:
                 type: object
                 properties:
                  data:
                   $ref: '#/components/schemas/Entity'

 

 

 

  • HKosova's avatar
    HKosova
    5 years ago

    Hi Maxim,

     

    It's not possible to exclude properties from a schema. You need to do it the other way round - define a base schema with just the common properties, then inherit from that schema and add new properties.