Documentation
¶
Index ¶
- type JsonSchema
- func BuildJsonSchema(operationDocument, definitionDocument *ast.Document) (*JsonSchema, error)
- func NewAnySchema() *JsonSchema
- func NewArraySchema(items *JsonSchema) *JsonSchema
- func NewBooleanSchema() *JsonSchema
- func NewEnumSchema(values []string) *JsonSchema
- func NewIntegerSchema() *JsonSchema
- func NewNumberSchema() *JsonSchema
- func NewObjectSchema() *JsonSchema
- func NewRefSchema(typeName string) *JsonSchema
- func NewStringSchema() *JsonSchema
- func (s *JsonSchema) MarshalJSON() ([]byte, error)
- func (s *JsonSchema) WithDefault(defaultValue interface{}) *JsonSchema
- func (s *JsonSchema) WithDescription(description string) *JsonSchema
- func (s *JsonSchema) WithFormat(format string) *JsonSchema
- func (s *JsonSchema) WithNullable(nullable bool) *JsonSchema
- type SchemaType
- type VariablesSchemaBuilder
- func (v *VariablesSchemaBuilder) Build() (*JsonSchema, error)
- func (v *VariablesSchemaBuilder) EnterDocument(operation, definition *ast.Document)
- func (v *VariablesSchemaBuilder) EnterVariableDefinition(ref int)
- func (v *VariablesSchemaBuilder) GetReport() *operationreport.Report
- func (v *VariablesSchemaBuilder) GetSchema() *JsonSchema
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 is tracked internally; serialization expresses nullability in the
// JSON Schema 2020-12 form (type-union, anyOf, or null in enum), not the
// OpenAPI 3.0 "nullable" keyword.
Nullable bool `json:"-"`
// Ref references a schema defined under the root "$defs" (e.g. "#/$defs/MyInput").
// Used to represent recursive input types, which cannot be inlined.
Ref string `json:"$ref,omitempty"`
// Defs holds reusable schema definitions, referenced via Ref. Only populated
// on the root schema.
Defs map[string]*JsonSchema `json:"$defs,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. Recursive input types are represented via "$ref"/"$defs" and support arbitrary nesting depth.
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 NewRefSchema ¶ added in v2.4.2
func NewRefSchema(typeName string) *JsonSchema
NewRefSchema creates a schema that references a definition under the root "$defs".
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.
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 ¶
func (v *VariablesSchemaBuilder) GetReport() *operationreport.Report
GetReport returns the report containing any errors
func (*VariablesSchemaBuilder) GetSchema ¶
func (v *VariablesSchemaBuilder) GetSchema() *JsonSchema
GetSchema returns the built schema