Rename derive_json_schema feature to impl_json_schema

This commit is contained in:
Graham Esau 2019-12-27 17:13:32 +00:00
parent 1c0f626e3f
commit 0ae2d48fba
5 changed files with 20 additions and 18 deletions

View file

@ -208,5 +208,5 @@ fn main() {
## Feature Flags ## Feature Flags
- `chrono` - implements `JsonSchema` for all [Chrono](https://github.com/chronotope/chrono) types which are serializable by Serde. - `chrono` - implements `JsonSchema` for all [Chrono](https://github.com/chronotope/chrono) types which are serializable by Serde.
- `derive_json_schema` - implements `JsonSchema` for Schemars types themselves - `impl_json_schema` - implements `JsonSchema` for Schemars types themselves

View file

@ -15,7 +15,7 @@ schemars = { version = "0.6", features = ["chrono"] }
<div class="indented"> <div class="indented">
### derive_json_schema ### impl_json_schema
Implements `JsonSchema` on Schemars types themselves. Implements `JsonSchema` on Schemars types themselves.

View file

@ -22,7 +22,9 @@ chrono = { version = "0.4", default-features = false, optional = true }
pretty_assertions = "0.6.1" pretty_assertions = "0.6.1"
[features] [features]
derive_json_schema = [] impl_json_schema = []
# derive_json_schema will be removed in a later version
derive_json_schema = ["impl_json_schema"]
[[test]] [[test]]
name = "chrono" name = "chrono"
@ -30,7 +32,7 @@ required-features = ["chrono"]
[[test]] [[test]]
name = "schema_for_schema" name = "schema_for_schema"
required-features = ["derive_json_schema"] required-features = ["impl_json_schema"]
[package.metadata.docs.rs] [package.metadata.docs.rs]
all-features = true all-features = true

View file

@ -202,7 +202,7 @@ fn main() {
## Feature Flags ## Feature Flags
- `chrono` - implements `JsonSchema` for all [Chrono](https://github.com/chronotope/chrono) types which are serializable by Serde. - `chrono` - implements `JsonSchema` for all [Chrono](https://github.com/chronotope/chrono) types which are serializable by Serde.
- `derive_json_schema` - implements `JsonSchema` for Schemars types themselves - `impl_json_schema` - implements `JsonSchema` for Schemars types themselves
*/ */
/// The map type used by schemars types. /// The map type used by schemars types.

View file

@ -1,6 +1,6 @@
#[cfg(feature = "derive_json_schema")] #[cfg(feature = "impl_json_schema")]
use crate as schemars; use crate as schemars;
#[cfg(feature = "derive_json_schema")] #[cfg(feature = "impl_json_schema")]
use crate::JsonSchema; use crate::JsonSchema;
use crate::{Map, Set}; use crate::{Map, Set};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -9,7 +9,7 @@ use serde_json::Value;
/// A JSON Schema. /// A JSON Schema.
#[allow(clippy::large_enum_variant)] #[allow(clippy::large_enum_variant)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[cfg_attr(feature = "derive_json_schema", derive(JsonSchema))] #[cfg_attr(feature = "impl_json_schema", derive(JsonSchema))]
#[serde(untagged)] #[serde(untagged)]
pub enum Schema { pub enum Schema {
/// A trivial boolean JSON Schema. /// A trivial boolean JSON Schema.
@ -56,7 +56,7 @@ impl From<bool> for Schema {
/// The root object of a JSON Schema document. /// The root object of a JSON Schema document.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
#[cfg_attr(feature = "derive_json_schema", derive(JsonSchema))] #[cfg_attr(feature = "impl_json_schema", derive(JsonSchema))]
#[serde(rename_all = "camelCase", default)] #[serde(rename_all = "camelCase", default)]
pub struct RootSchema { pub struct RootSchema {
/// The `$schema` keyword. /// The `$schema` keyword.
@ -78,7 +78,7 @@ pub struct RootSchema {
/// A JSON Schema object. /// A JSON Schema object.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
#[cfg_attr(feature = "derive_json_schema", derive(JsonSchema))] #[cfg_attr(feature = "impl_json_schema", derive(JsonSchema))]
#[serde(rename_all = "camelCase", default)] #[serde(rename_all = "camelCase", default)]
pub struct SchemaObject { pub struct SchemaObject {
/// Properties which annotate the [`SchemaObject`] which typically have no effect when an object is being validated against the schema. /// Properties which annotate the [`SchemaObject`] which typically have no effect when an object is being validated against the schema.
@ -218,7 +218,7 @@ impl From<Schema> for SchemaObject {
/// Properties which annotate a [`SchemaObject`] which typically have no effect when an object is being validated against the schema. /// 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)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
#[cfg_attr(feature = "derive_json_schema", derive(JsonSchema))] #[cfg_attr(feature = "impl_json_schema", derive(JsonSchema))]
#[serde(rename_all = "camelCase", default)] #[serde(rename_all = "camelCase", default)]
pub struct Metadata { pub struct Metadata {
/// The `$id` keyword. /// The `$id` keyword.
@ -268,7 +268,7 @@ fn is_false(b: &bool) -> bool {
/// Properties of a [`SchemaObject`] which define validation assertions in terms of other schemas. /// Properties of a [`SchemaObject`] which define validation assertions in terms of other schemas.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
#[cfg_attr(feature = "derive_json_schema", derive(JsonSchema))] #[cfg_attr(feature = "impl_json_schema", derive(JsonSchema))]
#[serde(rename_all = "camelCase", default)] #[serde(rename_all = "camelCase", default)]
pub struct SubschemaValidation { pub struct SubschemaValidation {
/// The `allOf` keyword. /// The `allOf` keyword.
@ -310,7 +310,7 @@ pub struct SubschemaValidation {
/// Properties of a [`SchemaObject`] which define validation assertions for numbers. /// Properties of a [`SchemaObject`] which define validation assertions for numbers.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
#[cfg_attr(feature = "derive_json_schema", derive(JsonSchema))] #[cfg_attr(feature = "impl_json_schema", derive(JsonSchema))]
#[serde(rename_all = "camelCase", default)] #[serde(rename_all = "camelCase", default)]
pub struct NumberValidation { pub struct NumberValidation {
/// The `multipleOf` keyword. /// The `multipleOf` keyword.
@ -342,7 +342,7 @@ pub struct NumberValidation {
/// Properties of a [`SchemaObject`] which define validation assertions for strings. /// Properties of a [`SchemaObject`] which define validation assertions for strings.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
#[cfg_attr(feature = "derive_json_schema", derive(JsonSchema))] #[cfg_attr(feature = "impl_json_schema", derive(JsonSchema))]
#[serde(rename_all = "camelCase", default)] #[serde(rename_all = "camelCase", default)]
pub struct StringValidation { pub struct StringValidation {
/// The `maxLength` keyword. /// The `maxLength` keyword.
@ -364,7 +364,7 @@ pub struct StringValidation {
/// Properties of a [`SchemaObject`] which define validation assertions for arrays. /// Properties of a [`SchemaObject`] which define validation assertions for arrays.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
#[cfg_attr(feature = "derive_json_schema", derive(JsonSchema))] #[cfg_attr(feature = "impl_json_schema", derive(JsonSchema))]
#[serde(rename_all = "camelCase", default)] #[serde(rename_all = "camelCase", default)]
pub struct ArrayValidation { pub struct ArrayValidation {
/// The `items` keyword. /// The `items` keyword.
@ -401,7 +401,7 @@ pub struct ArrayValidation {
/// Properties of a [`SchemaObject`] which define validation assertions for objects. /// Properties of a [`SchemaObject`] which define validation assertions for objects.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
#[cfg_attr(feature = "derive_json_schema", derive(JsonSchema))] #[cfg_attr(feature = "impl_json_schema", derive(JsonSchema))]
#[serde(rename_all = "camelCase", default)] #[serde(rename_all = "camelCase", default)]
pub struct ObjectValidation { pub struct ObjectValidation {
/// The `maxProperties` keyword. /// The `maxProperties` keyword.
@ -445,7 +445,7 @@ pub struct ObjectValidation {
/// ///
/// See [JSON Schema 4.2.1. Instance Data Model](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-4.2.1). /// 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)] #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "derive_json_schema", derive(JsonSchema))] #[cfg_attr(feature = "impl_json_schema", derive(JsonSchema))]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub enum InstanceType { pub enum InstanceType {
Null, Null,
@ -461,7 +461,7 @@ pub enum InstanceType {
/// ///
/// In some contexts, a `Single` may be semantically distinct from a `Vec` containing only item. /// In some contexts, a `Single` may be semantically distinct from a `Vec` containing only item.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "derive_json_schema", derive(JsonSchema))] #[cfg_attr(feature = "impl_json_schema", derive(JsonSchema))]
#[serde(untagged)] #[serde(untagged)]
pub enum SingleOrVec<T> { pub enum SingleOrVec<T> {
Single(Box<T>), Single(Box<T>),