diff --git a/docs/1.1-attributes.md b/docs/1.1-attributes.md
index 52ddc8a..498eff9 100644
--- a/docs/1.1-attributes.md
+++ b/docs/1.1-attributes.md
@@ -267,7 +267,7 @@ Validator docs: [required](https://github.com/Keats/validator#required) / [requi
-Set on a variant or field to generate this field's schema using the given function. This function must be callable as `fn(&mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema`.
+Set on a variant or field to generate this field's schema using the given function. This function must be callable as `fn(&mut schemars::SchemaGenerator) -> schemars::schema::Schema`.
diff --git a/docs/2-implementing.md b/docs/2-implementing.md
index cb0f18c..06dfa0e 100644
--- a/docs/2-implementing.md
+++ b/docs/2-implementing.md
@@ -60,10 +60,10 @@ The default implementation of this function returns `Self::schema_name()`.
## json_schema
```rust
-fn json_schema(gen: &mut gen::SchemaGenerator) -> Schema;
+fn json_schema(generator: &mut SchemaGenerator) -> Schema;
```
-This function creates the JSON schema itself. The `gen` argument can be used to check the schema generation settings, or to get schemas for other types. If you do need schemas for other types, you should call the `gen.subschema_for::()` method instead of `::json_schema(gen)`, as `subschema_for` can add `T`'s schema to the root schema's `$defs` so that it does not need to be duplicated when used more than once.
+This function creates the JSON schema itself. The `generator` argument can be used to check the schema generation settings, or to get schemas for other types. If you do need schemas for other types, you should call the `generator.subschema_for::()` method instead of `::json_schema(generator)`, as `subschema_for` can add `T`'s schema to the root schema's `$defs` so that it does not need to be duplicated when used more than once.
`json_schema` should not return a `$ref` schema.
diff --git a/docs/3-generating.md b/docs/3-generating.md
index b8cd970..6490169 100644
--- a/docs/3-generating.md
+++ b/docs/3-generating.md
@@ -6,7 +6,7 @@ permalink: /generating/
# Generating Schemas
-The easiest way to generate a schema for a type that implements is to use the [`schema_for!` macro](https://docs.rs/schemars/latest/schemars/macro.schema_for.html), like so:
+The easiest way to generate a schema for a type that implements is to use the [`schema_for!` macro](https://docs.rs/schemars/1.0.0--latest/schemars/macro.schema_for.html), like so:
```rust
let my_schema = schema_for!(MyStruct);
@@ -14,10 +14,10 @@ let my_schema = schema_for!(MyStruct);
This will create a schema that conforms to [JSON Schema 2020-12](https://json-schema.org/specification-links#2020-12), but this is liable to change in a future version of Schemars if support for other JSON Schema versions is added.
-If you want more control over how the schema is generated, you can use the [`gen` module](https://docs.rs/schemars/latest/schemars/gen/). There are two main types in this module:
+If you want more control over how the schema is generated, you can use the [`generate` module](https://docs.rs/schemars/1.0.0--latest/schemars/generate/). There are two main types in this module:
-- [`SchemaSettings`](https://docs.rs/schemars/latest/schemars/gen/struct.SchemaSettings.html), which defines what JSON Schema features should be used when generating schemas (for example, how `Option`s should be represented).
-- [`SchemaGenerator`](https://docs.rs/schemars/latest/schemars/gen/struct.SchemaGenerator.html), which manages the generation of a schema document.
+- [`SchemaSettings`](https://docs.rs/schemars/1.0.0--latest/schemars/generate/struct.SchemaSettings.html), which defines what JSON Schema features should be used when generating schemas (for example, how `Option`s should be represented).
+- [`SchemaGenerator`](https://docs.rs/schemars/1.0.0--latest/schemars/generate/struct.SchemaGenerator.html), which manages the generation of a schema document.
For example, to generate a schema that conforms to [JSON Schema Draft 7](https://json-schema.org/specification-links.html#draft-7):
@@ -30,7 +30,7 @@ See the API documentation for more info on how to use those types for custom sch
## Schema from Example Value
-If you want a schema for a type that can't/doesn't implement `JsonSchema`, but does implement `serde::Serialize`, then you can generate a JSON schema from a value of that type using the [`schema_for_value!` macro](https://docs.rs/schemars/latest/schemars/macro.schema_for_value.html). However, this schema will generally be less precise than if the type implemented `JsonSchema` - particularly when it involves enums, since schemars will not make any assumptions about the structure of an enum based on a single variant.
+If you want a schema for a type that can't/doesn't implement `JsonSchema`, but does implement `serde::Serialize`, then you can generate a JSON schema from a value of that type using the [`schema_for_value!` macro](https://docs.rs/schemars/1.0.0--latest/schemars/macro.schema_for_value.html). However, this schema will generally be less precise than if the type implemented `JsonSchema` - particularly when it involves enums, since schemars will not make any assumptions about the structure of an enum based on a single variant.
```rust
let value = MyStruct { foo = 123 };
diff --git a/docs/_includes/examples/custom_serialization.rs b/docs/_includes/examples/custom_serialization.rs
index c32203f..8e2a695 100644
--- a/docs/_includes/examples/custom_serialization.rs
+++ b/docs/_includes/examples/custom_serialization.rs
@@ -19,8 +19,8 @@ pub struct MyStruct {
pub bool_normal: bool,
}
-fn make_custom_schema(gen: &mut SchemaGenerator) -> Schema {
- let mut schema = String::json_schema(gen);
+fn make_custom_schema(generator: &mut SchemaGenerator) -> Schema {
+ let mut schema = String::json_schema(generator);
schema
.ensure_object()
.insert("format".into(), "boolean".into());
diff --git a/docs/_includes/examples/custom_settings.rs b/docs/_includes/examples/custom_settings.rs
index 335daf3..7858720 100644
--- a/docs/_includes/examples/custom_settings.rs
+++ b/docs/_includes/examples/custom_settings.rs
@@ -1,4 +1,4 @@
-use schemars::{gen::SchemaSettings, JsonSchema};
+use schemars::{generate::SchemaSettings, JsonSchema};
#[derive(JsonSchema)]
pub struct MyStruct {
@@ -18,7 +18,7 @@ fn main() {
s.option_nullable = true;
s.option_add_null_type = false;
});
- let gen = settings.into_generator();
- let schema = gen.into_root_schema_for::();
+ let generator = settings.into_generator();
+ let schema = generator.into_root_schema_for::();
println!("{}", serde_json::to_string_pretty(&schema).unwrap());
}
diff --git a/docs/examples/4-custom_settings.md b/docs/examples/4-custom_settings.md
index 7b85f65..f14cbe3 100644
--- a/docs/examples/4-custom_settings.md
+++ b/docs/examples/4-custom_settings.md
@@ -7,6 +7,6 @@ summary: Generating a schema using custom settings which changes how Option i
# Custom Schema Settings
-The `gen` module allows you to customise how schemas are generated. For example, the default behaviour for `Option` is to include `null` in the schema's `type`s, but we can instead add a `nullable` property to its schema:
+The `generate` module allows you to customise how schemas are generated. For example, the default behaviour for `Option` is to include `null` in the schema's `type`s, but we can instead add a `nullable` property to its schema:
{% include example.md name="custom_settings" %}
diff --git a/docs/index.md b/docs/index.md
index ad71e78..0601c21 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -7,7 +7,7 @@ nav_order: 1
Schemars is a library to generate JSON Schema documents from Rust data structures.
-This is built on Rust's trait system - any type which implements the [`JsonSchema`](https://docs.rs/schemars/latest/schemars/trait.JsonSchema.html) trait can have a JSON Schema generated describing that type. Schemars implements this on many standard library types, and provides a derive macro to automatically implement it on custom types.
+This is built on Rust's trait system - any type which implements the [`JsonSchema`](https://docs.rs/schemars/1.0.0--latest/schemars/trait.JsonSchema.html) trait can have a JSON Schema generated describing that type. Schemars implements this on many standard library types, and provides a derive macro to automatically implement it on custom types.
One of the main aims of this library is compatibility with [Serde](https://github.com/serde-rs/serde). Any generated schema _should_ match how [serde_json](https://github.com/serde-rs/json) would serialize/deserialize to/from JSON. To support this, Schemars will check for any `#[serde(...)]` attributes on types that derive `JsonSchema`, and adjust the generated schema accordingly.
diff --git a/schemars/examples/custom_serialization.rs b/schemars/examples/custom_serialization.rs
index c32203f..8e2a695 100644
--- a/schemars/examples/custom_serialization.rs
+++ b/schemars/examples/custom_serialization.rs
@@ -19,8 +19,8 @@ pub struct MyStruct {
pub bool_normal: bool,
}
-fn make_custom_schema(gen: &mut SchemaGenerator) -> Schema {
- let mut schema = String::json_schema(gen);
+fn make_custom_schema(generator: &mut SchemaGenerator) -> Schema {
+ let mut schema = String::json_schema(generator);
schema
.ensure_object()
.insert("format".into(), "boolean".into());
diff --git a/schemars/examples/custom_settings.rs b/schemars/examples/custom_settings.rs
index 335daf3..7858720 100644
--- a/schemars/examples/custom_settings.rs
+++ b/schemars/examples/custom_settings.rs
@@ -1,4 +1,4 @@
-use schemars::{gen::SchemaSettings, JsonSchema};
+use schemars::{generate::SchemaSettings, JsonSchema};
#[derive(JsonSchema)]
pub struct MyStruct {
@@ -18,7 +18,7 @@ fn main() {
s.option_nullable = true;
s.option_add_null_type = false;
});
- let gen = settings.into_generator();
- let schema = gen.into_root_schema_for::();
+ let generator = settings.into_generator();
+ let schema = generator.into_root_schema_for::();
println!("{}", serde_json::to_string_pretty(&schema).unwrap());
}
diff --git a/schemars/src/_private.rs b/schemars/src/_private.rs
index 4d70bf3..db0df0e 100644
--- a/schemars/src/_private.rs
+++ b/schemars/src/_private.rs
@@ -5,10 +5,10 @@ use serde_json::{json, map::Entry, Map, Value};
// Helper for generating schemas for flattened `Option` fields.
pub fn json_schema_for_flatten(
- gen: &mut SchemaGenerator,
+ generator: &mut SchemaGenerator,
required: bool,
) -> Schema {
- let mut schema = T::_schemars_private_non_optional_json_schema(gen);
+ let mut schema = T::_schemars_private_non_optional_json_schema(generator);
if T::_schemars_private_is_option() && !required {
if let Some(object) = schema.as_object_mut() {
diff --git a/schemars/src/gen.rs b/schemars/src/generate.rs
similarity index 95%
rename from schemars/src/gen.rs
rename to schemars/src/generate.rs
index 98dd7b3..a229f59 100644
--- a/schemars/src/gen.rs
+++ b/schemars/src/generate.rs
@@ -127,13 +127,13 @@ impl SchemaSettings {
///
/// # Example
/// ```
- /// use schemars::gen::{SchemaGenerator, SchemaSettings};
+ /// use schemars::generate::{SchemaGenerator, SchemaSettings};
///
/// let settings = SchemaSettings::default().with(|s| {
/// s.option_nullable = true;
/// s.option_add_null_type = false;
/// });
- /// let gen = settings.into_generator();
+ /// let generator = settings.into_generator();
/// ```
pub fn with(mut self, configure_fn: impl FnOnce(&mut Self)) -> Self {
configure_fn(&mut self);
@@ -163,8 +163,8 @@ impl SchemaSettings {
/// foo: i32,
/// }
///
-/// let gen = SchemaGenerator::default();
-/// let schema = gen.into_root_schema_for::();
+/// let generator = SchemaGenerator::default();
+/// let schema = generator.into_root_schema_for::();
/// ```
#[derive(Debug, Default)]
pub struct SchemaGenerator {
@@ -208,8 +208,8 @@ impl SchemaGenerator {
/// ```
/// use schemars::SchemaGenerator;
///
- /// let gen = SchemaGenerator::default();
- /// let settings = gen.settings();
+ /// let generator = SchemaGenerator::default();
+ /// let settings = generator.settings();
///
/// assert_eq!(settings.option_add_null_type, true);
/// ```
@@ -361,7 +361,7 @@ impl SchemaGenerator {
value: &T,
) -> Result {
let mut schema = value.serialize(crate::ser::Serializer {
- gen: self,
+ generator: self,
include_title: true,
})?;
@@ -392,7 +392,7 @@ impl SchemaGenerator {
value: &T,
) -> Result {
let mut schema = value.serialize(crate::ser::Serializer {
- gen: &mut self,
+ generator: &mut self,
include_title: true,
})?;
@@ -415,28 +415,32 @@ impl SchemaGenerator {
fn json_schema_internal(&mut self, id: CowStr) -> Schema {
struct PendingSchemaState<'a> {
- gen: &'a mut SchemaGenerator,
+ generator: &'a mut SchemaGenerator,
id: CowStr,
did_add: bool,
}
impl<'a> PendingSchemaState<'a> {
- fn new(gen: &'a mut SchemaGenerator, id: CowStr) -> Self {
- let did_add = gen.pending_schema_ids.insert(id.clone());
- Self { gen, id, did_add }
+ fn new(generator: &'a mut SchemaGenerator, id: CowStr) -> Self {
+ let did_add = generator.pending_schema_ids.insert(id.clone());
+ Self {
+ generator,
+ id,
+ did_add,
+ }
}
}
impl Drop for PendingSchemaState<'_> {
fn drop(&mut self) {
if self.did_add {
- self.gen.pending_schema_ids.remove(&self.id);
+ self.generator.pending_schema_ids.remove(&self.id);
}
}
}
let pss = PendingSchemaState::new(self, id);
- T::json_schema(pss.gen)
+ T::json_schema(pss.generator)
}
fn add_definitions(
@@ -514,7 +518,7 @@ fn json_pointer_mut<'a>(
/// # Example
/// ```
/// use schemars::transform::Transform;
-/// use schemars::gen::GenTransform;
+/// use schemars::generate::GenTransform;
///
/// #[derive(Debug, Clone)]
/// struct MyTransform;
@@ -534,7 +538,7 @@ pub trait GenTransform: Transform + DynClone + Any + Send {
/// # Example
/// To remove a specific transform from an instance of `SchemaSettings`:
/// ```
- /// use schemars::gen::SchemaSettings;
+ /// use schemars::generate::SchemaSettings;
/// use schemars::transform::ReplaceBoolSchemas;
///
/// let mut settings = SchemaSettings::openapi3();
@@ -553,7 +557,7 @@ pub trait GenTransform: Transform + DynClone + Any + Send {
/// # Example
/// To modify a specific transform in an instance of `SchemaSettings`:
/// ```
- /// use schemars::gen::SchemaSettings;
+ /// use schemars::generate::SchemaSettings;
/// use schemars::transform::ReplaceBoolSchemas;
///
/// let mut settings = SchemaSettings::openapi3();
diff --git a/schemars/src/json_schema_impls/array.rs b/schemars/src/json_schema_impls/array.rs
index 18e8b76..c17fbba 100644
--- a/schemars/src/json_schema_impls/array.rs
+++ b/schemars/src/json_schema_impls/array.rs
@@ -1,5 +1,5 @@
+use crate::SchemaGenerator;
use crate::_alloc_prelude::*;
-use crate::gen::SchemaGenerator;
use crate::{json_schema, JsonSchema, Schema};
use alloc::borrow::Cow;
@@ -37,10 +37,10 @@ macro_rules! array_impls {
format!("[{}; {}]", $len, T::schema_id()).into()
}
- fn json_schema(gen: &mut SchemaGenerator) -> Schema {
+ fn json_schema(generator: &mut SchemaGenerator) -> Schema {
json_schema!({
"type": "array",
- "items": serde_json::Value::from(gen.subschema_for::()),
+ "items": serde_json::Value::from(generator.subschema_for::()),
"minItems": $len,
"maxItems": $len,
})
diff --git a/schemars/src/json_schema_impls/arrayvec07.rs b/schemars/src/json_schema_impls/arrayvec07.rs
index a5511ab..0d7270f 100644
--- a/schemars/src/json_schema_impls/arrayvec07.rs
+++ b/schemars/src/json_schema_impls/arrayvec07.rs
@@ -1,5 +1,5 @@
+use crate::SchemaGenerator;
use crate::_alloc_prelude::*;
-use crate::gen::SchemaGenerator;
use crate::{json_schema, JsonSchema, Schema};
use arrayvec07::{ArrayString, ArrayVec};
@@ -17,10 +17,10 @@ where
format!("Array_up_to_size_{}_of_{}", CAP, T::schema_name()).into()
}
- fn json_schema(gen: &mut SchemaGenerator) -> Schema {
+ fn json_schema(generator: &mut SchemaGenerator) -> Schema {
json_schema!({
"type": "array",
- "items": gen.subschema_for::(),
+ "items": generator.subschema_for::(),
"maxItems": CAP
})
}
diff --git a/schemars/src/json_schema_impls/chrono04.rs b/schemars/src/json_schema_impls/chrono04.rs
index 994d4b8..a153aca 100644
--- a/schemars/src/json_schema_impls/chrono04.rs
+++ b/schemars/src/json_schema_impls/chrono04.rs
@@ -1,4 +1,4 @@
-use crate::gen::SchemaGenerator;
+use crate::SchemaGenerator;
use crate::{json_schema, JsonSchema, Schema};
use alloc::borrow::Cow;
use chrono04::prelude::*;
diff --git a/schemars/src/json_schema_impls/core.rs b/schemars/src/json_schema_impls/core.rs
index 4e2c9d6..07fbce5 100644
--- a/schemars/src/json_schema_impls/core.rs
+++ b/schemars/src/json_schema_impls/core.rs
@@ -1,5 +1,5 @@
+use crate::SchemaGenerator;
use crate::_alloc_prelude::*;
-use crate::gen::SchemaGenerator;
use crate::{json_schema, JsonSchema, Schema};
use alloc::borrow::Cow;
use core::ops::{Bound, Range, RangeInclusive};
@@ -16,10 +16,10 @@ impl JsonSchema for Option {
format!("Option<{}>", T::schema_id()).into()
}
- fn json_schema(gen: &mut SchemaGenerator) -> Schema {
- let mut schema = gen.subschema_for::();
+ fn json_schema(generator: &mut SchemaGenerator) -> Schema {
+ let mut schema = generator.subschema_for::();
- if gen.settings().option_add_null_type {
+ if generator.settings().option_add_null_type {
schema = match schema.try_to_object() {
Ok(mut obj) => {
let instance_type = obj.get_mut("type");
@@ -43,17 +43,17 @@ impl JsonSchema for Option {
_ => json_schema!({
"anyOf": [
obj,
- <()>::json_schema(gen)
+ <()>::json_schema(generator)
]
}),
}
}
Err(true) => true.into(),
- Err(false) => <()>::json_schema(gen),
+ Err(false) => <()>::json_schema(generator),
}
}
- if gen.settings().option_nullable {
+ if generator.settings().option_nullable {
schema
.ensure_object()
.insert("nullable".into(), true.into());
@@ -62,8 +62,8 @@ impl JsonSchema for Option {
schema
}
- fn _schemars_private_non_optional_json_schema(gen: &mut SchemaGenerator) -> Schema {
- T::_schemars_private_non_optional_json_schema(gen)
+ fn _schemars_private_non_optional_json_schema(generator: &mut SchemaGenerator) -> Schema {
+ T::_schemars_private_non_optional_json_schema(generator)
}
fn _schemars_private_is_option() -> bool {
@@ -80,20 +80,20 @@ impl JsonSchema for Result {
format!("Result<{}, {}>", T::schema_id(), E::schema_id()).into()
}
- fn json_schema(gen: &mut SchemaGenerator) -> Schema {
+ fn json_schema(generator: &mut SchemaGenerator) -> Schema {
json_schema!({
"oneOf": [
{
"type": "object",
"properties": {
- "Ok": gen.subschema_for::()
+ "Ok": generator.subschema_for::()
},
"required": ["Ok"]
},
{
"type": "object",
"properties": {
- "Err": gen.subschema_for::()
+ "Err": generator.subschema_for::()
},
"required": ["Err"]
}
@@ -111,20 +111,20 @@ impl JsonSchema for Bound {
format!("Bound<{}>", T::schema_id()).into()
}
- fn json_schema(gen: &mut SchemaGenerator) -> Schema {
+ fn json_schema(generator: &mut SchemaGenerator) -> Schema {
json_schema!({
"oneOf": [
{
"type": "object",
"properties": {
- "Included": gen.subschema_for::()
+ "Included": generator.subschema_for::()
},
"required": ["Included"]
},
{
"type": "object",
"properties": {
- "Excluded": gen.subschema_for::()
+ "Excluded": generator.subschema_for::()
},
"required": ["Excluded"]
},
@@ -146,8 +146,8 @@ impl JsonSchema for Range {
format!("Range<{}>", T::schema_id()).into()
}
- fn json_schema(gen: &mut SchemaGenerator) -> Schema {
- let subschema = gen.subschema_for::();
+ fn json_schema(generator: &mut SchemaGenerator) -> Schema {
+ let subschema = generator.subschema_for::();
json_schema!({
"type": "object",
"properties": {
diff --git a/schemars/src/json_schema_impls/decimal.rs b/schemars/src/json_schema_impls/decimal.rs
index 0f55ba9..afba4ab 100644
--- a/schemars/src/json_schema_impls/decimal.rs
+++ b/schemars/src/json_schema_impls/decimal.rs
@@ -1,4 +1,4 @@
-use crate::gen::SchemaGenerator;
+use crate::SchemaGenerator;
use crate::{json_schema, JsonSchema, Schema};
use alloc::borrow::Cow;
diff --git a/schemars/src/json_schema_impls/either1.rs b/schemars/src/json_schema_impls/either1.rs
index 3822faa..ba8a706 100644
--- a/schemars/src/json_schema_impls/either1.rs
+++ b/schemars/src/json_schema_impls/either1.rs
@@ -1,5 +1,5 @@
use crate::_alloc_prelude::*;
-use crate::gen::SchemaGenerator;
+use crate::SchemaGenerator;
use crate::{json_schema, JsonSchema, Schema};
use alloc::borrow::Cow;
use either1::Either;
@@ -15,9 +15,9 @@ impl JsonSchema for Either {
format!("either::Either<{}, {}>", L::schema_id(), R::schema_id()).into()
}
- fn json_schema(gen: &mut SchemaGenerator) -> Schema {
+ fn json_schema(generator: &mut SchemaGenerator) -> Schema {
json_schema!({
- "anyOf": [gen.subschema_for::(), gen.subschema_for::()],
+ "anyOf": [generator.subschema_for::(), generator.subschema_for::()],
})
}
}
diff --git a/schemars/src/json_schema_impls/ffi.rs b/schemars/src/json_schema_impls/ffi.rs
index 524c49f..cf2efe5 100644
--- a/schemars/src/json_schema_impls/ffi.rs
+++ b/schemars/src/json_schema_impls/ffi.rs
@@ -1,5 +1,5 @@
+use crate::SchemaGenerator;
use crate::_alloc_prelude::*;
-use crate::gen::SchemaGenerator;
use crate::{json_schema, JsonSchema, Schema};
use alloc::borrow::Cow;
use std::ffi::{CStr, CString, OsStr, OsString};
@@ -13,20 +13,20 @@ impl JsonSchema for OsString {
"std::ffi::OsString".into()
}
- fn json_schema(gen: &mut SchemaGenerator) -> Schema {
+ fn json_schema(generator: &mut SchemaGenerator) -> Schema {
json_schema!({
"oneOf": [
{
"type": "object",
"properties": {
- "Unix": >::json_schema(gen)
+ "Unix": >::json_schema(generator)
},
"required": ["Unix"]
},
{
"type": "object",
"properties": {
- "Windows": >::json_schema(gen)
+ "Windows": >::json_schema(generator)
},
"required": ["Windows"]
},
diff --git a/schemars/src/json_schema_impls/maps.rs b/schemars/src/json_schema_impls/maps.rs
index af43a43..f199f4a 100644
--- a/schemars/src/json_schema_impls/maps.rs
+++ b/schemars/src/json_schema_impls/maps.rs
@@ -1,5 +1,5 @@
use crate::_alloc_prelude::*;
-use crate::gen::SchemaGenerator;
+use crate::SchemaGenerator;
use crate::{json_schema, JsonSchema, Schema};
use alloc::borrow::Cow;
@@ -19,10 +19,10 @@ macro_rules! map_impl {
format!("Map<{}>", V::schema_id()).into()
}
- fn json_schema(gen: &mut SchemaGenerator) -> Schema {
+ fn json_schema(generator: &mut SchemaGenerator) -> Schema {
json_schema!({
"type": "object",
- "additionalProperties": gen.subschema_for::(),
+ "additionalProperties": generator.subschema_for::(),
})
}
}
diff --git a/schemars/src/json_schema_impls/mod.rs b/schemars/src/json_schema_impls/mod.rs
index a0287f7..1921a6a 100644
--- a/schemars/src/json_schema_impls/mod.rs
+++ b/schemars/src/json_schema_impls/mod.rs
@@ -21,12 +21,12 @@ macro_rules! forward_impl {
<$target>::schema_id()
}
- fn json_schema(gen: &mut $crate::gen::SchemaGenerator) -> $crate::Schema {
- <$target>::json_schema(gen)
+ fn json_schema(generator: &mut $crate::SchemaGenerator) -> $crate::Schema {
+ <$target>::json_schema(generator)
}
- fn _schemars_private_non_optional_json_schema(gen: &mut $crate::gen::SchemaGenerator) -> $crate::Schema {
- <$target>::_schemars_private_non_optional_json_schema(gen)
+ fn _schemars_private_non_optional_json_schema(generator: &mut $crate::SchemaGenerator) -> $crate::Schema {
+ <$target>::_schemars_private_non_optional_json_schema(generator)
}
fn _schemars_private_is_option() -> bool {
diff --git a/schemars/src/json_schema_impls/nonzero_signed.rs b/schemars/src/json_schema_impls/nonzero_signed.rs
index 37fef86..c5b3e84 100644
--- a/schemars/src/json_schema_impls/nonzero_signed.rs
+++ b/schemars/src/json_schema_impls/nonzero_signed.rs
@@ -1,5 +1,5 @@
+use crate::SchemaGenerator;
use crate::_alloc_prelude::*;
-use crate::gen::SchemaGenerator;
use crate::{JsonSchema, Schema};
use alloc::borrow::Cow;
use core::num::*;
@@ -17,8 +17,8 @@ macro_rules! nonzero_unsigned_impl {
stringify!(std::num::$type).into()
}
- fn json_schema(gen: &mut SchemaGenerator) -> Schema {
- let mut schema = <$primitive>::json_schema(gen);
+ fn json_schema(generator: &mut SchemaGenerator) -> Schema {
+ let mut schema = <$primitive>::json_schema(generator);
let object = schema.ensure_object();
object.insert("not".to_owned(), serde_json::json!({
"const": 0
diff --git a/schemars/src/json_schema_impls/nonzero_unsigned.rs b/schemars/src/json_schema_impls/nonzero_unsigned.rs
index 8c07fb3..c6711ab 100644
--- a/schemars/src/json_schema_impls/nonzero_unsigned.rs
+++ b/schemars/src/json_schema_impls/nonzero_unsigned.rs
@@ -1,7 +1,7 @@
-use crate::_alloc_prelude::*;
-use crate::gen::SchemaGenerator;
use crate::JsonSchema;
use crate::Schema;
+use crate::SchemaGenerator;
+use crate::_alloc_prelude::*;
use alloc::borrow::Cow;
use core::num::*;
@@ -18,8 +18,8 @@ macro_rules! nonzero_unsigned_impl {
stringify!(std::num::$type).into()
}
- fn json_schema(gen: &mut SchemaGenerator) -> Schema {
- let mut schema = <$primitive>::json_schema(gen);
+ fn json_schema(generator: &mut SchemaGenerator) -> Schema {
+ let mut schema = <$primitive>::json_schema(generator);
let object = schema.ensure_object();
object.insert("minimum".to_owned(), 1.into());
schema
diff --git a/schemars/src/json_schema_impls/primitives.rs b/schemars/src/json_schema_impls/primitives.rs
index 4b87961..c8d509c 100644
--- a/schemars/src/json_schema_impls/primitives.rs
+++ b/schemars/src/json_schema_impls/primitives.rs
@@ -1,5 +1,5 @@
use crate::_alloc_prelude::*;
-use crate::gen::SchemaGenerator;
+use crate::SchemaGenerator;
use crate::{json_schema, JsonSchema, Schema};
use alloc::borrow::Cow;
diff --git a/schemars/src/json_schema_impls/semver1.rs b/schemars/src/json_schema_impls/semver1.rs
index 43e0f3a..1869fa9 100644
--- a/schemars/src/json_schema_impls/semver1.rs
+++ b/schemars/src/json_schema_impls/semver1.rs
@@ -1,4 +1,4 @@
-use crate::gen::SchemaGenerator;
+use crate::SchemaGenerator;
use crate::{json_schema, JsonSchema, Schema};
use alloc::borrow::Cow;
use semver1::Version;
diff --git a/schemars/src/json_schema_impls/sequences.rs b/schemars/src/json_schema_impls/sequences.rs
index 8241dac..4af62a2 100644
--- a/schemars/src/json_schema_impls/sequences.rs
+++ b/schemars/src/json_schema_impls/sequences.rs
@@ -1,5 +1,5 @@
+use crate::SchemaGenerator;
use crate::_alloc_prelude::*;
-use crate::gen::SchemaGenerator;
use crate::{json_schema, JsonSchema, Schema};
use alloc::borrow::Cow;
@@ -19,10 +19,10 @@ macro_rules! seq_impl {
format!("[{}]", T::schema_id()).into()
}
- fn json_schema(gen: &mut SchemaGenerator) -> Schema {
+ fn json_schema(generator: &mut SchemaGenerator) -> Schema {
json_schema!({
"type": "array",
- "items": gen.subschema_for::(),
+ "items": generator.subschema_for::(),
})
}
}
@@ -45,11 +45,11 @@ macro_rules! set_impl {
format!("Set<{}>", T::schema_id()).into()
}
- fn json_schema(gen: &mut SchemaGenerator) -> Schema {
+ fn json_schema(generator: &mut SchemaGenerator) -> Schema {
json_schema!({
"type": "array",
"uniqueItems": true,
- "items": gen.subschema_for::(),
+ "items": generator.subschema_for::(),
})
}
}
diff --git a/schemars/src/json_schema_impls/serdejson.rs b/schemars/src/json_schema_impls/serdejson.rs
index 25f6e78..e062b37 100644
--- a/schemars/src/json_schema_impls/serdejson.rs
+++ b/schemars/src/json_schema_impls/serdejson.rs
@@ -1,5 +1,5 @@
use crate::_alloc_prelude::*;
-use crate::gen::SchemaGenerator;
+use crate::SchemaGenerator;
use crate::{json_schema, JsonSchema, Schema};
use alloc::borrow::Cow;
use alloc::collections::BTreeMap;
diff --git a/schemars/src/json_schema_impls/std_time.rs b/schemars/src/json_schema_impls/std_time.rs
index 1766e93..22b3fd9 100644
--- a/schemars/src/json_schema_impls/std_time.rs
+++ b/schemars/src/json_schema_impls/std_time.rs
@@ -1,4 +1,4 @@
-use crate::gen::SchemaGenerator;
+use crate::SchemaGenerator;
use crate::{json_schema, JsonSchema, Schema};
use alloc::borrow::Cow;
@@ -11,13 +11,13 @@ impl JsonSchema for core::time::Duration {
"std::time::Duration".into()
}
- fn json_schema(gen: &mut SchemaGenerator) -> Schema {
+ fn json_schema(generator: &mut SchemaGenerator) -> Schema {
json_schema!({
"type": "object",
"required": ["secs", "nanos"],
"properties": {
- "secs": u64::json_schema(gen),
- "nanos": u32::json_schema(gen),
+ "secs": u64::json_schema(generator),
+ "nanos": u32::json_schema(generator),
}
})
}
@@ -33,13 +33,13 @@ impl JsonSchema for std::time::SystemTime {
"std::time::SystemTime".into()
}
- fn json_schema(gen: &mut SchemaGenerator) -> Schema {
+ fn json_schema(generator: &mut SchemaGenerator) -> Schema {
json_schema!({
"type": "object",
"required": ["secs_since_epoch", "nanos_since_epoch"],
"properties": {
- "secs_since_epoch": u64::json_schema(gen),
- "nanos_since_epoch": u32::json_schema(gen),
+ "secs_since_epoch": u64::json_schema(generator),
+ "nanos_since_epoch": u32::json_schema(generator),
}
})
}
diff --git a/schemars/src/json_schema_impls/tuple.rs b/schemars/src/json_schema_impls/tuple.rs
index bb57c0e..88cc0ff 100644
--- a/schemars/src/json_schema_impls/tuple.rs
+++ b/schemars/src/json_schema_impls/tuple.rs
@@ -1,5 +1,5 @@
+use crate::SchemaGenerator;
use crate::_alloc_prelude::*;
-use crate::gen::SchemaGenerator;
use crate::{json_schema, JsonSchema, Schema};
use alloc::borrow::Cow;
@@ -23,11 +23,11 @@ macro_rules! tuple_impls {
id.into()
}
- fn json_schema(gen: &mut SchemaGenerator) -> Schema {
+ fn json_schema(generator: &mut SchemaGenerator) -> Schema {
json_schema!({
"type": "array",
"prefixItems": [
- $(gen.subschema_for::<$name>()),+
+ $(generator.subschema_for::<$name>()),+
],
"minItems": $len,
"maxItems": $len,
diff --git a/schemars/src/json_schema_impls/url2.rs b/schemars/src/json_schema_impls/url2.rs
index d34e949..6fcaceb 100644
--- a/schemars/src/json_schema_impls/url2.rs
+++ b/schemars/src/json_schema_impls/url2.rs
@@ -1,4 +1,4 @@
-use crate::gen::SchemaGenerator;
+use crate::SchemaGenerator;
use crate::{json_schema, JsonSchema, Schema};
use alloc::borrow::Cow;
use url2::Url;
diff --git a/schemars/src/json_schema_impls/uuid1.rs b/schemars/src/json_schema_impls/uuid1.rs
index 2628f00..677c279 100644
--- a/schemars/src/json_schema_impls/uuid1.rs
+++ b/schemars/src/json_schema_impls/uuid1.rs
@@ -1,4 +1,4 @@
-use crate::gen::SchemaGenerator;
+use crate::SchemaGenerator;
use crate::{json_schema, JsonSchema, Schema};
use alloc::borrow::Cow;
use uuid1::Uuid;
diff --git a/schemars/src/lib.rs b/schemars/src/lib.rs
index a556182..252609c 100644
--- a/schemars/src/lib.rs
+++ b/schemars/src/lib.rs
@@ -24,7 +24,7 @@ mod macros;
/// outside of `schemars`, and should not be considered part of the public API.
#[doc(hidden)]
pub mod _private;
-pub mod gen;
+pub mod generate;
pub mod transform;
#[cfg(feature = "schemars_derive")]
@@ -40,7 +40,7 @@ pub extern crate alloc as _alloc;
#[doc(hidden)]
pub extern crate serde_json as _serde_json;
-pub use gen::SchemaGenerator;
+pub use generate::SchemaGenerator;
pub use schema::Schema;
mod _alloc_prelude {
@@ -52,6 +52,17 @@ mod _alloc_prelude {
pub use alloc::vec::Vec;
}
+#[deprecated = "Only included for backward-compatibility - use the `schemars::generate` module instead."]
+#[doc(hidden)]
+pub mod r#gen {
+ #[deprecated = "Only included for backward-compatibility - use `schemars::SchemaGenerator` or `schemars::generate::SchemaGenerator` instead."]
+ pub type SchemaGenerator = crate::generate::SchemaGenerator;
+ #[deprecated = "Only included for backward-compatibility - use `schemars::generate::SchemaSettings` instead."]
+ pub type SchemaSettings = crate::generate::SchemaSettings;
+ #[deprecated = "Only included for backward-compatibility - use `schemars::generate::GenTransform` instead."]
+ pub use crate::generate::GenTransform;
+}
+
/// A type which can be described as a JSON Schema document.
///
/// This is implemented for many Rust primitive and standard library types.
@@ -166,12 +177,12 @@ pub trait JsonSchema {
/// add them to the [`SchemaGenerator`]'s schema definitions.
///
/// This should not return a `$ref` schema.
- fn json_schema(gen: &mut SchemaGenerator) -> Schema;
+ fn json_schema(generator: &mut SchemaGenerator) -> Schema;
// TODO document and bring into public API?
#[doc(hidden)]
- fn _schemars_private_non_optional_json_schema(gen: &mut SchemaGenerator) -> Schema {
- Self::json_schema(gen)
+ fn _schemars_private_non_optional_json_schema(generator: &mut SchemaGenerator) -> Schema {
+ Self::json_schema(generator)
}
// TODO document and bring into public API?
diff --git a/schemars/src/schema.rs b/schemars/src/schema.rs
index 5b7dcd8..96be662 100644
--- a/schemars/src/schema.rs
+++ b/schemars/src/schema.rs
@@ -242,7 +242,7 @@ impl crate::JsonSchema for Schema {
"schemars::Schema".into()
}
- fn json_schema(_: &mut crate::gen::SchemaGenerator) -> Schema {
+ fn json_schema(_: &mut crate::SchemaGenerator) -> Schema {
crate::json_schema!({
"type": ["object", "boolean"]
})
diff --git a/schemars/src/ser.rs b/schemars/src/ser.rs
index 0aefc6b..4b4117f 100644
--- a/schemars/src/ser.rs
+++ b/schemars/src/ser.rs
@@ -4,23 +4,23 @@ use core::fmt::Display;
use serde_json::{Error, Map, Value};
pub(crate) struct Serializer<'a> {
- pub(crate) gen: &'a mut SchemaGenerator,
+ pub(crate) generator: &'a mut SchemaGenerator,
pub(crate) include_title: bool,
}
pub(crate) struct SerializeSeq<'a> {
- gen: &'a mut SchemaGenerator,
+ generator: &'a mut SchemaGenerator,
items: Option,
}
pub(crate) struct SerializeTuple<'a> {
- gen: &'a mut SchemaGenerator,
+ generator: &'a mut SchemaGenerator,
items: Vec,
title: &'static str,
}
pub(crate) struct SerializeMap<'a> {
- gen: &'a mut SchemaGenerator,
+ generator: &'a mut SchemaGenerator,
properties: Map,
current_key: Option,
title: &'static str,
@@ -29,7 +29,7 @@ pub(crate) struct SerializeMap<'a> {
macro_rules! forward_to_subschema_for {
($fn:ident, $ty:ty) => {
fn $fn(self, _value: $ty) -> Result {
- Ok(self.gen.subschema_for::<$ty>())
+ Ok(self.generator.subschema_for::<$ty>())
}
};
}
@@ -78,7 +78,7 @@ impl<'a> serde::Serializer for Serializer<'a> {
where
T: Display,
{
- Ok(self.gen.subschema_for::<&str>())
+ Ok(self.generator.subschema_for::<&str>())
}
fn collect_map(self, iter: I) -> Result
@@ -95,7 +95,7 @@ impl<'a> serde::Serializer for Serializer<'a> {
}
let schema = v.serialize(Serializer {
- gen: self.gen,
+ generator: self.generator,
include_title: false,
})?;
Ok(match &acc {
@@ -113,7 +113,7 @@ impl<'a> serde::Serializer for Serializer<'a> {
}
fn serialize_none(self) -> Result {
- Ok(self.gen.subschema_for::