rusty-schema-diff

Crates.iorusty-schema-diff
lib.rsrusty-schema-diff
version0.1.1
sourcesrc
created_at2024-12-11 08:34:34.386638
updated_at2024-12-11 08:41:34.777893
descriptionA powerful schema evolution analyzer supporting JSON Schema, OpenAPI, Protobuf, and SQL DDL
homepagehttps://github.com/rusty-libraries/rusty-schema-diff
repository
max_upload_size
id1479745
size91,405
bufferization (24rr)

documentation

https://rusty-libraries.github.io/rusty-schema-diff/

README

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.

Commit count: 0

cargo fmt