Documentation
¶
Overview ¶
Package jschema provides JSON Schema loading, parsing, and traversal utilities.
Index ¶
- func ExtractKeyOrder(s *jsonschema.Schema) (map[string][]string, error)
- func ExtractKeyOrderFromJSON(data []byte) (map[string][]string, error)
- func ExtractKeyOrderFromYAML(data []byte) (map[string][]string, error)
- func ExtractYAMLNodeKeyOrder(node *yaml.Node, path string, result map[string][]string)
- func IsFileRef(ref string) bool
- func RewriteRefs(schema *jsonschema.Schema)
- func SetPropertyOrder(schema *jsonschema.Schema, keyOrder map[string][]string)
- func Traverse(schema *jsonschema.Schema, resolver RefResolver) iter.Seq[*jsonschema.Schema]
- func TraverseDefs(schema *jsonschema.Schema) iter.Seq2[string, *jsonschema.Schema]
- type Loader
- type RefResolver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractKeyOrder ¶
func ExtractKeyOrder(s *jsonschema.Schema) (map[string][]string, error)
ExtractKeyOrder parses raw JSON and extracts the order of keys for all "properties" objects.
func ExtractKeyOrderFromJSON ¶ added in v0.2.1
ExtractKeyOrderFromJSON extracts the order of keys for all "properties" objects directly from raw JSON bytes, preserving the original file order.
func ExtractKeyOrderFromYAML ¶ added in v0.2.1
ExtractKeyOrderFromYAML extracts the order of keys for all "properties" objects from raw YAML bytes, using yaml.Node which preserves insertion order.
func ExtractYAMLNodeKeyOrder ¶ added in v0.2.1
ExtractYAMLNodeKeyOrder recursively extracts key ordering from a yaml.Node tree. It collects the ordered keys for all mapping nodes whose path ends with "properties".
func IsFileRef ¶
IsFileRef returns true if ref is an external file reference. File refs do not start with "#/".
func RewriteRefs ¶
func RewriteRefs(schema *jsonschema.Schema)
RewriteRefs rewrites all $ref attributes to use #/$defs/Name format. It handles both #/components/schemas/Name and #/definitions/Name refs.
func SetPropertyOrder ¶ added in v0.2.1
func SetPropertyOrder(schema *jsonschema.Schema, keyOrder map[string][]string)
SetPropertyOrder walks the schema tree and sets PropertyOrder on each node that has properties, using the key order extracted from raw bytes.
func Traverse ¶
func Traverse(schema *jsonschema.Schema, resolver RefResolver) iter.Seq[*jsonschema.Schema]
Traverse returns an iterator over all schemas in the tree. It handles cycles by tracking visited schemas. If resolver is provided, it follows $ref links to their targets.
func TraverseDefs ¶
func TraverseDefs(schema *jsonschema.Schema) iter.Seq2[string, *jsonschema.Schema]
TraverseDefs returns an iterator over $defs in topological order. Dependencies are yielded before the schemas that reference them. Each iteration yields (name, schema) pairs.
Types ¶
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader loads schemas from a filesystem.
func (*Loader) LoadFile ¶
func (l *Loader) LoadFile(filePath string) (*jsonschema.Schema, error)
LoadFile loads and parses a schema file. The format is determined from the file extension.
func (*Loader) ResolveRefs ¶
func (l *Loader) ResolveRefs(schema *jsonschema.Schema, basePath string) error
ResolveRefs resolves all external file $refs in the schema tree in-place. It recursively loads referenced schemas and replaces the ref with the loaded content. Internal refs (starting with #/) are left unchanged.
type RefResolver ¶
type RefResolver func(ref string) *jsonschema.Schema
RefResolver resolves $ref strings to schemas. Return nil if the ref cannot be resolved.