I try to find how to define a model that can be represented by one of the following objects:
{
"name": "John Doe",
"additional_info": {
"scheme": {
"id": 1
},
"source": "direct"
}
}
{
"name": "John Doe",
"additional_info": {
"scheme": {
"id": 1
},
"source": "direct",
"optional_key": "something"
}
}
{
"name": "John Doe",
"additional_info": {}
}
So I need to make sure that the additional_info
object OR maybe empty, OR must contain at least two required keys scheme
(AND the scheme
object must contain id
key) and source
, AND may contain any optional keys.
I tried the following scheme:
model:
description: ''
content:
application/json:
schema:
allOf:
- type: object
properties:
name:
type: string
- oneOf:
- type: object
properties:
additional_info:
type: object
properties:
scheme:
type: object
required:
- id
properties:
id:
type: integer
source:
type: string
required:
- scheme
- source
- type: object
properties:
additional_info:
type: object
additionalProperties: false
examples:
example-1:
name: John Doe
additional_info:
scheme:
id: 1
source: direct
example-2:
name: John Doe
additional_info: {}
example-3:
name: John Doe
additional_info:
scheme:
id: 1
source: direct
optional_key: something
But I'm not sure if it is correct.