diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7d34d23..5e4f2a7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,6 @@ jobs: - uses: actions-rs/cargo@v1 with: command: test - args: --release format: name: Format diff --git a/Cargo.toml b/Cargo.toml index 3abbaa6..1dc2b77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [workspace] +resolver = "3" members = [ "schema_analysis", diff --git a/rust-toolchain.toml b/rust-toolchain.toml index c5794a6..73328e0 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.85" +channel = "1.90" diff --git a/schema_analysis/Cargo.toml b/schema_analysis/Cargo.toml index 7986f9b..e5fe644 100644 --- a/schema_analysis/Cargo.toml +++ b/schema_analysis/Cargo.toml @@ -3,7 +3,7 @@ name = "schema_analysis" version = "0.5.0" authors = ["QuartzLibrary"] license = "MIT OR Apache-2.0" -edition = "2018" +edition = "2024" description = "Analyze the schema of any self describing format" homepage = "https://schema-analysis.com/" repository = "https://github.com/QuartzLibrary/schema_analysis" diff --git a/schema_analysis/src/analysis/field.rs b/schema_analysis/src/analysis/field.rs index 107d7bc..587540c 100644 --- a/schema_analysis/src/analysis/field.rs +++ b/schema_analysis/src/analysis/field.rs @@ -4,7 +4,7 @@ use serde::de::{DeserializeSeed, Error, Visitor}; use crate::Field; -use super::{schema::SchemaVisitor, schema_seed::SchemaVisitorSeed, Context}; +use super::{Context, schema::SchemaVisitor, schema_seed::SchemaVisitorSeed}; pub(super) struct InferredField { _marker: PhantomData, diff --git a/schema_analysis/src/analysis/mod.rs b/schema_analysis/src/analysis/mod.rs index 35ae692..992b9e6 100644 --- a/schema_analysis/src/analysis/mod.rs +++ b/schema_analysis/src/analysis/mod.rs @@ -170,14 +170,14 @@ let _: Visitor::Value = deserializer.deserialize_str(visitor); `[...]` */ -use serde::{de::DeserializeSeed, Deserialize}; +use serde::{Deserialize, de::DeserializeSeed}; #[allow(unused_imports)] use serde::de::Visitor; // For docs above. use crate::{ - context::{Context, DefaultContext}, Coalesce, Schema, + context::{Context, DefaultContext}, }; mod field; @@ -235,7 +235,7 @@ where mod boilerplate { use std::fmt; - use crate::{context::Context, Schema}; + use crate::{Schema, context::Context}; use super::InferredSchema; diff --git a/schema_analysis/src/analysis/schema.rs b/schema_analysis/src/analysis/schema.rs index 9f1742e..79b4045 100644 --- a/schema_analysis/src/analysis/schema.rs +++ b/schema_analysis/src/analysis/schema.rs @@ -3,11 +3,11 @@ use std::marker::PhantomData; use ordermap::OrderMap; use serde::de::{Error, Visitor}; -use crate::{traits::Aggregate, Field, Schema}; +use crate::{Field, Schema, traits::Aggregate}; use super::{ - field::{InferredField, InferredFieldSeed}, Context, + field::{InferredField, InferredFieldSeed}, }; pub(super) struct SchemaVisitor { diff --git a/schema_analysis/src/analysis/schema_seed.rs b/schema_analysis/src/analysis/schema_seed.rs index 1448aca..fe4f40f 100644 --- a/schema_analysis/src/analysis/schema_seed.rs +++ b/schema_analysis/src/analysis/schema_seed.rs @@ -1,11 +1,11 @@ use serde::de::{Error, Visitor}; -use crate::{traits::Aggregate, traits::Coalesce, Schema}; +use crate::{Schema, traits::Aggregate, traits::Coalesce}; use super::{ + Context, field::{InferredField, InferredFieldSeed}, schema::SchemaVisitor, - Context, }; pub(super) struct SchemaVisitorSeed<'s, C: Context> { @@ -182,8 +182,8 @@ where match &mut self.schema { // The schema matches Schema::Sequence { - field: ref mut boxed_field, - context: ref mut aggregators, + field: boxed_field, + context: aggregators, } => { let field = boxed_field.as_mut(); diff --git a/schema_analysis/src/context/mod.rs b/schema_analysis/src/context/mod.rs index c678046..0840c64 100644 --- a/schema_analysis/src/context/mod.rs +++ b/schema_analysis/src/context/mod.rs @@ -23,7 +23,7 @@ pub use string::{SemanticExtractor, StringContext, SuspiciousStrings}; use serde::{Deserialize, Serialize}; use std::fmt::Debug; -use crate::{traits::Aggregate, Coalesce}; +use crate::{Coalesce, traits::Aggregate}; /// Interface describing the custom analysis that will be run on each type /// alongside the schema shape. diff --git a/schema_analysis/src/context/number.rs b/schema_analysis/src/context/number.rs index 016e460..839d281 100644 --- a/schema_analysis/src/context/number.rs +++ b/schema_analysis/src/context/number.rs @@ -2,13 +2,13 @@ use std::fmt::Debug; -use serde::{de::DeserializeOwned, Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::DeserializeOwned}; use crate::{traits::Aggregate, traits::Coalesce}; use super::{ - shared::{MinMax, Sampler}, Counter, + shared::{MinMax, Sampler}, }; /// The context for numeric values. diff --git a/schema_analysis/src/context/sequence.rs b/schema_analysis/src/context/sequence.rs index 7354375..a82ad36 100644 --- a/schema_analysis/src/context/sequence.rs +++ b/schema_analysis/src/context/sequence.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; use crate::{traits::Aggregate, traits::Coalesce}; -use super::{shared::MinMax, Counter}; +use super::{Counter, shared::MinMax}; #[derive(Debug, Clone, Default, Serialize, Deserialize)] pub struct SequenceContext { diff --git a/schema_analysis/src/helpers.rs b/schema_analysis/src/helpers.rs index 839845a..acb0743 100644 --- a/schema_analysis/src/helpers.rs +++ b/schema_analysis/src/helpers.rs @@ -6,7 +6,7 @@ pub mod xml { use std::mem; - use crate::{context::Context, Field, Schema}; + use crate::{Field, Schema, context::Context}; /// A wrapper function that applies all XML cleaning transformations. /// diff --git a/schema_analysis/src/schema.rs b/schema_analysis/src/schema.rs index af654a5..2517b46 100644 --- a/schema_analysis/src/schema.rs +++ b/schema_analysis/src/schema.rs @@ -1,9 +1,9 @@ use std::mem; -use ordermap::{map::Entry, OrderMap}; +use ordermap::{OrderMap, map::Entry}; use serde::{Deserialize, Serialize}; -use crate::{context::Context, context::DefaultContext, Coalesce, StructuralEq}; +use crate::{Coalesce, StructuralEq, context::Context, context::DefaultContext}; /// This enum is the core output of the analysis, it describes the structure of a document. /// diff --git a/schema_analysis/src/targets/json_typegen.rs b/schema_analysis/src/targets/json_typegen.rs index cc5ee89..b7fefb8 100644 --- a/schema_analysis/src/targets/json_typegen.rs +++ b/schema_analysis/src/targets/json_typegen.rs @@ -19,9 +19,9 @@ let output: String = json_typegen_shared::codegen_from_shape("Root", &Shape::Boo ``` */ -pub use json_typegen_shared::{codegen_from_shape, ErrorKind, JTError, Options, OutputMode, Shape}; +pub use json_typegen_shared::{ErrorKind, JTError, Options, OutputMode, Shape, codegen_from_shape}; -use crate::{context::Context, Field, Schema}; +use crate::{Field, Schema, context::Context}; impl Schema { /// Convert a [Schema] to a json_typegen [Shape]. diff --git a/schema_analysis/src/targets/schemars.rs b/schema_analysis/src/targets/schemars.rs index 68f2108..c1b5fa4 100644 --- a/schema_analysis/src/targets/schemars.rs +++ b/schema_analysis/src/targets/schemars.rs @@ -1,24 +1,23 @@ //! Integration with [schemars](https://github.com/GREsau/schemars) -use std::error::Error; - use schemars::schema as schemars_types; -use crate::{context::Context, Schema}; +use crate::{Schema, context::Context}; impl Schema { /// Convert into a json_schema using the default settings. - pub fn to_json_schema_with_schemars(&self) -> Result { - self.to_json_schema_with_schemars_version(&Default::default()) + pub fn to_json_schema_with_schemars(&self) -> serde_json::Result { + let default = Default::default(); + self.to_json_schema_with_schemars_version(&default) } /// Convert into a specific version of json_schema. pub fn to_json_schema_with_schemars_version( &self, version: &JsonSchemaVersion, - ) -> Result { - let settings: schemars::gen::SchemaSettings = version.to_schemars_settings(); - let mut generator: schemars::gen::SchemaGenerator = settings.into(); + ) -> serde_json::Result { + let settings: schemars::r#gen::SchemaSettings = version.to_schemars_settings(); + let mut generator: schemars::r#gen::SchemaGenerator = settings.into(); let root = self.to_schemars_schema(&mut generator); serde_json::to_string_pretty(&root) @@ -27,7 +26,7 @@ impl Schema { /// Convert using a provided generator (which also holds the settings) to a json schema. pub fn to_schemars_schema( &self, - generator: &mut schemars::gen::SchemaGenerator, + generator: &mut schemars::r#gen::SchemaGenerator, ) -> schemars_types::RootSchema { let inner = helpers::inferred_to_schemars(generator, self); helpers::wrap_in_root(inner, generator.settings()) @@ -35,24 +34,20 @@ impl Schema { } /// The currently supported json schema versions. -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] pub enum JsonSchemaVersion { - /// `schemars::gen::SchemaSettings::draft07` + /// `schemars::r#gen::SchemaSettings::draft07` Draft07, - /// `schemars::gen::SchemaSettings::draft2019_09` + /// `schemars::r#gen::SchemaSettings::draft2019_09` + #[default] Draft2019_09, - /// `schemars::gen::SchemaSettings::openapi3` + /// `schemars::r#gen::SchemaSettings::openapi3` OpenApi3, } -impl Default for JsonSchemaVersion { - fn default() -> Self { - Self::Draft2019_09 - } -} impl JsonSchemaVersion { /// Convert the version to full settings. - pub fn to_schemars_settings(&self) -> schemars::gen::SchemaSettings { - use schemars::gen::SchemaSettings; + pub fn to_schemars_settings(&self) -> schemars::r#gen::SchemaSettings { + use schemars::r#gen::SchemaSettings; match self { JsonSchemaVersion::Draft07 => SchemaSettings::draft07(), JsonSchemaVersion::Draft2019_09 => SchemaSettings::draft2019_09(), @@ -67,12 +62,12 @@ mod helpers { use schemars::schema as schemars_types; - use crate::{context::Context, Field, Schema}; + use crate::{Field, Schema, context::Context}; /// Wraps a [Schema](schemars_types::Schema) in a [RootSchema](schemars_types::RootSchema). pub fn wrap_in_root( inner: schemars_types::Schema, - settings: &schemars::gen::SchemaSettings, + settings: &schemars::r#gen::SchemaSettings, ) -> schemars_types::RootSchema { schemars_types::RootSchema { meta_schema: settings.meta_schema.clone(), @@ -83,7 +78,7 @@ mod helpers { /// Converts an inferred [Schema] to a schemars [Schema](schemars_types::Schema). pub fn inferred_to_schemars( - generator: &mut schemars::gen::SchemaGenerator, + generator: &mut schemars::r#gen::SchemaGenerator, inferred: &Schema, ) -> schemars_types::Schema { // Note: we can use the generator even if we don't generate the final root schema @@ -166,7 +161,7 @@ mod helpers { /// Converts a [Field] into a [Schema](schemars_types::Schema). fn internal_field_to_schemars_schema( - generator: &mut schemars::gen::SchemaGenerator, + generator: &mut schemars::r#gen::SchemaGenerator, field: &Field, ) -> schemars_types::Schema { // Note: we can use the generator even if we don't generate the final root schema diff --git a/schema_analysis/tests/source_json.rs b/schema_analysis/tests/source_json.rs index 321f770..20a8703 100644 --- a/schema_analysis/tests/source_json.rs +++ b/schema_analysis/tests/source_json.rs @@ -1,4 +1,4 @@ -use serde_json::{json, Value}; +use serde_json::{Value, json}; use schema_analysis::InferredSchema; diff --git a/schema_analysis/tests/source_toml.rs b/schema_analysis/tests/source_toml.rs index 41dbd1d..7d89298 100644 --- a/schema_analysis/tests/source_toml.rs +++ b/schema_analysis/tests/source_toml.rs @@ -1,4 +1,4 @@ -use toml::{value::Table, Value}; +use toml::{Value, value::Table}; use schema_analysis::InferredSchema; diff --git a/schema_analysis/tests/source_xml.rs b/schema_analysis/tests/source_xml.rs index a9b2cc7..4487bc3 100644 --- a/schema_analysis/tests/source_xml.rs +++ b/schema_analysis/tests/source_xml.rs @@ -1,4 +1,4 @@ -use schema_analysis::{helpers, InferredSchema}; +use schema_analysis::{InferredSchema, helpers}; mod shared; use shared::FormatTests; diff --git a/schema_analysis/tests/target_json_schema_json_typegen.rs b/schema_analysis/tests/target_json_schema_json_typegen.rs index 30bf644..4d24f1c 100644 --- a/schema_analysis/tests/target_json_schema_json_typegen.rs +++ b/schema_analysis/tests/target_json_schema_json_typegen.rs @@ -1,7 +1,7 @@ #![cfg(feature = "json_typegen")] use json_typegen_shared::OutputMode; -use serde_json::{json, Value}; +use serde_json::{Value, json}; use schema_analysis::{InferredSchema, Schema}; diff --git a/schema_analysis/tests/target_json_schema_schemars.rs b/schema_analysis/tests/target_json_schema_schemars.rs index a09f25c..a07e9f9 100644 --- a/schema_analysis/tests/target_json_schema_schemars.rs +++ b/schema_analysis/tests/target_json_schema_schemars.rs @@ -1,6 +1,6 @@ #![cfg(feature = "schemars_integration")] -use serde_json::{json, Value}; +use serde_json::{Value, json}; use schema_analysis::{InferredSchema, Schema}; diff --git a/website/schema_analysis_wasm/Cargo.toml b/website/schema_analysis_wasm/Cargo.toml index f8229ed..d4da7ce 100644 --- a/website/schema_analysis_wasm/Cargo.toml +++ b/website/schema_analysis_wasm/Cargo.toml @@ -2,7 +2,7 @@ name = "schema_analysis_wasm" version = "0.2.2" authors = ["QuartzLibrary"] -edition = "2018" +edition = "2024" publish = false [lib] diff --git a/website/schema_analysis_wasm/src/lib.rs b/website/schema_analysis_wasm/src/lib.rs index 39f7fb3..da046fd 100644 --- a/website/schema_analysis_wasm/src/lib.rs +++ b/website/schema_analysis_wasm/src/lib.rs @@ -3,7 +3,7 @@ use std::{error::Error, fmt, sync::Mutex}; use once_cell::sync::Lazy; use wasm_bindgen::prelude::wasm_bindgen; -use schema_analysis::{targets::json_typegen::OutputMode, InferredSchema, Schema}; +use schema_analysis::{InferredSchema, Schema, targets::json_typegen::OutputMode}; // For some reason Rust Analyzer (clippy) errors with missing-unsafe if log! (or similar) // is not in a nested function. Adding an unsafe block results in a rustc lint (unused_unsafe). @@ -68,7 +68,7 @@ pub fn infer(data: Vec, file_type: DataType) -> Result<(), wasm_bindgen::JsV mod infer { - use serde::{de::DeserializeSeed, Deserializer}; + use serde::{Deserializer, de::DeserializeSeed}; use schema_analysis::InferredSchema;