#schema #protobuf #diff #openapi #sql

rusty-schema-diff

A powerful schema evolution analyzer supporting JSON Schema, OpenAPI, Protobuf, and SQL DDL

2 releases

new 0.1.1 Dec 11, 2024
0.1.0 Dec 11, 2024

#979 in Web programming

Download history 202/week @ 2024-12-06

202 downloads per month

Custom license

91KB
1.5K SLoC

Rusty Schema Diff

Crates.io docs.rs License

Welcome to Rusty Schema Diff, a powerful schema evolution analyzer that supports multiple schema formats including JSON Schema, OpenAPI, Protobuf, and SQL DDL. This library helps you analyze and manage schema changes across different versions, detect breaking changes, and generate migration paths.

Table of Contents

Features

  • Multi-format support (JSON Schema, OpenAPI, Protobuf, SQL DDL)
  • Breaking change detection
  • Compatibility scoring
  • Migration path generation
  • Detailed change analysis
  • Validation and error reporting

Installation

Add this to your Cargo.toml:

[dependencies]
rusty-schema-diff = "0.1.1"

Getting Started

Basic Usage

use rusty_schema_diff::{Schema, SchemaFormat, JsonSchemaAnalyzer, SchemaAnalyzer};
use semver::Version;

// Create schema instances
let old_schema = Schema::new(
    SchemaFormat::JsonSchema,
    r#"{"type": "object", "properties": {"name": {"type": "string"}}}"#.to_string(),
    Version::parse("1.0.0").unwrap()
);

let new_schema = Schema::new(
    SchemaFormat::JsonSchema,
    r#"{"type": "object", "properties": {"name": {"type": "string"}, "age": {"type": "integer"}}}"#.to_string(),
    Version::parse("1.1.0").unwrap()
);

// Analyze compatibility
let analyzer = JsonSchemaAnalyzer;
let report = analyzer.analyze_compatibility(&old_schema, &new_schema).unwrap();

println!("Compatible: {}", report.is_compatible);
println!("Score: {}", report.compatibility_score);

Analyzing JSON Schema Changes

use rusty_schema_diff::prelude::*;

let analyzer = JsonSchemaAnalyzer;
let report = analyzer.analyze_compatibility(&old_schema, &new_schema).unwrap();

// Generate migration plan
let plan = analyzer.generate_migration_path(&old_schema, &new_schema).unwrap();

for step in plan.steps {
    println!("Migration step: {}", step);
}

Analyzing OpenAPI Changes

use rusty_schema_diff::prelude::*;

let analyzer = OpenApiAnalyzer;
let report = analyzer.analyze_compatibility(&old_api, &new_api).unwrap();

println!("Breaking changes:");
for change in report.changes.iter().filter(|c| c.is_breaking) {
    println!("- {}: {}", change.location, change.description);
}

Analyzing SQL DDL Changes

use rusty_schema_diff::prelude::*;

let analyzer = SqlAnalyzer;
let report = analyzer.analyze_compatibility(&old_ddl, &new_ddl).unwrap();

// Generate SQL migration statements
let plan = analyzer.generate_migration_path(&old_ddl, &new_ddl).unwrap();
for statement in plan.steps {
    println!("SQL: {}", statement);
}

Documentation

For detailed information on all available analyzers and their functionality, please refer to the API Documentation.

License

This library is licensed under the MIT License. See the LICENSE file for details.

Dependencies

~6.5MB
~132K SLoC