jsonschema

package
v0.380.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AnyTypes = []string{"string", "object", "array", "integer", "number", "boolean", "null"}
)

Functions

func ErrorsToString

func ErrorsToString(errs []gojsonschema.ResultError) (ret string)

func ValidateRequest

func ValidateRequest(ctx context.Context, schema *proto.Schema, action *proto.Action, input any) (*gojsonschema.Result, error)

ValidateRequest validates that the input is valid for the given action and schema. If validation errors are found they will be contained in the returned result. If an error is returned then validation could not be completed, likely to do an invalid JSON schema being created.

Types

type Components

type Components struct {
	Schemas map[string]JSONSchema `json:"schemas"`
}

type JSONSchema

type JSONSchema struct {
	// Type is generally just a string, but when we need a type to be
	// null it is a list containing the type and the string "null".
	// In JSON output for most cases we just want a string, not a list
	// of one string, so we use any here so it can be either
	Type any `json:"type,omitempty"`

	// New in draft 6
	// Const is used to restrict a value to a single value.
	// https://json-schema.org/understanding-json-schema/reference/const
	Const any `json:"const,omitempty"`

	// The enum field needs to be able to contains strings and null,
	// so we use *string here
	Enum []*string `json:"enum,omitempty"`

	// Validation for strings
	Format string `json:"format,omitempty"`

	// Validation for objects
	Properties            map[string]JSONSchema `json:"properties,omitempty"`
	AdditionalProperties  *bool                 `json:"additionalProperties,omitempty"`
	UnevaluatedProperties *bool                 `json:"unevaluatedProperties,omitempty"`
	Required              []string              `json:"required,omitempty"`
	OneOf                 []JSONSchema          `json:"oneOf,omitempty"`
	AnyOf                 []JSONSchema          `json:"anyOf,omitempty"`
	Title                 string                `json:"title,omitempty"`

	// For arrays
	Items *JSONSchema `json:"items,omitempty"`

	// Used to link to a type defined in the root $defs
	Ref string `json:"$ref,omitempty"`

	// Only used in the root JSONSchema object to define types that
	// can then be referenced using $ref
	Components *Components `json:"components,omitempty"`
}

func JSONSchemaForActionInput

func JSONSchemaForActionInput(ctx context.Context, schema *proto.Schema, action *proto.Action) JSONSchema

func JSONSchemaForActionResponse

func JSONSchemaForActionResponse(ctx context.Context, schema *proto.Schema, action *proto.Action) JSONSchema

func JSONSchemaForMessage

func JSONSchemaForMessage(ctx context.Context, schema *proto.Schema, action *proto.Action, message *proto.Message) JSONSchema

Generates JSONSchema for an operation by generating properties for the root input message. Any subsequent nested messages are referenced.

func ValidateResponse

func ValidateResponse(ctx context.Context, schema *proto.Schema, action *proto.Action, response any) (JSONSchema, *gojsonschema.Result, error)

type RelaxedDateFormatChecker added in v0.369.1

type RelaxedDateFormatChecker struct{}

func (RelaxedDateFormatChecker) IsFormat added in v0.369.1

func (f RelaxedDateFormatChecker) IsFormat(input interface{}) bool

Checks that the value matches the a ISO8601 except the date component is mandatory

Jump to

Keyboard shortcuts

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