Schema.anyOf constructor
Construct a schema representing a value that must conform to any (one or more) of the provided sub-schemas.
This schema instructs the model to produce data that is valid against at
least one of the schemas listed in the schemas array. This is useful
when a field can accept multiple distinct types or structures.
Example: A field that can hold either a simple user ID (integer) or a detailed user object.
Schema.anyOf(anyOf: [
.Schema.integer(description: "User ID"),
.Schema.object(properties: [
"userId": Schema.integer(),
"userName": Schema.string()
], description: "Detailed User Object")
])
The generated data could be decoded based on which schema it matches.
Implementation
Schema.anyOf({
required List<Schema> schemas,
}) : this(
SchemaType.anyOf, // The type will be ignored in toJson
anyOf: schemas,
);