jsonschema: pre-compile regexps

This is the first CL that deals with the process of preparing a schema for validation.

Perform some basic checks on the scheme. Along the way, compile regexps and store
them in the schema for use during validation.

Change-Id: I0e5e6ce28656dcecb6d2d4b2fdc98998fa05b6f1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/669696
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Jonathan Amsterdam 2025-04-26 09:10:49 -04:00
commit 3d33fafc5d

View file

@ -13,6 +13,7 @@ import (
"fmt"
"iter"
"math"
"regexp"
)
// A Schema is a JSON schema object.
@ -106,6 +107,10 @@ type Schema struct {
Then *Schema `json:"then,omitempty"`
Else *Schema `json:"else,omitempty"`
DependentSchemas map[string]*Schema `json:"dependentSchemas,omitempty"`
// computed fields
pattern *regexp.Regexp
patternProperties map[*regexp.Regexp]*Schema
}
// String returns a short description of the schema.