Documentation
¶
Overview ¶
Package translate provides schema translation utilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ToPascalCase ¶ added in v0.2.0
ToPascalCase converts a snake_case string to PascalCase for type name generation.
func ToSnakeCase ¶ added in v0.2.0
ToSnakeCase converts a string to a valid snake_case identifier. It splits on non-alphanumeric characters, lowercases each part, and prefixes with underscore if the result starts with a digit.
Types ¶
type Field ¶ added in v0.2.0
type Field struct {
Name string // property name (may be mutated by EnrichField)
Type string // fully resolved target type string
Nullable bool // true if not in schema.Required
Tag string // language-specific annotation, e.g. `json:"name,omitempty"`
Description string // schema description, if any
}
Field represents a single property within a type definition.
type Register ¶
type Register map[string]Translator
Register maps format names to their translators.
type SchemaData ¶ added in v0.2.0
type SchemaData struct {
Defs []TypeDef // $defs in topological order
Root TypeDef // the root/main schema
Description string // root schema description, if any
Extra map[string]any // translator-specific template data
}
SchemaData is the complete input passed to a translator template.
func Prepare ¶ added in v0.2.0
func Prepare(portName string, schema *jsonschema.Schema, resolver TypeResolver) (*SchemaData, error)
Prepare converts a JSON Schema into a SchemaData ready for template execution. It walks the schema tree, resolves types using the provided TypeResolver, and returns the data in topological order. Inline nested objects are automatically extracted as named type definitions.
type Translator ¶
type Translator interface {
// Translate converts a JSON schema to the target format.
// portName is used to name the output schema variable (e.g., "users" -> "users_schema").
// outputDir is the output directory path, used to derive package names where applicable.
Translate(portName string, schema *jsonschema.Schema, outputDir string) ([]byte, error)
// FileExtension returns the appropriate file extension (e.g., ".py", ".sql")
FileExtension() string
}
Translator defines the interface all format translators must implement.
type TypeDef ¶ added in v0.2.0
type TypeDef struct {
Name string // formatted name, e.g. "_Address" (PySpark) or "Address" (Go)
Fields []Field // ordered fields
}
TypeDef represents a named type definition (a $def or the root schema).
type TypeResolver ¶ added in v0.2.0
type TypeResolver interface {
// PrimitiveType maps a JSON Schema type and format to a target type string.
// Format is checked first, allowing "date-time" to override "string".
PrimitiveType(schemaType, format string) string
// ArrayType wraps an element type string in an array type.
ArrayType(elemType string) string
// RefType returns the type string for a $ref reference.
RefType(defName string) string
// FormatDefName formats a $def name for the target language.
FormatDefName(defName string) string
// FormatRootName formats the root schema name from the port name.
FormatRootName(portName string) string
// EnrichField applies language-specific post-processing to a resolved field.
// It may mutate any combination of the field's properties:
// - Name: rename for target conventions (e.g. snake_case → PascalCase for Go)
// - Type: wrap for nullability (e.g. Optional[T] for Python, *T for Go)
// - Tag: set annotations (e.g. json struct tags for Go, " = None" for Python)
// Called once per field after type resolution, before template execution.
EnrichField(f *Field)
}
TypeResolver converts JSON Schema types to target-language type strings and naming conventions. Each translator implements this interface to control how schemas map to its output format.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package avro provides Apache Avro schema translation utilities.
|
Package avro provides Apache Avro schema translation utilities. |
|
Package databrickspyspark provides Databricks PySpark schema translation with metadata comments.
|
Package databrickspyspark provides Databricks PySpark schema translation with metadata comments. |
|
Package databricksscala provides Databricks Scala StructType schema translation with metadata.
|
Package databricksscala provides Databricks Scala StructType schema translation with metadata. |
|
Package databrickssql provides Databricks SQL schema translation with DELTA and field comments.
|
Package databrickssql provides Databricks SQL schema translation with DELTA and field comments. |
|
Package gotypes provides Go struct type schema translation utilities.
|
Package gotypes provides Go struct type schema translation utilities. |
|
Package protobuf provides Protocol Buffers (proto3) schema translation utilities.
|
Package protobuf provides Protocol Buffers (proto3) schema translation utilities. |
|
Package pydantic provides Pydantic BaseModel schema translation utilities.
|
Package pydantic provides Pydantic BaseModel schema translation utilities. |
|
Package pyspark provides PySpark schema translation utilities.
|
Package pyspark provides PySpark schema translation utilities. |
|
Package python provides Python dataclass schema translation utilities.
|
Package python provides Python dataclass schema translation utilities. |
|
Package scala provides plain Scala case class schema translation.
|
Package scala provides plain Scala case class schema translation. |
|
Package sparkscala provides Spark Scala StructType schema translation utilities.
|
Package sparkscala provides Spark Scala StructType schema translation utilities. |
|
Package sparksql provides Spark DDL schema translation.
|
Package sparksql provides Spark DDL schema translation. |