Mayan19
Mayan19

Reputation: 113

Openapi 3.0: does 'allOf' make the properties of schemas required if the schema is having single property?

I am having following schemas defined in 'components' section of my openApi 3.0:

schema1:
   required:
      - prop1
      - prop2
      - prop3
   properties:
      prop1
      prop2
      prop3
schema2:
   required:
      - prop4
      - prop5
      - prop6
   properties:
      prop4
      prop5
      prop6

now there is another schema performing 'anyOf' operation on above 2 schemas as

schema3:
   anyOf:
     - $ref: '#/components/schema1'
     - $ref: '#/components/schema2'

And I have another schema with a single property as

schema4:
   properties:
      prop7

Now my question is If I perform allOf on schema3 and schema4 in schema5 then will the property7 become a required property? If yes then how to keep property7 optional in schema5.

Schema5 is as:

schema5:
   allOf:
     - $ref: '#/components/schema3'
     - $ref: '#/components/schema4'

Upvotes: 1

Views: 1822

Answers (1)

Helen
Helen

Reputation: 97847

will the property7 become a required property?

No - because property7 is not listed in the required list anywhere in your schemas.

Upvotes: 2

Related Questions