jschema

package
v0.1.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package jschema provides JSON Schema loading, parsing, and traversal utilities.

Index

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 IsFileRef

func IsFileRef(ref string) bool

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 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 NewLoader

func NewLoader(fsys fs.FS) *Loader

NewLoader creates a Loader that reads from the given 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL