|
| 1 | +# Rusty Schema Diff |
| 2 | + |
| 3 | +   |
| 4 | + |
| 5 | +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. |
| 6 | + |
| 7 | +## Table of Contents |
| 8 | + |
| 9 | +- [Rusty Schema Diff](#rusty-schema-diff) |
| 10 | + - [Table of Contents](#table-of-contents) |
| 11 | + - [Features](#features) |
| 12 | + - [Installation](#installation) |
| 13 | + - [Getting Started](#getting-started) |
| 14 | + - [Basic Usage](#basic-usage) |
| 15 | + - [Analyzing JSON Schema Changes](#analyzing-json-schema-changes) |
| 16 | + - [Analyzing OpenAPI Changes](#analyzing-openapi-changes) |
| 17 | + - [Analyzing SQL DDL Changes](#analyzing-sql-ddl-changes) |
| 18 | + - [Documentation](#documentation) |
| 19 | + - [License](#license) |
| 20 | + |
| 21 | +## Features |
| 22 | + |
| 23 | +- Multi-format support (JSON Schema, OpenAPI, Protobuf, SQL DDL) |
| 24 | +- Breaking change detection |
| 25 | +- Compatibility scoring |
| 26 | +- Migration path generation |
| 27 | +- Detailed change analysis |
| 28 | +- Validation and error reporting |
| 29 | + |
| 30 | +## Installation |
| 31 | + |
| 32 | +Add this to your `Cargo.toml`: |
| 33 | + |
| 34 | +```toml |
| 35 | +[dependencies] |
| 36 | +rusty-schema-diff = "0.1.0" |
| 37 | +``` |
| 38 | + |
| 39 | +## Getting Started |
| 40 | + |
| 41 | +### Basic Usage |
| 42 | + |
| 43 | +```rust |
| 44 | +use rusty_schema_diff::{Schema, SchemaFormat, JsonSchemaAnalyzer, SchemaAnalyzer}; |
| 45 | +use semver::Version; |
| 46 | + |
| 47 | +// Create schema instances |
| 48 | +let old_schema = Schema::new( |
| 49 | + SchemaFormat::JsonSchema, |
| 50 | + r#"{"type": "object", "properties": {"name": {"type": "string"}}}"#.to_string(), |
| 51 | + Version::parse("1.0.0").unwrap() |
| 52 | +); |
| 53 | + |
| 54 | +let new_schema = Schema::new( |
| 55 | + SchemaFormat::JsonSchema, |
| 56 | + r#"{"type": "object", "properties": {"name": {"type": "string"}, "age": {"type": "integer"}}}"#.to_string(), |
| 57 | + Version::parse("1.1.0").unwrap() |
| 58 | +); |
| 59 | + |
| 60 | +// Analyze compatibility |
| 61 | +let analyzer = JsonSchemaAnalyzer; |
| 62 | +let report = analyzer.analyze_compatibility(&old_schema, &new_schema).unwrap(); |
| 63 | + |
| 64 | +println!("Compatible: {}", report.is_compatible); |
| 65 | +println!("Score: {}", report.compatibility_score); |
| 66 | +``` |
| 67 | + |
| 68 | +### Analyzing JSON Schema Changes |
| 69 | + |
| 70 | +```rust |
| 71 | +use rusty_schema_diff::prelude::*; |
| 72 | + |
| 73 | +let analyzer = JsonSchemaAnalyzer; |
| 74 | +let report = analyzer.analyze_compatibility(&old_schema, &new_schema).unwrap(); |
| 75 | + |
| 76 | +// Generate migration plan |
| 77 | +let plan = analyzer.generate_migration_path(&old_schema, &new_schema).unwrap(); |
| 78 | + |
| 79 | +for step in plan.steps { |
| 80 | + println!("Migration step: {}", step); |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +### Analyzing OpenAPI Changes |
| 85 | + |
| 86 | +```rust |
| 87 | +use rusty_schema_diff::prelude::*; |
| 88 | + |
| 89 | +let analyzer = OpenApiAnalyzer; |
| 90 | +let report = analyzer.analyze_compatibility(&old_api, &new_api).unwrap(); |
| 91 | + |
| 92 | +println!("Breaking changes:"); |
| 93 | +for change in report.changes.iter().filter(|c| c.is_breaking) { |
| 94 | + println!("- {}: {}", change.location, change.description); |
| 95 | +} |
| 96 | +``` |
| 97 | + |
| 98 | +### Analyzing SQL DDL Changes |
| 99 | + |
| 100 | +```rust |
| 101 | +use rusty_schema_diff::prelude::*; |
| 102 | + |
| 103 | +let analyzer = SqlAnalyzer; |
| 104 | +let report = analyzer.analyze_compatibility(&old_ddl, &new_ddl).unwrap(); |
| 105 | + |
| 106 | +// Generate SQL migration statements |
| 107 | +let plan = analyzer.generate_migration_path(&old_ddl, &new_ddl).unwrap(); |
| 108 | +for statement in plan.steps { |
| 109 | + println!("SQL: {}", statement); |
| 110 | +} |
| 111 | +``` |
| 112 | + |
| 113 | +## Documentation |
| 114 | + |
| 115 | +For detailed information on all available analyzers and their functionality, please refer to the [API Documentation](https://docs.rs/rusty-schema-diff). |
| 116 | + |
| 117 | +## License |
| 118 | + |
| 119 | +This library is licensed under the MIT License. See the [LICENSE](LICENSE.md) file for details. |
0 commit comments