jsonSchemaValidatorGenerators top-level property
Registry for functions that can generate JSON Schema declarations.
This Map can handle all schemake validators. Custom validators can be added to it as needed, or changed by Zone as explained later.
The JSON Schema for the validator is written to the StringBuffer provided
to the function. The buffer will be writing inside the JSON object
containing the type
wrapped by the Validator.
For example, if the type is Validatable(Strings(), validator)
, the buffer
will have written { "type": "string"
when the function is called.
The generator function could write something like , "pattern": "[a-z]+"
,
resulting in the schema { "type": "string", "pattern": "[a-z]+" }
Notice that the JsonSchemaOptions argument will always have value false
for properties JsonSchemaOptions.startObject and JsonSchemaOptions.endObject
because the JSON object is started and ended by schemake.
Changing the generators only for a specific Zone
This registry can be modified globally by modifying this Map or,
if you prefer to avoid modifying global state, by setting the Zone key
jsonSchemaValidatorGeneratorsZoneKey
with a Map
with the same type as this value.
See runZoned for details on how to customize a Zone.
Implementation
final jsonSchemaValidatorGenerators = <Type, JsonSchemaWriterFunction>{
EnumValidator: generateEnum,
NonBlankStringValidator: generateNonBlankString,
IntRangeValidator: generateIntRange,
FloatRangeValidator: generateFloatRange,
};