Documentation
¶
Overview ¶
Package jsonschema derives, parses, and validates JSON Schema contracts.
Example ¶
package main
import (
"fmt"
"github.com/Tangerg/scope/core/jsonschema"
)
func main() {
type answer struct {
Value int `json:"value"`
}
schema, err := jsonschema.For[answer]()
if err != nil {
panic(err)
}
fmt.Println(schema.Validate([]byte(`{"value":42}`)))
}
Output: <nil>
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrInvalid = errors.New("jsonschema: invalid schema")
Functions ¶
This section is empty.
Types ¶
type Modeler ¶
type Modeler interface {
// JSONSchemaModel returns a non-nil typed value whose encoding/json wire shape
// exactly matches the receiver's custom encoding. The concrete model type is
// part of the schema contract and must remain stable across calls.
JSONSchemaModel() any
}
Modeler is implemented by rich values whose encoding/json representation is described by a separate typed model. Implementations must return the same non-nil model type on every call.
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema is an immutable, compiled JSON Schema. Its zero value is invalid and successfully constructed values are safe for concurrent validation.
func For ¶
For derives and compiles the JSON Schema contract for T. It follows encoding/json field names and options and the invopop/jsonschema tag dialect. Structs reject additional properties by default.
func (Schema) JSON ¶
func (s Schema) JSON() json.RawMessage
func (Schema) MarshalJSON ¶
func (*Schema) UnmarshalJSON ¶
Click to show internal directories.
Click to hide internal directories.