GTS Rust Implementation
A complete Rust implementation of the Global Type System (GTS)
Overview
GTS Global Type System is a simple, human-readable, globally unique identifier and referencing system for data type definitions (e.g., JSON Schemas) and data instances (e.g., JSON objects). This Rust implementation provides high-performance, type-safe operations for working with GTS identifiers.
Roadmap
Featureset:
- OP#1 - ID Validation: Verify identifier syntax using regex patterns
- OP#2 - ID Extraction: Fetch identifiers from JSON objects or JSON Schema documents
- OP#3 - ID Parsing: Decompose identifiers into constituent parts (vendor, package, namespace, type, version, etc.)
- OP#4 - ID Pattern Matching: Match identifiers against patterns containing wildcards
- OP#5 - ID to UUID Mapping: Generate deterministic UUIDs from GTS identifiers
- OP#6 - Schema Validation: Validate object instances against their corresponding schemas
- OP#7 - Relationship Resolution: Load all schemas and instances, resolve inter-dependencies, and detect broken references
- OP#8 - Compatibility Checking: Verify that schemas with different MINOR versions are compatible
- OP#8.1 - Backward compatibility checking
- OP#8.2 - Forward compatibility checking
- OP#8.3 - Full compatibility checking
- OP#9 - Version Casting: Transform instances between compatible MINOR versions
- OP#10 - Query Execution: Filter identifier collections using the GTS query language
- OP#11 - Attribute Access: Retrieve property values and metadata using the attribute selector (
@)
See details in gts/README.md
Other GTS spec Reference Implementation recommended features support:
- In-memory entities registry - simple GTS entities registry with optional GTS references validation on entity registration
- CLI - command-line interface for all GTS operations
- Web server - a non-production web-server with REST API for the operations processing and testing
- x-gts-ref - to support special GTS entity reference annotation in schemas
- YAML support - to support YAML files (*.yml, *.yaml) as input files
- TypeSpec support - add typespec.io files (*.tsp) support
- UUID for instances - to support UUID as ID in JSON instances (anonymous instances)
Rust-specific features:
- Generate GTS schemas from Rust source code, see gts-macros/README.md and gts-macros-test/README.md
- Schema inheritance and composition for nested generic types with automatic
allOfgeneration - Automatically refer to GTS schemas for referenced objects
Technical Backlog:
- Code coverage - target is 90%
- Documentation - add documentation for all the features
- Interface - export publicly available interface and keep cli and others private
- Server API - finalise the server API
- Final code cleanup - remove unused code, denormalize, add critical comments, etc.
Architecture
The project is organized as a Cargo workspace with two crates:
gts (Library Crate)
Core library providing all GTS functionality:
- gts.rs - GTS ID parsing, validation, wildcard matching
- entities.rs - JSON entities, configuration, validation
- path_resolver.rs - JSON path resolution
- schema_cast.rs - Schema compatibility and casting
- files_reader.rs - File system scanning
- store.rs - Entity storage and querying
- ops.rs - High-level operations API
gts-cli (Binary Crate)
Command-line tool and HTTP server:
- cli.rs - Full CLI with all commands
- gen_schemas.rs - GTS schema generation from Rust source code
- server.rs - Axum-based HTTP server
- main.rs - Entry point
Installation
From Source
The binary will be available at target/release/gts.
As a Library
Add to your Cargo.toml:
[]
= { = "path/to/gts-rust/gts" }
Usage
CLI Commands
All CLI commands support --path to specify data directories and --config for custom configuration.
OP#1 - ID Validation
Verify that a GTS identifier follows the correct syntax.
# Validate a schema ID
# Validate an instance ID
# Validate a chained ID
# Invalid ID example
Output:
OP#2 - ID Extraction
Extract GTS identifiers from JSON objects. This happens automatically when loading files.
# List all entities (extracts IDs from all JSON/YAML files)
OP#3 - ID Parsing
Decompose a GTS identifier into its constituent parts.
# Parse a simple schema ID
# Parse an instance ID with minor version
# Parse a chained ID
Output:
OP#4 - ID Pattern Matching
Match identifiers against patterns with wildcards.
# Match with wildcard namespace
# Match specific version range
# No match example
Output:
OP#5 - ID to UUID Mapping
Generate deterministic UUIDs from GTS identifiers.
# Generate UUID with major version scope (default)
# Generate UUID with minor version scope
# Same major version produces same UUID
Output:
OP#6 - Schema Validation
Validate object instances against their corresponding schemas.
# Validate a single instance
# The system:
# 1. Loads the instance by ID
# 2. Finds its schema (via $schema or type field)
# 3. Validates using JSON Schema validation
Output:
OP#7 - Relationship Resolution
Load all schemas and instances, resolve inter-dependencies, and detect broken references.
# Resolve relationships for an entity
# The system:
# 1. Loads the entity
# 2. Extracts all GTS ID references ($ref, nested IDs)
# 3. Resolves each reference
# 4. Reports missing or broken references
Output:
OP#8 - Compatibility Checking
Verify that schemas with different MINOR versions are compatible.
# Check compatibility between schema versions
# The system checks:
# - OP#8.1: Backward compatibility (old instances work with new schema)
# - OP#8.2: Forward compatibility (new instances work with old schema)
# - OP#8.3: Full compatibility (both directions compatible)
Output:
OP#9 - Version Casting
Transform instances between compatible MINOR versions.
# Cast instance from v1.0 to v1.1 schema (instance is identified by UUID)
# The system:
# 1. Loads source instance and both schemas
# 2. Checks compatibility
# 3. Applies transformations (adds defaults, removes extra fields, updates const values)
# 4. Returns transformed instance
Output:
OP#10 - Query Execution
Filter identifier collections using the GTS query language.
# Query with wildcard pattern
# Query with attribute filter
# Query schemas only (ending with ~)
# Query specific namespace
Output:
OP#11 - Attribute Access
Retrieve property values and metadata using the attribute selector (@).
# Access top-level property
# Access nested property
# Access array element
# Access schema property
Output:
Additional Commands
List Entities:
Start HTTP Server:
# Start server without HTTP logging (WARNING level only)
# CURL: curl http://127.0.0.1:8000/entities | jq .
# Start server with HTTP request logging (-v or --verbose)
# Start server with detailed logging including request/response bodies (-vv)
Verbose logging format:
- No flag: WARNING level only (no HTTP request logs)
-v: INFO level - Logs HTTP requests with color-coded output-vv: DEBUG level - Additionally logs request/response bodies with pretty-printed JSON
Generate OpenAPI Spec:
Library Usage
All operations are available through the GtsOps API.
Setup
use ;
use json;
// Initialize GTS operations with data paths
let mut ops = new;
OP#1 - ID Validation
// Validate a GTS ID
let result = ops.validate_id;
assert!;
// Validate invalid ID
let result = ops.validate_id;
assert!;
assert!;
// Direct validation without ops
let is_valid = is_valid;
assert!;
OP#2 - ID Extraction
// ID extraction happens automatically when loading entities
// Configure which fields to check for IDs:
let config = GtsConfig ;
// Load entities (IDs extracted automatically)
let results = ops.list;
for entity in results.results
OP#3 - ID Parsing
// Parse a GTS ID into components
let result = ops.parse_id;
assert!;
assert_eq!;
let segment = &result.segments;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert!;
// Parse chained ID
let result = ops.parse_id;
assert_eq!;
// Direct parsing
let id = new?;
assert_eq!;
OP#4 - ID Pattern Matching
// Match ID against wildcard pattern
let result = ops.match_id_pattern;
assert!;
// No match
let result = ops.match_id_pattern;
assert!;
// Direct wildcard matching
let pattern = new?;
let id = new?;
assert!;
OP#5 - ID to UUID Mapping
// Generate UUID from GTS ID
let result = ops.uuid;
assert!;
// Minor scope UUID
let result = ops.uuid;
// Direct UUID generation
let id = new?;
let uuid = id.to_uuid;
println!;
// Same major version produces same UUID
let id1 = new?;
let id2 = new?;
assert_eq!;
OP#6 - Schema Validation
// Validate instance against its schema
let result = ops.validate_instance;
assert!;
if !result.ok
// The system automatically:
// 1. Loads the instance
// 2. Finds its schema (via $schema or type field)
// 3. Validates using JSON Schema
OP#7 - Relationship Resolution
// Resolve all references for an entity
let result = ops.resolve_relationships;
assert!;
// Check for broken references
if !result.missing_refs.is_empty
// List all references
for ref_id in result.refs
OP#8 - Compatibility Checking
// Check schema compatibility
let result = ops.compatibility;
// OP#8.1 - Backward compatibility
if result.is_backward_compatible else
// OP#8.2 - Forward compatibility
if result.is_forward_compatible else
// OP#8.3 - Full compatibility
if result.is_fully_compatible
OP#9 - Version Casting
// Cast instance to new schema version (instance identified by UUID)
let result = ops.cast;
// Check what changed
println!;
println!;
println!;
// Get the transformed entity
if let Some = result.casted_entity
// Check compatibility
if !result.is_backward_compatible
OP#10 - Query Execution
// Query with wildcard pattern
let results = ops.query;
println!;
for entity in results.results
// Query with attribute filter
let results = ops.query;
// Query schemas only
let results = ops.query;
// List all entities
let results = ops.list;
OP#11 - Attribute Access
// Access entity attribute
let result = ops.attr;
assert!;
println!;
// Access nested property
let result = ops.attr;
// Access array element
let result = ops.attr;
// Access schema property
let result = ops.attr;
assert_eq!;
// Handle missing attributes
if !result.ok
Complete Example
use GtsOps;
HTTP API
Start the server:
# curl http://localhost:8000/entities | jq .
Example API calls:
# Validate ID
# Parse ID
# Query entities
# Add entity
Configuration
Create a gts.config.json file to customize entity ID field detection:
GTS ID Format
GTS identifiers follow this format:
gts.<vendor>.<package>.<namespace>.<type>.v<MAJOR>[.<MINOR>][~]
- Prefix: Always starts with
gts. - Vendor: Organization or vendor code
- Package: Module or application name
- Namespace: Category within the package
- Type: Specific type name
- Version: Semantic version (major.minor)
- Type Marker: Trailing
~indicates a schema/type (vs instance)
Examples:
gts.x.core.events.event.v1~- Schemagts.x.core.events.event.v1.0- Instancegts.x.core.events.type.v1~vendor.app._.custom.v1~- Chained (inheritance)
Testing
Run the test suite:
Run with verbose output:
Development
Build
Build Release
Run Tests
Format Code
Lint
License
Apache-2.0
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Links
Acknowledgments
This Rust implementation is based on the Python reference implementation and follows the GTS specification v0.4.