From 94d75378f69d2503d8d0addfe470e6f09802db26 Mon Sep 17 00:00:00 2001 From: Graham Esau Date: Sat, 20 Mar 2021 22:20:58 +0000 Subject: [PATCH] Add SchemaGenerator::definitions_mut() --- CHANGELOG.md | 3 +++ schemars/src/gen.rs | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b77390a..2e48b2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog ## **In-dev** - [0.8.1] +### Added: +- `SchemaGenerator::definitions_mut()` which returns a mutable reference to the generator's schema definitions + ### Changed: - Deriving JsonSchema on enums now sets `additionalProperties` to false on generated schemas wherever serde doesn't accept unknown properties. This includes non-unit variants of externally tagged enums, and struct-style variants of all enums that have the `deny_unknown_fields` attribute. diff --git a/schemars/src/gen.rs b/schemars/src/gen.rs index ba293e0..58d820b 100644 --- a/schemars/src/gen.rs +++ b/schemars/src/gen.rs @@ -231,6 +231,14 @@ impl SchemaGenerator { &self.definitions } + /// Mutably borrows the collection of all [referenceable](JsonSchema::is_referenceable) schemas that have been generated. + /// + /// The keys of the returned `Map` are the [schema names](JsonSchema::schema_name), and the values are the schemas + /// themselves. + pub fn definitions_mut(&mut self) -> &mut Map { + &mut self.definitions + } + /// Returns the collection of all [referenceable](JsonSchema::is_referenceable) schemas that have been generated, /// leaving an empty map in its place. ///