JSONSchema.anyOf constructor
JSONSchema.anyOf({
- required List<
JSONSchema> schemas,
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.
JSONSchema.anyOf(anyOf: [
.JSONSchema.integer(description: "User ID"),
.JSONSchema.object(properties: [
"userId": JSONSchema.integer(),
"userName": JSONSchema.string()
], description: "Detailed User Object")
])
The generated data could be decoded based on which schema it matches.
Implementation
JSONSchema.anyOf({
required List<JSONSchema> schemas,
}) : this(
SchemaType.anyOf, // The type will be ignored in toJson
anyOf: schemas,
);