References:
Background
Usage of the allOf constraint describes a JSON schema that must match all subschemas defined, which I've seen used as a way to compose multiple schemas or share a common base model.
Note from JSON schema docs:
Instances must independently be valid against “all of” the schemas in the allOf.
The PetStore Expanded 3.0 spec has an example of this:
# .. rest of OAS
components:
schemas:
Pet:
allOf:
- $ref: '#/components/schemas/NewPet'
- type: object
required:
- id
properties:
id:
type: integer
format: int64
NewPet:
type: object
required:
- name
properties:
name:
type: string
tag:
type: string
Proposal
I'm wondering for something like above if we can consider the schema as both of them combined, for the example above:
Original
Pet:
allOf:
- $ref: "#/components/schemas/NewPet"
- type: object
required:
- id
properties:
id:
type: integer
format: int64
NewPet:
type: object
required:
- name
properties:
name:
type: string
tag:
type: string
Combined
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Possible IR output
{
"name": "pet",
"schema": {
"attributes": [
{
"name": "id",
"int64": {
"computed_optional_required": "required"
}
},
{
"name": "name",
"string": {
"computed_optional_required": "required"
}
},
{
"name": "tag",
"string": {
"computed_optional_required": "computed_optional"
}
}
]
}
}
Notes
- We'd need to combine the schemas together somehow, duplicate properties with mismatched types/nested children would need to be considered
- There are potential invalid
allOf use-cases we'd need to determine how to handle
- The
allOf keyword can appear anywhere, not just in the root of the schema like shown above 😄 , will need to consider that
References:
Background
Usage of the
allOfconstraint describes a JSON schema that must match all subschemas defined, which I've seen used as a way to compose multiple schemas or share a common base model.Note from JSON schema docs:
The PetStore Expanded 3.0 spec has an example of this:
Proposal
I'm wondering for something like above if we can consider the schema as both of them combined, for the example above:
Original
Combined
Possible IR output
{ "name": "pet", "schema": { "attributes": [ { "name": "id", "int64": { "computed_optional_required": "required" } }, { "name": "name", "string": { "computed_optional_required": "required" } }, { "name": "tag", "string": { "computed_optional_required": "computed_optional" } } ] } }Notes
allOfuse-cases we'd need to determine how to handleallOfkeyword can appear anywhere, not just in the root of the schema like shown above 😄 , will need to consider that