Open
Description
UPDATED on 2018-09-05. Originally this was a question between the difference of the schema.Object FieldValidator and the Schema paramter on Field, and it evolved from there.
Background
Today there are two ways to specify a schema:
s := schema.Schema{
Fields: schema.Fields{
"meta": {Schema: subSchema}
}
}
and
s := schema.Schema{
Fields: schema.Fields{
"meta": {Validator: schema.Object{Schema: subSchema}}
}
}
These are equivalent in principal, but in reality, the code supports them differently.
E.g. for validating and correctly setting e.g. read-only values, only the first method will work.
The second way of expressing this, the only one supported by the JSON-schmea encoding package, is the only syntax that allowed Schema validation within an Array, AnyOff, AllOf or other nested structure in the past.
Proposal
This ticket suggests a redesign of the schema package so that:
- Allow any
FieldValidator
to be used in a top-level schema (renamed to just schema.Validator in example). - Merge the
schema.Schema
andschema.Field
types into one - Fields is moved from schema to Object (and is now a map of Schemas)
- Move the
Required
Field attribute (does not make sense on all fields) to be a list-attribute on Object.
Example struct definitions:
type Object struct{
Fields map[string]Schema
Required []string
}
type Object struct{
Fields map[string]Schema
Required []string
}
type Schema struct{
Title string
Description string
ReadOnly bool
Type Validator
}
type Array struct{
KeysValidator Validator
Values Schema
}