From 9fd2a5cf031ccaf870c570b69a540ad0ea102d38 Mon Sep 17 00:00:00 2001 From: Graham Esau Date: Tue, 3 Sep 2024 20:21:59 +0100 Subject: [PATCH] Add missing docs --- schemars/src/generate.rs | 17 +++++++++++++++++ schemars/src/lib.rs | 8 +++++++- schemars/src/transform.rs | 6 ++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/schemars/src/generate.rs b/schemars/src/generate.rs index c4b0035b..375fa08d 100644 --- a/schemars/src/generate.rs +++ b/schemars/src/generate.rs @@ -55,6 +55,9 @@ pub struct SchemaSettings { /// /// Defaults to `false`. pub inline_subschemas: bool, + /// Whether the generated schemas should describe how types are serialized or *de*serialized. + /// + /// Defaults to `Contract::Deserialize`. pub contract: Contract, } @@ -165,18 +168,26 @@ impl SchemaSettings { SchemaGenerator::new(self) } + /// Updates the settings to generate schemas describing how types are **deserialized**. pub fn for_deserialize(mut self) -> Self { self.contract = Contract::Deserialize; self } + /// Updates the settings to generate schemas describing how types are **serialized**. pub fn for_serialize(mut self) -> Self { self.contract = Contract::Serialize; self } } +/// A setting to specify whether generated schemas should describe how types are serialized or +/// *de*serialized. +/// +/// This enum is marked as `#[non_exhaustive]` to reserve space to introduce further variants +/// in future. #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[allow(missing_docs)] #[non_exhaustive] pub enum Contract { Deserialize, @@ -184,10 +195,12 @@ pub enum Contract { } impl Contract { + /// Returns true if `self` is the `Deserialize` contract. pub fn is_deserialize(&self) -> bool { self == &Contract::Deserialize } + /// Returns true if `self` is the `Serialize` contract. pub fn is_serialize(&self) -> bool { self == &Contract::Serialize } @@ -469,6 +482,10 @@ impl SchemaGenerator { Ok(schema) } + /// Returns a reference to the [contract](SchemaSettings::contract) for the settings on this + /// `SchemaGenerator`. + /// + /// This specifies whether generated schemas describe serialize or *de*serialize behaviour. pub fn contract(&self) -> &Contract { &self.settings.contract } diff --git a/schemars/src/lib.rs b/schemars/src/lib.rs index 9bc458e1..b516c6fb 100644 --- a/schemars/src/lib.rs +++ b/schemars/src/lib.rs @@ -1,4 +1,10 @@ -#![deny(unsafe_code, clippy::cargo, clippy::pedantic)] +#![deny( + unsafe_code, + missing_docs, + unused_imports, + clippy::cargo, + clippy::pedantic +)] #![allow( clippy::must_use_candidate, clippy::return_self_not_must_use, diff --git a/schemars/src/transform.rs b/schemars/src/transform.rs index 047a62f3..7d24b5d6 100644 --- a/schemars/src/transform.rs +++ b/schemars/src/transform.rs @@ -389,6 +389,12 @@ impl Transform for ReplacePrefixItems { } } +/// Replaces the `unevaluatedProperties` schema property with the `additionalProperties` property, +/// adding properties from a schema's subschemas to its `properties` where necessary. +/// This also applies to subschemas. +/// +/// This is useful for versions of JSON Schema (e.g. Draft 7) that do not support the +/// `unevaluatedProperties` property. #[derive(Debug, Clone)] pub struct ReplaceUnevaluatedProperties;