Documentation
¶
Index ¶
- Variables
- func JSONFieldName(f reflect.StructField) string
- type ArrayBuilder
- type Builder
- func (b Builder) Build() Schema
- func (b Builder) Const(value string) Builder
- func (b Builder) Default(value any) Builder
- func (b Builder) Deprecated(value bool) Builder
- func (b Builder) Description(desc string) Builder
- func (b Builder) Enum(values ...any) Builder
- func (b Builder) Examples(values ...any) Builder
- func (b Builder) ReadOnly(value bool) Builder
- func (b Builder) Reference(ref string) Schema
- func (b Builder) Title(value string) Builder
- func (b Builder) Type(typs ...Type) Builder
- func (b Builder) WriteOnly(value bool) Builder
- type Format
- type NumberBuilder
- func (nb NumberBuilder) Build() Schema
- func (nb NumberBuilder) ExclusiveMaximum(n int) NumberBuilder
- func (nb NumberBuilder) ExclusiveMinimum(n int) NumberBuilder
- func (nb NumberBuilder) Maximum(n int) NumberBuilder
- func (nb NumberBuilder) Minimum(n int) NumberBuilder
- func (nb NumberBuilder) MultipleOf(n int) NumberBuilder
- type ObjectBuilder
- type Option
- type Schema
- type Schemer
- type StringBuilder
- func (s StringBuilder) Build() Schema
- func (s StringBuilder) Format(value Format) StringBuilder
- func (s StringBuilder) Length(n int) StringBuilder
- func (s StringBuilder) MaxLength(n int) StringBuilder
- func (s StringBuilder) MinLength(n int) StringBuilder
- func (s StringBuilder) Pattern(value string) StringBuilder
- type Type
- type ValidationError
- type Validator
Constants ¶
This section is empty.
Variables ¶
var ErrSchemaLoad = errors.New("remote schemas are not supported")
var ErrSchemaNotFound = errors.New("schema not found in validator")
var ErrUnknowType = errors.New("unable to create jsonschema for type")
Functions ¶
func JSONFieldName ¶
func JSONFieldName(f reflect.StructField) string
Types ¶
type ArrayBuilder ¶
ArrayBuilder provides functions for array related options on the schema.
func (ArrayBuilder) Build ¶
func (a ArrayBuilder) Build() Schema
func (ArrayBuilder) MaxContains ¶
func (a ArrayBuilder) MaxContains(n int) ArrayBuilder
func (ArrayBuilder) MaxItems ¶
func (a ArrayBuilder) MaxItems(n int) ArrayBuilder
func (ArrayBuilder) MinContains ¶
func (a ArrayBuilder) MinContains(n int) ArrayBuilder
func (ArrayBuilder) MinItems ¶
func (a ArrayBuilder) MinItems(n int) ArrayBuilder
func (ArrayBuilder) UniqueItems ¶
func (a ArrayBuilder) UniqueItems() ArrayBuilder
type Builder ¶
type Builder struct {
StringBuilder
NumberBuilder
ArrayBuilder
ObjectBuilder
Schema *openapi.Schema
}
Builder provides functions to build a json schema.
func (Builder) Deprecated ¶
func (Builder) Description ¶
type Format ¶
type Format string
const ( FormatInt32 Format = openapi.Int32Format FormatInt64 Format = openapi.Int64Format FormatFloat Format = openapi.FloatFormat FormatDouble Format = openapi.DoubleFormat FormatPassword Format = openapi.PasswordFormat FormatDateTime Format = openapi.DateTimeFormat FormatTime Format = openapi.TimeFormat FormatDate Format = openapi.DateFormat FormatDuration Format = openapi.DurationFormat FormatEmail Format = openapi.EmailFormat FormatIDNEmail Format = openapi.IDNEmailFormat FormatHostname Format = openapi.HostnameFormat FormatIDNHostname Format = openapi.IDNHostnameFormat FormatIPv4 Format = openapi.IPv4Format FormatIPv6 Format = openapi.IPv6Format FormatUUID Format = openapi.UUIDFormat FormatURI Format = openapi.URIFormat FormatURIReference Format = openapi.URIReferenceFormat FormatIRI Format = openapi.IRIFormat FormatIRIReference Format = openapi.IRIReferenceFormat FormatURITemplate Format = openapi.URITemplateFormat FormatJsonPointer Format = openapi.JsonPointerFormat FormatRelativeJsonPointer Format = openapi.RelativeJsonPointerFormat FormatRegex Format = openapi.RegexFormat )
type NumberBuilder ¶
NumberBuilder provides functions for number related options on the schema.
func (NumberBuilder) Build ¶
func (nb NumberBuilder) Build() Schema
func (NumberBuilder) ExclusiveMaximum ¶
func (nb NumberBuilder) ExclusiveMaximum(n int) NumberBuilder
func (NumberBuilder) ExclusiveMinimum ¶
func (nb NumberBuilder) ExclusiveMinimum(n int) NumberBuilder
func (NumberBuilder) Maximum ¶
func (nb NumberBuilder) Maximum(n int) NumberBuilder
func (NumberBuilder) Minimum ¶
func (nb NumberBuilder) Minimum(n int) NumberBuilder
func (NumberBuilder) MultipleOf ¶
func (nb NumberBuilder) MultipleOf(n int) NumberBuilder
type ObjectBuilder ¶
ObjectBuilder provides functions for object related options on the schema.
func (ObjectBuilder) Build ¶
func (o ObjectBuilder) Build() Schema
func (ObjectBuilder) MaxProperties ¶
func (o ObjectBuilder) MaxProperties(n int) ObjectBuilder
func (ObjectBuilder) MinProperties ¶
func (o ObjectBuilder) MinProperties(n int) ObjectBuilder
func (ObjectBuilder) Property ¶
func (o ObjectBuilder) Property(name string, schema Schema) ObjectBuilder
func (ObjectBuilder) Required ¶
func (o ObjectBuilder) Required(vals ...string) ObjectBuilder
type Schema ¶
Schema represents a json schema object.
https://json-schema.org/overview/what-is-jsonschema
func NewDateTimeSchema ¶
func NewDateTimeSchema() Schema
NewDateTimeSchema returns a Schema representing strings in the `date-time` format.
func (Schema) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
type Schemer ¶
type Schemer struct {
// DefaultStructRequire will mark all struct fields
// on the object schema as required unless it is a pointer.
DefaultStructRequire bool
// RefPath determines whether or not the schema will have
// any $ref items in it. When empty all schemas will be inlined.
// When set $ref will be $RefPath$TypeName.
//
// Defaults to `/schemas`.
RefPath string
// GetTypeName is used to get a name for the schema
// from a given type.
//
// This defaults to the name from reflect.Type Name.
GetTypeName func(reflect.Type) string
// contains filtered or unexported fields
}
Schemer creates Schema from provided types.
func NewSchemer ¶
func NewSchemer() Schemer
NewSchemer returns a Schemer with the default values set.
func (Schemer) GetSchemaByRef ¶
Get returns a Schema from the provided type.
type StringBuilder ¶
StringBuilder provides functions for string related options on the schema.
func (StringBuilder) Build ¶
func (s StringBuilder) Build() Schema
func (StringBuilder) Format ¶
func (s StringBuilder) Format(value Format) StringBuilder
func (StringBuilder) Length ¶
func (s StringBuilder) Length(n int) StringBuilder
func (StringBuilder) MaxLength ¶
func (s StringBuilder) MaxLength(n int) StringBuilder
func (StringBuilder) MinLength ¶
func (s StringBuilder) MinLength(n int) StringBuilder
func (StringBuilder) Pattern ¶
func (s StringBuilder) Pattern(value string) StringBuilder
type Type ¶
type Type string
const ( TypeString Type = openapi.StringType TypeNumber Type = openapi.NumberType TypeInteger Type = openapi.IntegerType TypeObject Type = openapi.ObjectType TypeArray Type = openapi.ArrayType TypeBoolean Type = openapi.BooleanType TypeNull Type = openapi.NullType )
type ValidationError ¶
type ValidationError struct {
OriginalError *jsonschema.ValidationError
Causes []ValidationError
Message string
Location string
}
ValidationError represents any errors that occurred during validation of a json object against a schema.
func (ValidationError) Error ¶
func (ve ValidationError) Error() string
func (ValidationError) String ¶
func (ve ValidationError) String() string