Documentation
¶
Index ¶
- type Generator
- type GeneratorOptions
- type Parser
- func (p *Parser) ExtractSchemas(rootTypeName string) []SchemaInfo
- func (p *Parser) GetDefinition(name string) *Schema
- func (p *Parser) GetResolvedSchema(ref string) *Schema
- func (p *Parser) Parse(data []byte) (*Schema, error)
- func (p *Parser) ParseFile(filename string) (*Schema, error)
- func (p *Parser) ValidateJSON(data []byte, schema *Schema) error
- type Schema
- type SchemaInfo
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator generates Go code from JTD schemas
func NewGenerator ¶
func NewGenerator(parser *Parser, opts GeneratorOptions) *Generator
NewGenerator creates a new code generator
func (*Generator) GenerateValidation ¶
GenerateValidation generates validation methods for types
func (*Generator) GenerateWithTemplate ¶
GenerateWithTemplate generates code using a template
type GeneratorOptions ¶
type GeneratorOptions struct {
PackageName string
GenerateComments bool
GenerateValidate bool
TypeNamePrefix string
TypeNameSuffix string
RootTypeName string // Name for the root schema type (defaults to package name if empty)
}
GeneratorOptions configures the code generator
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser handles parsing JTD schemas and resolving references
func (*Parser) ExtractSchemas ¶
func (p *Parser) ExtractSchemas(rootTypeName string) []SchemaInfo
ExtractSchemas extracts all schemas that need code generation
func (*Parser) GetDefinition ¶
GetDefinition returns a definition by name
func (*Parser) GetResolvedSchema ¶
GetResolvedSchema returns a resolved schema for a given reference
type Schema ¶
type Schema struct {
// Metadata
Metadata map[string]any `json:"metadata,omitempty"`
// Nullable indicates whether the value can be null
Nullable bool `json:"nullable,omitempty"`
// Type forms
Type Type `json:"type,omitempty"`
// Enum form
Enum []string `json:"enum,omitempty"`
// Elements form (for arrays)
Elements *Schema `json:"elements,omitempty"`
// Properties form (for objects)
Properties map[string]*Schema `json:"properties,omitempty"`
OptionalProperties map[string]*Schema `json:"optionalProperties,omitempty"`
AdditionalProperties bool `json:"additionalProperties,omitempty"`
// Values form (for maps)
Values *Schema `json:"values,omitempty"`
// Discriminator form (for tagged unions)
Discriminator string `json:"discriminator,omitempty"`
Mapping map[string]*Schema `json:"mapping,omitempty"`
// Ref form
Ref string `json:"ref,omitempty"`
// Definitions (for root schema only)
Definitions map[string]*Schema `json:"definitions,omitempty"`
}
Schema represents a JSON Type Definition schema according to RFC 8927
func ParseSchema ¶
ParseSchema parses a JSON Type Definition schema from JSON
type SchemaInfo ¶
type SchemaInfo struct {
Name string
GoName string
Schema *Schema
IsRoot bool
IsNullable bool
Description string
}
SchemaInfo contains information about a schema for code generation
type Type ¶
type Type string
Type represents the primitive types in JTD
const ( TypeBoolean Type = "boolean" TypeString Type = "string" TypeTimestamp Type = "timestamp" TypeFloat32 Type = "float32" TypeFloat64 Type = "float64" TypeInt8 Type = "int8" TypeInt16 Type = "int16" TypeInt32 Type = "int32" TypeUint8 Type = "uint8" TypeUint16 Type = "uint16" TypeUint32 Type = "uint32" )