schema

package
v0.0.0-...-0b08f29 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package schema implements JSON validation utilities

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Validator

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

Validator is a utility to validate JSON object against a given schema

func NewValidator

func NewValidator(schemas []string, refs []string) (*Validator, error)

NewValidator creates a new Validator using schemas for the top level JSON schemas and refs for refs that may be referenced in the top level schemas. Top level schemas cannot reference each others. If a reference is mentioned, it can only be in the list of refs

func NewValidatorFromFS

func NewValidatorFromFS(schemaFS embed.FS) (*Validator, error)

NewValidatorFromFS creates a new Validator using schemas from schemaFS. Json files from / will be used as toplevel schemas, while json files in /refs/ will be used as references

func (*Validator) HasSchema

func (v *Validator) HasSchema(schemaID string) bool

HasSchema returns true if schemaID is known

func (*Validator) ValidateString

func (v *Validator) ValidateString(json, schemaID string) error

ValidateString validates the given json against schemaID. If no error is returned, then the passed json is valid

func (*Validator) ValidateStruct

func (v *Validator) ValidateStruct(json interface{}, schemaID string) error

ValidateStruct validates the given json as a struct against schemaID. If no error is returned, then the passed json is valid

Jump to

Keyboard shortcuts

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