translate

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func ToPascalCase(s string) string

ToPascalCase converts a snake_case string to PascalCase for type name generation.

func ToSnakeCase added in v0.2.0

func ToSnakeCase(s string) string

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 Constraints added in v0.2.1

type Constraints struct {
	Enum             []any
	Const            *any
	Pattern          string
	Format           string
	MinLength        *int
	MaxLength        *int
	Minimum          *float64
	Maximum          *float64
	ExclusiveMinimum *float64
	ExclusiveMaximum *float64
	MultipleOf       *float64
	MinItems         *int
	MaxItems         *int
}

Constraints holds JSON Schema validation constraints for a field.

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
	Constraints Constraints // JSON Schema validation constraints
}

Field represents a single property within a type definition.

type Register

type Register map[string]Translator

Register maps format names to their translators.

func (Register) Available

func (r Register) Available() []string

Available returns all registered translator names.

func (Register) Get

func (r Register) Get(name string) (Translator, error)

Get retrieves a translator by name.

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

	// MapType wraps key and value type strings in a map type.
	MapType(keyType, valueType 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 dqxyaml translates JSON Schema constraints to DQX YAML quality checks.
Package dqxyaml translates JSON Schema constraints to DQX YAML quality checks.
Package gotypes provides Go struct type schema translation utilities.
Package gotypes provides Go struct type schema translation utilities.
Package markdown provides markdown schema documentation utilities.
Package markdown provides markdown schema documentation 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.

Jump to

Keyboard shortcuts

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