jsonschema

package
v0.2.64 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: MIT Imports: 6 Imported by: 8

Documentation

Overview

Package jsonschema implements request validator with github.com/santhosh-tekuri/jsonschema/v2.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

type Factory struct {
	// JSONMarshal controls custom marshaler, nil value enables "encoding/json".
	JSONMarshal func(interface{}) ([]byte, error)
	// contains filtered or unexported fields
}

Factory makes JSON Schema request validators.

Please use NewFactory to create an instance.

func NewFactory

func NewFactory(
	requestSchemas rest.RequestJSONSchemaProvider,
	responseSchemas rest.ResponseJSONSchemaProvider,
) Factory

NewFactory creates new validator factory.

func (Factory) MakeRequestValidator

func (f Factory) MakeRequestValidator(
	method string,
	input interface{},
	mapping rest.RequestMapping,
) rest.Validator

MakeRequestValidator creates request validator for HTTP method and input structure.

func (Factory) MakeResponseValidator

func (f Factory) MakeResponseValidator(
	statusCode int,
	contentType string,
	output interface{},
	headerMapping map[string]string,
) rest.Validator

MakeResponseValidator creates response validator.

Header mapping is a map of struct field name to header name.

type Validator

type Validator struct {
	// JSONMarshal controls custom marshaler, nil value enables "encoding/json".
	JSONMarshal func(interface{}) ([]byte, error)
	// contains filtered or unexported fields
}

Validator is a JSON Schema based validator.

func (*Validator) AddSchema

func (v *Validator) AddSchema(in rest.ParamIn, name string, jsonSchema []byte, required bool) error

AddSchema registers schema for validation.

func (*Validator) ForbidUnknownParams added in v0.2.26

func (v *Validator) ForbidUnknownParams(in rest.ParamIn, forbidden bool)

ForbidUnknownParams configures if unknown parameters should be forbidden.

func (*Validator) HasConstraints added in v0.1.3

func (v *Validator) HasConstraints(in rest.ParamIn) bool

HasConstraints indicates if there are validation rules for parameter location.

func (*Validator) ValidateData

func (v *Validator) ValidateData(in rest.ParamIn, namedData map[string]interface{}) error

ValidateData performs validation of a mapped request data.

func (*Validator) ValidateJSONBody

func (v *Validator) ValidateJSONBody(jsonBody []byte) error

ValidateJSONBody performs validation of JSON body.

Jump to

Keyboard shortcuts

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