oneOf Keyword Pattern Support

Use the oneOf keyword to ensure that the given data is valid against one of the subschemas.

Note:

When using oneOf, the following guidelines are mandatory:
  • The discriminator element must be present.
  • The discriminator element name must be unique across all subschemas.

Note:

The following oneOf keyword patterns are not currently supported.
  • oneOf with a subschema being of simple type
  • oneOf defined as items of a top level array
  • oneOf with a nested oneOf subschema (either defined inline or as $ref)

Any other patterns not listed in the following sections should also be considered unsupported.

oneOf with All Subschemas Defined as $ref

You can use a oneOf pattern in which all subschemas are defined as references ($ref). For this example, the pet schema can validate against either of two subschemas.

{
    "schemas": {
        "Pet": {
            "discriminator": {
                "propertyName": "pet_type",
                "mapping": {
                    "CAT": "#/components/schemas/Cat_Type",
                    "DOG": "#/components/schemas/Dog_Type"
                }
            },
            "oneOf": [
                {
                    "$ref": "#/components/schemas/Cat_Type"
                },
                {
                    "$ref": "#/components/schemas/Dog_Type"
                }
            ]
        },
        "Cat_Type": {
            "type": "object",
            "required": [
                "pet_type"
            ],
            "properties": {
                "hunts": {
                    "type": "boolean"
                },
                "pet_type": {
                    "type": "string"
                },
                "age": {
                    "type": "integer"
                }
            }
        },
        "Dog_Type": {
            "type": "object",
            "required": [
                "pet_type"
            ],
            "properties": {
                "bark": {
                    "type": "boolean"
                },
                "pet_type": {
                    "type": "string"
                },
                "breed": {
                    "type": "string",
                    "enum": [
                        "Dingo",
                        "Husky",
                        "Retriever",
                        "Shepherd"
                    ]
                }
            }
        }
    }
}

oneOf with All Subschemas Defined as Inline

You can use a oneOf pattern in which all subschemas are defined inline. For this example, the Pet schema can validate against either of two subschemas.

Note:

This pattern is only supported for outgoing messages from Oracle Integration (that is, either an invoke connection request or a trigger connection response back to a client).
{
    "schemas": {
        "Pet": {
            "discriminator": {
                "propertyName": "pet_type"
            },
            "oneOf": [
                {
                    "properties": {
                        "age": {
                            "type": "integer"
                        },
                        "hunts": {
                            "type": "boolean"
                        },
                        "pet_type": {
                            "type": "string"
                        }
                    },
                    "required": [
                        "pet_type"
                    ],
                    "type": "object"
                },
                {
                    "properties": {
                        "bark": {
                            "type": "boolean"
                        },
                        "breed": {
                            "enum": [
                                "Dingo",
                                "Husky",
                                "Retriever",
                                "Shepherd"
                            ],
                            "type": "string"
                        },
                        "pet_type": {
                            "type": "string"
                        }
                    },
                    "required": [
                        "pet_type"
                    ],
                    "type": "object"
                }
            ]
        }
    }
}

oneOf with a Mix of Inline and $ref Subschemas

Note:

  • discriminator mapping is mandatory in this pattern for all subschemas defined as $ref.
  • If more than one subschema is defined as inline, this pattern is only supported for outgoing messages from Oracle Integration (that is, either an invoke connection request or a trigger response back to the client).

You can use a oneOf pattern in which the subschemas are defined both as references ($ref) and inline. For this example, there is one subschema defined as a reference and one subschema defined inline.

{
    "schemas": {
        "Pet": {
            "discriminator": {
                "propertyName": "pet_type",
                "mapping": {
                    "CAT": "#/components/schemas/Cat_Type"
                }
            },
            "oneOf": [
                {
                    "$ref": "#/components/schemas/Cat_Type"
                },
                {
                    "type": "object",
                    "required": [
                        "pet_type"
                    ],
                    "properties": {
                        "bark": {
                            "type": "boolean"
                        },
                        "pet_type": {
                            "type": "string"
                        },
                        "breed": {
                            "type": "string",
                            "enum": [
                                "Dingo",
                                "Husky",
                                "Retriever",
                                "Shepherd"
                            ]
                        }
                    }
                }
            ]
        },
        "Cat_Type": {
            "type": "object",
            "required": [
                "pet_type"
            ],
            "properties": {
                "hunts": {
                    "type": "boolean"
                },
                "pet_type": {
                    "type": "string"
                },
                "age": {
                    "type": "integer"
                }
            }
        }
    }
}

oneOf with a Subschema Containing Multiple Mappings

You can use a oneOf pattern in which a subschema contains multiple mappings.
{
    "schemas": {
        "Pet": {
            "discriminator": {
                "propertyName": "pet_type",
                "mapping": {
                    "CAT": "#/components/schemas/Cat_Type",
                    "DOG": "#/components/schemas/Dog_Type",
                    "PUP": "#/components/schemas/Dog_Type"
                }
            },
            "oneOf": [
                {
                    "$ref": "#/components/schemas/Cat_Type"
                },
                {
                    "$ref": "#/components/schemas/Dog_Type"
                }
            ]
        },
        "Cat_Type": {
            "type": "object",
            "required": [
                "pet_type"
            ],
            "properties": {
                "hunts": {
                    "type": "boolean"
                },
                "pet_type": {
                    "type": "string"
                },
                "age": {
                    "type": "integer"
                }
            }
        },
        "Dog_Type": {
            "type": "object",
            "required": [
                "pet_type"
            ],
            "properties": {
                "bark": {
                    "type": "boolean"
                },
                "pet_type": {
                    "type": "string"
                },
                "breed": {
                    "type": "string",
                    "enum": [
                        "Dingo",
                        "Husky",
                        "Retriever",
                        "Shepherd"
                    ]
                }
            }
        }
    }
}

oneOf Defined as Items of an Array Type

You can use a oneOf pattern defined as items of an array type.
{
    "components": {
        "schemas": {
            "ItemRootIccPrivateVO-item-patch-request": {
                "properties": {
                    "Pets": {
                        "description": "The items in the collection.",
                        "items": {
                            "discriminator": {
                                "propertyName": "pet_type",
                                "mapping": {
                                    "CAT": "#/components/schemas/Cat_Type",
                                    "DOG": "#/components/schemas/Dog_Type"
                                }
                            },
                            "oneOf": [
                                {
                                    "$ref": "#/components/schemas/Cat_Type"
                                },
                                {
                                    "$ref": "#/components/schemas/Dog_Type"
                                }
                            ]
                        }
                    },
                    "title": "Pets",
                    "type": "array",
                    "x-cardinality": "1"
                }
            },
            "type": "object"
        }
    }
}

oneOf with a Nested allOf Subschema Defined as $ref

You can use a oneOf pattern in which allOf is nested and defined as a reference ($ref).

{
    "schemas": {
        "Animal": {
            "discriminator": {
                "propertyName": "pet_type",
                "mapping": {
                    "CAT": "#/components/schemas/CatPet",
                    "DOG": "#/components/schemas/DogPet"
                }
            },
            "oneOf": [
                {
                    "$ref": "#/components/schemas/CatPet"
                },
                {
                    "$ref": "#/components/schemas/DogPet"
                }
            ]
        },
        "CatPet": {
            "allOf": [
                {
                    "$ref": "#/components/schemas/Pet"
                },
                {
                    "$ref": "#/components/schemas/Cat"
                }
            ]
        },
        "DogPet": {
            "allOf": [
                {
                    "$ref": "#/components/schemas/Pet"
                },
                {
                    "$ref": "#/components/schemas/Dog"
                }
            ]
        },
        "Pet": {
            "type": "object",
            "required": [
                "pet_type"
            ],
            "properties": {
                "pet_type": {
                    "type": "string"
                }
            }
        },
        "Dog": {
            "type": "object",
            "properties": {
                "bark": {
                    "type": "boolean"
                },
                "breed": {
                    "type": "string",
                    "enum": [
                        "Dingo",
                        "Husky",
                        "Retriever",
                        "Shepherd"
                    ]
                }
            }
        },
        "Cat": {
            "type": "object",
            "properties": {
                "hunts": {
                    "type": "boolean"
                },
                "age": {
                    "type": "integer"
                }
            }
        }
    }
}

oneOf with a Nested allOf Subschema Defined Inline

You can use a oneOf pattern in which the allOf is nested and defined inline.

{
    "schemas": {
        "Animal": {
            "discriminator": {
                "propertyName": "pet_type",
                "mapping": {
                    "DOG": "#/components/schemas/DogPet"
                }
            },
            "oneOf": [
                {
                    "allOf": [
                        {
                            "$ref": "#/components/schemas/Pet"
                        },
                        {
                            "$ref": "#/components/schemas/Cat"
                        }
                    ]
                },
                {
                    "$ref": "#/components/schemas/DogPet"
                }
            ]
        },
        "DogPet": {
            "allOf": [
                {
                    "$ref": "#/components/schemas/Pet"
                },
                {
                    "$ref": "#/components/schemas/Dog"
                }
            ]
        },
        "Pet": {
            "type": "object",
            "required": [
                "pet_type"
            ],
            "properties": {
                "pet_type": {
                    "type": "string"
                }
            }
        },
        "Dog": {
            "type": "object",
            "properties": {
                "bark": {
                    "type": "boolean"
                },
                "breed": {
                    "type": "string",
                    "enum": [
                        "Dingo",
                        "Husky",
                        "Retriever",
                        "Shepherd"
                    ]
                }
            }
        },
        "Cat": {
            "type": "object",
            "properties": {
                "hunts": {
                    "type": "boolean"
                },
                "age": {
                    "type": "integer"
                }
            }
        }
    }
}

oneOf with a Nested anyOf Subschema Defined as $ref

You can use a oneOf pattern in which a nested anyOf subschema is defined as a reference ($ref).
{
    "schemas": {
        "Animal": {
            "discriminator": {
                "propertyName": "pet_type",
                "mapping": {
                    "CAT": "#/components/schemas/CatPet",
                    "DOG": "#/components/schemas/DogPet"
                }
            },
            "oneOf": [
                {
                    "$ref": "#/components/schemas/CatPet"
                },
                {
                    "$ref": "#/components/schemas/DogPet"
                }
            ]
        },
        "CatPet": {
            "anyOf": [
                {
                    "$ref": "#/components/schemas/Pet"
                },
                {
                    "$ref": "#/components/schemas/Cat"
                }
            ]
        },
        "DogPet": {
            "anyOf": [
                {
                    "$ref": "#/components/schemas/Pet"
                },
                {
                    "$ref": "#/components/schemas/Dog"
                }
            ]
        },
        "Pet": {
            "type": "object",
            "required": [
                "pet_type"
            ],
            "properties": {
                "pet_type": {
                    "type": "string"
                }
            }
        },
        "Dog": {
            "type": "object",
            "properties": {
                "bark": {
                    "type": "boolean"
                },
                "breed": {
                    "type": "string",
                    "enum": [
                        "Dingo",
                        "Husky",
                        "Retriever",
                        "Shepherd"
                    ]
                }
            }
        },
        "Cat": {
            "type": "object",
            "properties": {
                "hunts": {
                    "type": "boolean"
                },
                "age": {
                    "type": "integer"
                }
            }
        }
    }
}

oneOf with a Nested anyOf Subschema Defined Inline

You can use a oneOf pattern in which a nested anyof subschema is defined inline.
	
 Collapse source
{
    "schemas": {
        "Animal": {
            "discriminator": {
                "propertyName": "pet_type",
                "mapping": {
                    "DOG": "#/components/schemas/DogPet"
                }
            },
            "oneOf": [
                {
                    "anyOf": [
                        {
                            "$ref": "#/components/schemas/Pet"
                        },
                        {
                            "$ref": "#/components/schemas/Cat"
                        }
                    ]
                },
                {
                    "$ref": "#/components/schemas/DogPet"
                }
            ]
        },
        "DogPet": {
            "allOf": [
                {
                    "$ref": "#/components/schemas/Pet"
                },
                {
                    "$ref": "#/components/schemas/Dog"
                }
            ]
        },
        "Pet": {
            "type": "object",
            "required": [
                "pet_type"
            ],
            "properties": {
                "pet_type": {
                    "type": "string"
                }
            }
        },
        "Dog": {
            "type": "object",
            "properties": {
                "bark": {
                    "type": "boolean"
                },
                "breed": {
                    "type": "string",
                    "enum": [
                        "Dingo",
                        "Husky",
                        "Retriever",
                        "Shepherd"
                    ]
                }
            }
        },
        "Cat": {
            "type": "object",
            "properties": {
                "hunts": {
                    "type": "boolean"
                },
                "age": {
                    "type": "integer"
                }
            }
        }
    }
}