-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
encoding/jsonschema: schema version support
This adds some logic for understanding JSON schema versions which will be used to trigger version-specific behavior in subsequent CLs. Signed-off-by: Roger Peppe <[email protected]> Change-Id: I91c15cbe54454d4f22a88e5ad532bfa2d03ad6f1 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199315 Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
- Loading branch information
Showing
7 changed files
with
91 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package jsonschema | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
//go:generate go run golang.org/x/tools/cmd/stringer -type=schemaVersion -linecomment | ||
|
||
type schemaVersion int | ||
|
||
const ( | ||
versionUnknown schemaVersion = iota // unknown | ||
versionDraft04 // http://json-schema.org/draft-04/schema# | ||
versionDraft05 // http://json-schema.org/draft-05/schema# | ||
versionDraft06 // http://json-schema.org/draft-06/schema# | ||
versionDraft07 // http://json-schema.org/draft-07/schema# | ||
version2019_09 // https://json-schema.org/draft/2019-09/schema | ||
version2020_12 // https://json-schema.org/draft/2020-12/schema | ||
|
||
numVersions // unknown | ||
) | ||
|
||
func parseSchemaVersion(sv string) (schemaVersion, error) { | ||
// If this linear search is ever a performance issue, we could | ||
// build a map, but it doesn't seem worthwhile for now. | ||
for i := schemaVersion(1); i < numVersions; i++ { | ||
if sv == i.String() { | ||
return i, nil | ||
} | ||
} | ||
return 0, fmt.Errorf("$schema URI not recognized") | ||
} |