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 ¶
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.