Skip to content

Commit

Permalink
Add missing docs
Browse files Browse the repository at this point in the history
  • Loading branch information
GREsau committed Sep 3, 2024
1 parent 72d6e9b commit 9fd2a5c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
17 changes: 17 additions & 0 deletions schemars/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -165,29 +168,39 @@ 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,
Serialize,
}

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
}
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 7 additions & 1 deletion schemars/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 6 additions & 0 deletions schemars/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 9fd2a5c

Please sign in to comment.