Documentation ¶
Overview ¶
package schema implements a minimal JSON Schema library that parses the schema as YAML. The goal of this package is to be able to parse Apple's YAML MDM and Declarative Device Management Schema into a Go struct Abstract Syntax Tree
Index ¶
- Variables
- func GenerateFromFile(path, pkgName string, reps replace.Replacements) ([]byte, error)
- func GenerateFromGit(repoURL, commit, path, pkgName string, reps replace.Replacements) ([]byte, error)
- type EncodeOption
- type Encoder
- type IntegerNumber
- func (in *IntegerNumber) Float64() float64
- func (in *IntegerNumber) Int64() int64
- func (in *IntegerNumber) IsFloat64() bool
- func (in *IntegerNumber) IsInt64() bool
- func (in *IntegerNumber) MarshalYAML() ([]byte, error)
- func (in *IntegerNumber) UnmarshalYAML(data []byte) error
- func (in *IntegerNumber) Value() any
- type IntegerNumberString
- func (in *IntegerNumberString) Float64() float64
- func (in *IntegerNumberString) Int64() int64
- func (in *IntegerNumberString) IsFloat64() bool
- func (in *IntegerNumberString) IsInt64() bool
- func (in *IntegerNumberString) IsString() bool
- func (in *IntegerNumberString) MarshalYAML() ([]byte, error)
- func (in *IntegerNumberString) String() string
- func (in *IntegerNumberString) UnmarshalYAML(data []byte) error
- func (in *IntegerNumberString) Value() any
- type OrderedMap
- type Schema
- type Type
- type TypeSlice
Constants ¶
This section is empty.
Variables ¶
var ErrUnexpectedBool = errors.New("unexpected boolean")
Functions ¶
func GenerateFromFile ¶
func GenerateFromFile(path, pkgName string, reps replace.Replacements) ([]byte, error)
GenerateFromFile generates Go types from the schema at path using the given pkgName and optional replacements
func GenerateFromGit ¶
func GenerateFromGit(repoURL, commit, path, pkgName string, reps replace.Replacements) ([]byte, error)
GenerateFromGit generates Go types from the schema at the git repo/commit/path using the given pkgName and optional replacements
Types ¶
type EncodeOption ¶
type EncodeOption func(*Encoder)
EncodeOption allows configuring an Encoder
func WithReplacements ¶
func WithReplacements(reps replace.Replacements) EncodeOption
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder encodes Schemas to Go types
func NewEncoder ¶
func NewEncoder(f *jen.File, opts ...EncodeOption) *Encoder
type IntegerNumber ¶
type IntegerNumber struct {
// contains filtered or unexported fields
}
IntegerNumber holds either an int64 or a float64
func NewIntegerNumber ¶
func NewIntegerNumber[T int64 | float64](v T) *IntegerNumber
func (*IntegerNumber) Float64 ¶
func (in *IntegerNumber) Float64() float64
Float64 returns the underlying float64. Float64 will panic if the underlying type is not float64
func (*IntegerNumber) Int64 ¶
func (in *IntegerNumber) Int64() int64
Int64 returns the underlying int64. Int64 will panic if the underlying type is not int64
func (*IntegerNumber) IsFloat64 ¶
func (in *IntegerNumber) IsFloat64() bool
func (*IntegerNumber) IsInt64 ¶
func (in *IntegerNumber) IsInt64() bool
func (*IntegerNumber) MarshalYAML ¶
func (in *IntegerNumber) MarshalYAML() ([]byte, error)
func (*IntegerNumber) UnmarshalYAML ¶
func (in *IntegerNumber) UnmarshalYAML(data []byte) error
func (*IntegerNumber) Value ¶
func (in *IntegerNumber) Value() any
type IntegerNumberString ¶
type IntegerNumberString struct {
// contains filtered or unexported fields
}
IntegerNumberString holds an int64, float64, or a string
func NewIntegerNumberString ¶
func NewIntegerNumberString[T int64 | float64 | string](v T) *IntegerNumberString
func (*IntegerNumberString) Float64 ¶
func (in *IntegerNumberString) Float64() float64
Float64 returns the underlying float64. Float64 will panic if the underlying type is not float64
func (*IntegerNumberString) Int64 ¶
func (in *IntegerNumberString) Int64() int64
Int64 returns the underlying int64. Int64 will panic if the underlying type is not int64
func (*IntegerNumberString) IsFloat64 ¶
func (in *IntegerNumberString) IsFloat64() bool
func (*IntegerNumberString) IsInt64 ¶
func (in *IntegerNumberString) IsInt64() bool
func (*IntegerNumberString) IsString ¶
func (in *IntegerNumberString) IsString() bool
func (*IntegerNumberString) MarshalYAML ¶
func (in *IntegerNumberString) MarshalYAML() ([]byte, error)
func (*IntegerNumberString) String ¶
func (in *IntegerNumberString) String() string
String returns the underlying string. String will panic if the underlying type is not string
func (*IntegerNumberString) UnmarshalYAML ¶
func (in *IntegerNumberString) UnmarshalYAML(data []byte) error
func (*IntegerNumberString) Value ¶
func (in *IntegerNumberString) Value() any
type OrderedMap ¶
OrderedMap is an ordered map[string]*Schema
func (*OrderedMap) Iter ¶
func (m *OrderedMap) Iter(f func(key string, schm *Schema))
Iter iterates through keys and values in order
func (*OrderedMap) UnmarshalYAML ¶
func (m *OrderedMap) UnmarshalYAML(f func(interface{}) error) error
type Schema ¶
type Schema struct { Title string `yaml:"title,omitempty"` Type TypeSlice `yaml:"type"` Description string `yaml:"description,omitempty"` AdditionalProperties bool `yaml:"additionalProperties,omitempty"` Required []string `yaml:"required,omitempty"` Properties *OrderedMap `yaml:"properties,omitempty"` Items *Schema `yaml:"items,omitempty"` Enum []string `yaml:"enum,omitempty"` Default any `yaml:"default,omitempty"` }
Schema represents a JSON Schema (encoded in YAML)
func NewFromFile ¶
NewFromFile parses the yaml schema at path