jsonschema

package
v2.0.0-rc.195 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2025 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JsonSchema

type JsonSchema struct {
	// Core schema fields
	Type                 SchemaType             `json:"type,omitempty"`
	Properties           map[string]*JsonSchema `json:"properties,omitempty"`
	Required             []string               `json:"required,omitempty"`
	AdditionalProperties *bool                  `json:"additionalProperties,omitempty"`
	Description          string                 `json:"description,omitempty"`
	Nullable             bool                   `json:"nullable,omitempty"`

	// Array-specific fields
	Items *JsonSchema `json:"items,omitempty"`

	// Enum values
	Enum []string `json:"enum,omitempty"`

	// Default value
	Default interface{} `json:"default,omitempty"`

	// String-specific fields
	Format string `json:"format,omitempty"`

	// Number-specific fields
	Minimum *float64 `json:"minimum,omitempty"`
	Maximum *float64 `json:"maximum,omitempty"`

	// Additional validation
	Pattern string `json:"pattern,omitempty"`
}

JsonSchema represents a JSON Schema definition

func BuildJsonSchema

func BuildJsonSchema(operationDocument, definitionDocument *ast.Document) (*JsonSchema, error)

BuildJsonSchema builds a JSON schema for the variables of the given operation using the default recursion depth of 1

func BuildJsonSchemaWithOptions

func BuildJsonSchemaWithOptions(operationDocument, definitionDocument *ast.Document, maxRecursionDepth int) (*JsonSchema, error)

BuildJsonSchemaWithOptions builds a JSON schema for the variables of the given operation with a custom recursion depth limit

func NewAnySchema

func NewAnySchema() *JsonSchema

NewAnySchema creates a schema representing any value (serialized as {} in JSON)

func NewArraySchema

func NewArraySchema(items *JsonSchema) *JsonSchema

NewArraySchema creates a new schema for an array type

func NewBooleanSchema

func NewBooleanSchema() *JsonSchema

NewBooleanSchema creates a new schema for a boolean type

func NewEnumSchema

func NewEnumSchema(values []string) *JsonSchema

NewEnumSchema creates a new schema for an enum type

func NewIntegerSchema

func NewIntegerSchema() *JsonSchema

NewIntegerSchema creates a new schema for an integer type

func NewNumberSchema

func NewNumberSchema() *JsonSchema

NewNumberSchema creates a new schema for a number type

func NewObjectSchema

func NewObjectSchema() *JsonSchema

NewObjectSchema creates a new schema for an object type

func NewStringSchema

func NewStringSchema() *JsonSchema

NewStringSchema creates a new schema for a string type

func (*JsonSchema) MarshalJSON

func (s *JsonSchema) MarshalJSON() ([]byte, error)

MarshalJSON customizes JSON serialization to omit empty fields

func (*JsonSchema) WithDefault

func (s *JsonSchema) WithDefault(defaultValue interface{}) *JsonSchema

WithDefault adds a default value to the schema

func (*JsonSchema) WithDescription

func (s *JsonSchema) WithDescription(description string) *JsonSchema

WithDescription adds a description to the schema

func (*JsonSchema) WithFormat

func (s *JsonSchema) WithFormat(format string) *JsonSchema

WithFormat adds a format to a string schema

func (*JsonSchema) WithNullable

func (s *JsonSchema) WithNullable(nullable bool) *JsonSchema

WithNullable marks a schema as nullable

type SchemaType

type SchemaType string

SchemaType represents the type of a JSON Schema property

const (
	TypeObject  SchemaType = "object"
	TypeArray   SchemaType = "array"
	TypeString  SchemaType = "string"
	TypeNumber  SchemaType = "number"
	TypeInteger SchemaType = "integer"
	TypeBoolean SchemaType = "boolean"
	TypeNull    SchemaType = "null"
)

type VariablesSchemaBuilder

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

VariablesSchemaBuilder creates a unified JSON schema for the variables of a GraphQL operation

func NewVariablesSchemaBuilder

func NewVariablesSchemaBuilder(operationDocument, definitionDocument *ast.Document) *VariablesSchemaBuilder

NewVariablesSchemaBuilder creates a new VariablesSchemaBuilder with default settings

func NewVariablesSchemaBuilderWithOptions

func NewVariablesSchemaBuilderWithOptions(operationDocument, definitionDocument *ast.Document, maxRecursionDepth int) *VariablesSchemaBuilder

NewVariablesSchemaBuilderWithOptions creates a new VariablesSchemaBuilder with custom options

func (*VariablesSchemaBuilder) Build

func (v *VariablesSchemaBuilder) Build() (*JsonSchema, error)

Build traverses the operation and builds a unified JSON schema for its variables

func (*VariablesSchemaBuilder) EnterDocument

func (v *VariablesSchemaBuilder) EnterDocument(operation, definition *ast.Document)

EnterDocument implements the astvisitor.EnterDocumentVisitor interface

func (*VariablesSchemaBuilder) EnterVariableDefinition

func (v *VariablesSchemaBuilder) EnterVariableDefinition(ref int)

EnterVariableDefinition implements the astvisitor.EnterVariableDefinitionVisitor interface

func (*VariablesSchemaBuilder) GetReport

GetReport returns the report containing any errors

func (*VariablesSchemaBuilder) GetSchema

func (v *VariablesSchemaBuilder) GetSchema() *JsonSchema

GetSchema returns the built schema

Jump to

Keyboard shortcuts

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