Schema extension type

A JSON Schema object defining any kind of property.

See https://json-schema.org/draft/2020-12/json-schema-core.html for the full specification.

Note: Only a subset of the json schema spec is supported by these types, if you need something more complex you can create your own Map<String, Object?> and cast it to Schema (or a subtype) directly.

on

Constructors

Schema.any({String? title, String? description})
Creates a JSON schema definition for any value.
factory
Schema.boolean({String? title, String? description})
Creates a JSON Schema definition for a bool.
factory
Schema.combined({Object? type, List<Object?>? enumValues, Object? constValue, String? title, String? description, String? $comment, Object? defaultValue, List<Object?>? examples, bool? deprecated, bool? readOnly, bool? writeOnly, Map<String, Schema>? $defs, String? $ref, String? $anchor, String? $dynamicAnchor, String? $id, String? $schema, List<Object?>? allOf, List<Object?>? anyOf, List<Object?>? oneOf, Object? not, Object? ifSchema, Object? thenSchema, Object? elseSchema, Map<String, Schema>? dependentSchemas})
Creates a combined schema.
factory
Schema.fromBoolean(bool value, {List<String> jsonPath = const []})
Creates a schema from a boolean value.
factory
Schema.fromMap(Map<String, Object?> _value)
Schema.integer({String? title, String? description, int? minimum, int? maximum, int? exclusiveMinimum, int? exclusiveMaximum, num? multipleOf})
Creates a JSON Schema definition for an int.
factory
Schema.list({String? title, String? description, Schema? items, List<Schema>? prefixItems, Object? unevaluatedItems, Schema? contains, int? minContains, int? maxContains, int? minItems, int? maxItems, bool? uniqueItems})
Creates a JSON Schema definition for a List.
factory
Schema.nil({String? title, String? description})
Creates a JSON Schema definition for null.
factory
Schema.number({String? title, String? description, num? minimum, num? maximum, num? exclusiveMinimum, num? exclusiveMaximum, num? multipleOf})
Creates a JSON Schema definition for a num.
factory
Schema.object({String? title, String? description, Map<String, Schema>? properties, Map<String, Schema>? patternProperties, List<String>? required, Map<String, List<String>>? dependentRequired, Object? additionalProperties, Object? unevaluatedProperties, Schema? propertyNames, int? minProperties, int? maxProperties})
Creates a JSON Schema definition for an object with properties.
factory
Schema.string({String? title, String? description, List<Object?>? enumValues, Object? constValue, int? minLength, int? maxLength, String? pattern, String? format})
Creates a JSON Schema definition for a String.
factory

Properties

$anchor String?
An anchor for this schema.
no setter
$comment String?
A comment for the schema.
no setter
$defs Map<String, Schema>?
A map of re-usable schemas.
no setter
$dynamicAnchor String?
A dynamic anchor for this schema.
no setter
$dynamicRef String?
A dynamic reference to another schema.
no setter
$id String?
The ID of the schema.
no setter
$ref String?
A reference to another schema.
no setter
$schema String?
The meta-schema for this schema.
no setter
allOf List<Object?>?
The instance must be valid against all of these schemas.
no setter
anyOf List<Object?>?
The instance must be valid against at least one of these schemas.
no setter
constValue Object?
A constant value that the instance must be equal to.
no setter
defaultValue Object?
The default value for the instance.
no setter
dependentSchemas Map<String, Schema>?
A map where the keys are property names, and the values are schemas that must be valid for the object if the key is present.
no setter
deprecated bool?
Indicates whether the instance is deprecated.
no setter
description String?
A detailed description of the schema.
no setter
elseSchema Object?
The schema that the instance must be valid against if it is not valid against ifSchema.
no setter
enumValues List<Object?>?
A list of valid values for an instance.
no setter
examples List<Object?>?
A list of example values.
no setter
ifSchema Object?
If the instance is valid against this schema, then it must also be valid against thenSchema.
no setter
not Object?
The instance must not be valid against this schema.
no setter
oneOf List<Object?>?
The instance must be valid against exactly one of these schemas.
no setter
readOnly bool?
Indicates whether the instance is read-only.
no setter
thenSchema Object?
The schema that the instance must be valid against if it is valid against ifSchema.
no setter
title String?
A descriptive title for the schema.
no setter
type Object?
The type of the data that this schema defines.
no setter
value Map<String, Object?>
The underlying map representation of the schema.
no setter
writeOnly bool?
Indicates whether the instance is write-only.
no setter

Methods

mapToSchemaOrBool(String key) Map<String, Schema>?
Retrieves a map of property names to schemas, handling boolean schemas.
schemaOrBool(String key) Schema?
Retrieves a subschema for a given keyword, handling boolean schemas.
toJson({String? indent}) String
Convert to JSON with optional indent depth.

Operators

operator [](String key) Object?
Gets the value of a keyword from the schema map.