Do not implement JsonSchema for internal types by default.
It will be implemented only if the derive_json_schema feature is enabled
This commit is contained in:
parent
f8737be9c4
commit
5c307b92fb
2 changed files with 30 additions and 13 deletions
|
@ -19,9 +19,16 @@ chrono = { version = "0.4", default-features = false, optional = true }
|
|||
[dev-dependencies]
|
||||
pretty_assertions = "0.6.1"
|
||||
|
||||
[features]
|
||||
derive_json_schema = []
|
||||
|
||||
[[test]]
|
||||
name = "chrono"
|
||||
required-features = ["chrono"]
|
||||
|
||||
[[test]]
|
||||
name = "schema_for_schema"
|
||||
required-features = ["derive_json_schema"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
use crate as schemars;
|
||||
use crate::{JsonSchema, Map, Set};
|
||||
#[cfg(feature = "derive_json_schema")]
|
||||
use crate::JsonSchema;
|
||||
use crate::{Map, Set};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
/// A JSON Schema.
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "derive_json_schema", derive(JsonSchema))]
|
||||
#[serde(untagged)]
|
||||
pub enum Schema {
|
||||
/// A trivial boolean JSON Schema.
|
||||
|
@ -51,7 +54,8 @@ impl From<bool> for Schema {
|
|||
}
|
||||
|
||||
/// A JSON Schema object.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, JsonSchema)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
|
||||
#[cfg_attr(feature = "derive_json_schema", derive(JsonSchema))]
|
||||
#[serde(rename_all = "camelCase", default)]
|
||||
pub struct SchemaObject {
|
||||
/// Properties which annotate the [`SchemaObject`] which typically have no effect when an object is being validated against the schema.
|
||||
|
@ -177,7 +181,8 @@ impl From<Schema> for SchemaObject {
|
|||
}
|
||||
|
||||
/// Properties which annotate a [`SchemaObject`] which typically have no effect when an object is being validated against the schema.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, JsonSchema)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
|
||||
#[cfg_attr(feature = "derive_json_schema", derive(JsonSchema))]
|
||||
#[serde(rename_all = "camelCase", default)]
|
||||
pub struct Metadata {
|
||||
/// The `$schema` keyword.
|
||||
|
@ -237,7 +242,8 @@ fn is_false(b: &bool) -> bool {
|
|||
}
|
||||
|
||||
/// Properties of a [`SchemaObject`] which define validation assertions in terms of other schemas.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, JsonSchema)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
|
||||
#[cfg_attr(feature = "derive_json_schema", derive(JsonSchema))]
|
||||
#[serde(rename_all = "camelCase", default)]
|
||||
pub struct SubschemaValidation {
|
||||
/// The `allOf` keyword.
|
||||
|
@ -278,7 +284,8 @@ pub struct SubschemaValidation {
|
|||
}
|
||||
|
||||
/// Properties of a [`SchemaObject`] which define validation assertions for numbers.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, JsonSchema)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
|
||||
#[cfg_attr(feature = "derive_json_schema", derive(JsonSchema))]
|
||||
#[serde(rename_all = "camelCase", default)]
|
||||
pub struct NumberValidation {
|
||||
/// The `multipleOf` keyword.
|
||||
|
@ -309,7 +316,8 @@ pub struct NumberValidation {
|
|||
}
|
||||
|
||||
/// Properties of a [`SchemaObject`] which define validation assertions for strings.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, JsonSchema)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
|
||||
#[cfg_attr(feature = "derive_json_schema", derive(JsonSchema))]
|
||||
#[serde(rename_all = "camelCase", default)]
|
||||
pub struct StringValidation {
|
||||
/// The `maxLength` keyword.
|
||||
|
@ -330,7 +338,8 @@ pub struct StringValidation {
|
|||
}
|
||||
|
||||
/// Properties of a [`SchemaObject`] which define validation assertions for arrays.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, JsonSchema)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
|
||||
#[cfg_attr(feature = "derive_json_schema", derive(JsonSchema))]
|
||||
#[serde(rename_all = "camelCase", default)]
|
||||
pub struct ArrayValidation {
|
||||
/// The `items` keyword.
|
||||
|
@ -366,7 +375,8 @@ pub struct ArrayValidation {
|
|||
}
|
||||
|
||||
/// Properties of a [`SchemaObject`] which define validation assertions for objects.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, JsonSchema)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
|
||||
#[cfg_attr(feature = "derive_json_schema", derive(JsonSchema))]
|
||||
#[serde(rename_all = "camelCase", default)]
|
||||
pub struct ObjectValidation {
|
||||
/// The `maxProperties` keyword.
|
||||
|
@ -409,9 +419,8 @@ pub struct ObjectValidation {
|
|||
/// The possible types of values in JSON Schema documents.
|
||||
///
|
||||
/// See [JSON Schema 4.2.1. Instance Data Model](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-4.2.1).
|
||||
#[derive(
|
||||
Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, JsonSchema,
|
||||
)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[cfg_attr(feature = "derive_json_schema", derive(JsonSchema))]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum InstanceType {
|
||||
Null,
|
||||
|
@ -426,7 +435,8 @@ pub enum InstanceType {
|
|||
/// A type which can be serialized as a single item, or multiple items.
|
||||
///
|
||||
/// In some contexts, a `Single` may be semantically distinct from a `Vec` containing only item.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, JsonSchema)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[cfg_attr(feature = "derive_json_schema", derive(JsonSchema))]
|
||||
#[serde(untagged)]
|
||||
pub enum SingleOrVec<T> {
|
||||
Single(Box<T>),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue