package jsonschema
type CompilerContext struct {
c *objCompiler
}
func (ctx *CompilerContext ) Enqueue (schPath []string ) *Schema {
ptr := ctx .c .up .ptr
for _ , tok := range schPath {
ptr = ptr .append (tok )
}
return ctx .c .enqueuePtr (ptr )
}
func (ctx *CompilerContext ) EnqueueRef (ref string ) (*Schema , error ) {
return ctx .c .enqueueRefVal (ref )
}
type Vocabulary struct {
URL string
Schema *Schema
Subschemas []SchemaPath
Compile func (ctx *CompilerContext , obj map [string ]any ) (SchemaExt , error )
}
type SchemaExt interface {
Validate (ctx *ValidatorContext , v any )
}
type ValidatorContext struct {
vd *validator
}
func (ctx *ValidatorContext ) ValueLocation () []string {
return ctx .vd .vloc
}
func (ctx *ValidatorContext ) Validate (sch *Schema , v any , vpath []string ) error {
switch len (vpath ) {
case 0 :
return ctx .vd .validateSelf (sch , "" , false )
case 1 :
return ctx .vd .validateVal (sch , v , vpath [0 ])
default :
return ctx .vd .validateValue (sch , v , vpath )
}
}
func (ctx *ValidatorContext ) EvaluatedProp (pname string ) {
delete (ctx .vd .uneval .props , pname )
}
func (ctx *ValidatorContext ) EvaluatedItem (index int ) {
delete (ctx .vd .uneval .items , index )
}
func (ctx *ValidatorContext ) AddError (k ErrorKind ) {
ctx .vd .addError (k )
}
func (ctx *ValidatorContext ) AddErrors (errors []*ValidationError , k ErrorKind ) {
ctx .vd .addErrors (errors , k )
}
func (ctx *ValidatorContext ) AddErr (err error ) {
ctx .vd .addErr (err )
}
func (ctx *ValidatorContext ) Equals (v1 , v2 any ) (bool , error ) {
b , k := equals (v1 , v2 )
if k != nil {
return false , ctx .vd .error (k )
}
return b , nil
}
func (ctx *ValidatorContext ) Duplicates (arr []any ) (int , int , error ) {
i , j , k := duplicates (arr )
if k != nil {
return -1 , -1 , ctx .vd .error (k )
}
return i , j , nil
}
The pages are generated with Golds v0.8.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .