cuelang.org/go@v0.10.1/encoding/jsonschema/version.go (about) 1 package jsonschema 2 3 import ( 4 "fmt" 5 ) 6 7 //go:generate go run golang.org/x/tools/cmd/stringer -type=schemaVersion -linecomment 8 9 type schemaVersion int 10 11 const ( 12 versionUnknown schemaVersion = iota // unknown 13 versionDraft04 // http://json-schema.org/draft-04/schema# 14 // Note: draft 05 never existed and should not be used. 15 versionDraft06 // http://json-schema.org/draft-06/schema# 16 versionDraft07 // http://json-schema.org/draft-07/schema# 17 version2019_09 // https://json-schema.org/draft/2019-09/schema 18 version2020_12 // https://json-schema.org/draft/2020-12/schema 19 20 numVersions // unknown 21 ) 22 23 func parseSchemaVersion(sv string) (schemaVersion, error) { 24 // If this linear search is ever a performance issue, we could 25 // build a map, but it doesn't seem worthwhile for now. 26 for i := schemaVersion(1); i < numVersions; i++ { 27 if sv == i.String() { 28 return i, nil 29 } 30 } 31 return 0, fmt.Errorf("$schema URI not recognized") 32 }