jsonschema

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Overview

Package jsonschema converts JSON Schema documents into queryfy schemas.

This package supports a practical subset of JSON Schema (Draft 2020-12 / Draft 7 compatible) focused on the features that map cleanly to queryfy's validation model. Unsupported features produce clear errors rather than silent data loss.

Usage:

schema, errs := jsonschema.FromJSON(data, nil)
if len(errs) > 0 {
    // handle conversion errors
}
// schema is a queryfy.Schema ready for validation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToJSON

func ToJSON(schema queryfy.Schema, opts *ExportOptions) ([]byte, error)

ToJSON converts a queryfy schema to a JSON Schema document. Returns the JSON bytes and any errors encountered during conversion. A nil opts uses default settings.

func ToMap

func ToMap(schema queryfy.Schema, opts *ExportOptions) map[string]interface{}

ToMap converts a queryfy schema to a map representation of JSON Schema. Useful when you need to manipulate the output before serialising.

Types

type ConversionError

type ConversionError struct {
	// Path is the dot-separated location in the JSON Schema document
	// (e.g., "properties.address.properties.city").
	Path string

	// Keyword is the JSON Schema keyword that caused the error
	// (e.g., "$ref", "oneOf").
	Keyword string

	// Message describes the problem.
	Message string

	// IsWarning is true when the error is non-fatal (StrictMode=false
	// and the feature was skipped).
	IsWarning bool
}

ConversionError describes a single problem encountered during conversion.

func FromJSON

func FromJSON(data []byte, opts *Options) (queryfy.Schema, []ConversionError)

FromJSON parses a JSON Schema document and returns a queryfy schema. The second return value is a slice of conversion errors/warnings. A nil opts uses default settings (non-strict, no unknown storage).

func (*ConversionError) Error

func (e *ConversionError) Error() string

type ExportOptions

type ExportOptions struct {
	// SchemaURI sets the $schema keyword. Empty string omits it.
	SchemaURI string

	// ID sets the $id keyword. Empty string omits it.
	ID string

	// IncludeMeta includes stored metadata as extension keywords in the
	// output (e.g., "x-custom": "value").
	IncludeMeta bool
}

ExportOptions controls the export behaviour.

type Options

type Options struct {
	// StrictMode causes unsupported JSON Schema features to produce errors.
	// When false, unsupported features are skipped with a warning in the
	// returned error slice.
	StrictMode bool

	// StoreUnknown causes unrecognised keywords to be stored as schema
	// metadata via Meta(). This is useful for round-tripping or for
	// downstream consumers that need access to custom extensions.
	StoreUnknown bool
}

Options controls the conversion behaviour.

Jump to

Keyboard shortcuts

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