jsonschema

package
v0.0.0-...-f88c608 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: AGPL-3.0, MIT Imports: 9 Imported by: 1

Documentation

Overview

Package jsonschema uses reflection to generate JSON Schemas from Go types [1].

If json tags are present on struct fields, they will be used to infer property names and if a property is required (omitempty is present).

[1] http://json-schema.org/latest/json-schema-validation.html

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Definitions

type Definitions map[string]*Type

Definitions is a map of type names to types.

type Schema

type Schema struct {
	*Type
	Definitions Definitions `json:"definitions,omitempty"`
}

Schema represents a JSON Schema.

func Reflect

func Reflect(v interface{}) *Schema

Reflect a Schema from a value.

func ReflectFromObjType

func ReflectFromObjType(objtype *rpcreflect.ObjType) *Schema

rpcreflect is itself a description so we provide additional handling here

func ReflectFromType

func ReflectFromType(t reflect.Type) *Schema

ReflectFromType a Schema from a reflect.Type.

type Type

type Type struct {
	Type                 string           `json:"type,omitempty"`
	Format               string           `json:"format,omitempty"`
	Items                *Type            `json:"items,omitempty"`
	Properties           map[string]*Type `json:"properties,omitempty"`
	PatternProperties    map[string]*Type `json:"patternProperties,omitempty"`
	AdditionalProperties json.RawMessage  `json:"additionalProperties,omitempty"`
	Ref                  string           `json:"$ref,omitempty"`
	Required             []string         `json:"required,omitempty"`
	MaxLength            int              `json:"maxLength,omitempty"`
	MinLength            int              `json:"minLength,omitempty"`
	Pattern              string           `json:"pattern,omitempty"`
	Enum                 []interface{}    `json:"enum,omitempty"`
	Default              interface{}      `json:"default,omitempty"`
	Title                string           `json:"title,omitempty"`
	Description          string           `json:"description,omitempty"`
}

Type represents a JSON Schema type.

Jump to

Keyboard shortcuts

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