jschema

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2022 License: Apache-2.0 Imports: 18 Imported by: 2

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Enum

type Enum struct {
	// contains filtered or unexported fields
}

func EnumFromFile

func EnumFromFile(f *fs.File) Enum

func NewEnum

func NewEnum(name string, content []byte) Enum

func (Enum) Check

func (e Enum) Check() (err error)

type Option

type Option func(s *Schema)

func AllowTrailingNonSpaceCharacters

func AllowTrailingNonSpaceCharacters() Option

func KeysAreOptionalByDefault

func KeysAreOptionalByDefault() Option

type Schema

type Schema struct {
	// contains filtered or unexported fields
}
Example
s := New("root", []byte(`{"foo": @Fizz,"bar": @Buzz}`))

l, err := s.Len()
if err != nil {
	fmt.Printf("Error: %s\n", err)
	return
}
fmt.Println(l)

err = s.AddType("@Fizz", New("fizz", []byte(`{"fizz": 1}`)))
if err != nil {
	fmt.Printf("Error: %s\n", err)
	return
}

err = s.AddType("@Buzz", New("buzz", []byte(`{"buzz": 2}`)))
if err != nil {
	fmt.Printf("Error: %s\n", err)
	return
}

err = s.Check()
if err != nil {
	fmt.Printf("Error: %s\n", err)
	return
}

err = s.Validate(json.New("json", []byte(`{"foo":{"fizz":42},"bar":{"buzz":42}}`)))
if err != nil {
	fmt.Printf("Error: %s\n", err)
	return
}
Output:

27

func FromFile

func FromFile(f *fs.File, oo ...Option) *Schema

FromFile creates a Jsight schema from file.

func New

func New(name string, content []byte, oo ...Option) *Schema

New creates a Jsight schema with specified name and content.

func (*Schema) AddRule

func (*Schema) AddRule(string, jschema.Rule) error

func (*Schema) AddType

func (s *Schema) AddType(name string, sc jschema.Schema) (err error)

func (*Schema) Build

func (s *Schema) Build() error

func (*Schema) Check

func (s *Schema) Check() (err error)

func (*Schema) Example

func (s *Schema) Example() (b []byte, err error)

func (*Schema) GetAST

func (s *Schema) GetAST() (an jschema.ASTNode, err error)

func (*Schema) Len

func (s *Schema) Len() (uint, error)

func (*Schema) UsedUserTypes

func (s *Schema) UsedUserTypes() ([]string, error)

func (*Schema) Validate

func (s *Schema) Validate(document jschema.Document) (err error)

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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