From ca7c66eb08b94fb30968c6f129204914d70ae28e Mon Sep 17 00:00:00 2001 From: Graham Esau Date: Fri, 12 Jun 2020 20:43:16 +0100 Subject: [PATCH] v0.8.0-alpha-3 --- CHANGELOG.md | 3 +++ schemars/Cargo.toml | 4 ++-- schemars/src/gen.rs | 12 +++++++++--- schemars_derive/Cargo.toml | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8f3a75..97e0d24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,11 +5,14 @@ - `visit::Visitor`, a trait for updating a schema and all schemas it contains recursively. A `SchemaSettings` can now contain a list of visitors. - `into_object()` method added to `Schema` as a shortcut for `into::()` - Preserve order of schema properties under `preserve_order` feature flag (https://github.com/GREsau/schemars/issues/32) +- `SchemaGenerator::take_definitions()` which behaves similarly to the now-removed `into_definitions()` method but without consuming the generator +- `SchemaGenerator::visitors_mut()` which returns an iterator over a generator's settings's visitors ### Removed (**BREAKING CHANGES**): - `SchemaSettings::bool_schemas` - this has been superseded by the `ReplaceBoolSchemas` visitor - `SchemaSettings::allow_ref_siblings` - this has been superseded by the `RemoveRefSiblings` visitor - `SchemaSettings` no longer implements `PartialEq` +- `SchemaGenerator::into_definitions()` - this has been superseded by `SchemaGenerator::take_definitions()` ### Fixed: - **BREAKING CHANGE** unknown items in `#[schemars(...)]` attributes now cause a compilation error (https://github.com/GREsau/schemars/issues/18) diff --git a/schemars/Cargo.toml b/schemars/Cargo.toml index f3052ed..d43ce77 100644 --- a/schemars/Cargo.toml +++ b/schemars/Cargo.toml @@ -3,7 +3,7 @@ name = "schemars" description = "Generate JSON Schemas from Rust code" homepage = "https://graham.cool/schemars/" repository = "https://github.com/GREsau/schemars" -version = "0.8.0-alpha-2" +version = "0.8.0-alpha-3" authors = ["Graham Esau "] edition = "2018" license = "MIT" @@ -13,7 +13,7 @@ categories = ["encoding"] build = "build.rs" [dependencies] -schemars_derive = { version = "=0.8.0-alpha-2", optional = true, path = "../schemars_derive" } +schemars_derive = { version = "=0.8.0-alpha-3", optional = true, path = "../schemars_derive" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" dyn-clone = "1.0" diff --git a/schemars/src/gen.rs b/schemars/src/gen.rs index a107e77..27616de 100644 --- a/schemars/src/gen.rs +++ b/schemars/src/gen.rs @@ -212,12 +212,18 @@ impl SchemaGenerator { &self.definitions } - /// Consumes `self` and returns the collection of all [referenceable](JsonSchema::is_referenceable) schemas that have been generated. + /// Returns the collection of all [referenceable](JsonSchema::is_referenceable) schemas that have been generated, + /// leaving an empty map in its place. /// /// The keys of the returned `Map` are the [schema names](JsonSchema::schema_name), and the values are the schemas /// themselves. - pub fn into_definitions(self) -> Map { - self.definitions + pub fn take_definitions(&mut self) -> Map { + std::mem::replace(&mut self.definitions, Map::default()) + } + + /// Returns an iterator over the [visitors](SchemaSettings::visitors) being used by this `SchemaGenerator`. + pub fn visitors_mut(&mut self) -> impl Iterator { + self.settings.visitors.iter_mut().map(|v| v.as_mut()) } /// Generates a root JSON Schema for the type `T`. diff --git a/schemars_derive/Cargo.toml b/schemars_derive/Cargo.toml index 499429e..60d79bb 100644 --- a/schemars_derive/Cargo.toml +++ b/schemars_derive/Cargo.toml @@ -3,7 +3,7 @@ name = "schemars_derive" description = "Macros for #[derive(JsonSchema)], for use with schemars" homepage = "https://graham.cool/schemars/" repository = "https://github.com/GREsau/schemars" -version = "0.8.0-alpha-2" +version = "0.8.0-alpha-3" authors = ["Graham Esau "] edition = "2018" license = "MIT"