Documentation
¶
Overview ¶
Package jsonschema loads and compares authored Draft 2020-12 schema resources.
Draft 2020-12 is the only supported dialect. A $dynamicRef that needs dynamic scope resolution is an error. YAML input must be JSON-compatible, so anchors, aliases and non-string keys are errors too.
Index ¶
Constants ¶
const Dialect = "https://json-schema.org/draft/2020-12/schema"
Dialect is the supported JSON Schema dialect.
Variables ¶
var ErrNotSchema = errors.New("expected a Draft 2020-12 JSON Schema declaration")
ErrNotSchema identifies an input without a supported standalone schema declaration.
Functions ¶
func Compare ¶
func Compare(left, right *Document, rules *wc.BreakingRulesConfig) (*wc.SchemaChanges, error)
Compare uses the schema comparator on authored constraints. Each referenced resource is compared once, independent of the number of references to it.
rules holds explicit overrides only. Each rule it contains replaces the verdict for that keyword in both directions, so merged defaults such as GenerateDefaultBreakingRules would mark a widening edit as breaking. Pass nil for the direction-aware defaults. A root replaced by a boolean, or the reverse, has no keyword and no override.
func MatchResources ¶
MatchResources pairs the original and modified resources by resolved ID, then by source path and embedded pointer. A comparison of two single schemas always pairs their roots. Unmatched resources have no entry in the returned map.
func PropertyPath ¶
PropertyPath appends an object key to a JSONPath without changing its identity.
Types ¶
type Document ¶
type Document struct {
Root *Resource
Resources []*Resource
Sources map[string]*Source
References []Reference
Rolodex *index.Rolodex
// contains filtered or unexported fields
}
Document owns the resources and source locations for a comparison input.
func Load ¶
func Load(data []byte, source string, config *datamodel.DocumentConfiguration, explicit bool) (*Document, error)
Load reads one root and all its referenced resources using the supplied source configuration. Explicit mode accepts unmarked object and boolean schemas.
func LoadCollection ¶
func LoadCollection(members map[string][]byte, directory string, config *datamodel.DocumentConfiguration) (*Document, error)
LoadCollection registers all named schema sources before resolving references. Names are slash-separated paths relative to directory. An empty snapshot is valid. The returned document has a nil Root and one entry in Sources per physical file.
type MemberError ¶
MemberError identifies the collection member that failed to load. Its text is the member's own diagnostic, which already names the file.
func (*MemberError) Error ¶
func (e *MemberError) Error() string
func (*MemberError) Unwrap ¶
func (e *MemberError) Unwrap() error
type Reference ¶
type Reference struct {
From, To *yaml.Node
Value string
// Keyword identifies the authored $ref or $dynamicRef.
Keyword string
// contains filtered or unexported fields
}
Reference connects an authored reference site to a schema in this snapshot.