Implement JsonSchema on Uuid

This commit is contained in:
Graham Esau 2019-12-27 22:41:28 +00:00
parent 547f81fd67
commit 008d70e52a
8 changed files with 48 additions and 2 deletions

View file

@ -2,7 +2,7 @@
## next ## next
### Added: ### Added:
- Implemented `JsonSchema` on types from `indexmap` and `either` (as optional dependencies) - Implemented `JsonSchema` on types from `indexmap`, `either` and `uuid` (as optional dependencies)
### Changed ### Changed
- Remove trait bounds from Map/Set JsonSchema impls. They are unnecessary as we never create/use any instances of these types. - Remove trait bounds from Map/Set JsonSchema impls. They are unnecessary as we never create/use any instances of these types.

View file

@ -210,5 +210,6 @@ fn main() {
- `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.
- `indexmap` - implements `JsonSchema` on `IndexMap` and `IndexSet` from [indexmap](https://github.com/bluss/indexmap). - `indexmap` - implements `JsonSchema` on `IndexMap` and `IndexSet` from [indexmap](https://github.com/bluss/indexmap).
- `either` - implements `JsonSchema` on [`Either`](https://github.com/bluss/either). - `either` - implements `JsonSchema` on [`Either`](https://github.com/bluss/either).
- `uuid` - implements `JsonSchema` on [`Uuid`](https://github.com/uuid-rs/uuid).
- `impl_json_schema` - implements `JsonSchema` for Schemars types themselves - `impl_json_schema` - implements `JsonSchema` for Schemars types themselves

View file

@ -27,4 +27,7 @@ Implements `JsonSchema` on `IndexMap` and `IndexSet` from [indexmap](https://git
### either ### either
Implements `JsonSchema` on [`Either`](https://github.com/bluss/either). Implements `JsonSchema` on [`Either`](https://github.com/bluss/either).
### uuid
Implements `JsonSchema` on [`Uuid`](https://github.com/uuid-rs/uuid).
</div> </div>

View file

@ -19,7 +19,8 @@ serde_json = "1.0"
chrono = { version = "0.4", default-features = false, optional = true } chrono = { version = "0.4", default-features = false, optional = true }
indexmap = { version = "1.2", optional = true } indexmap = { version = "1.2", optional = true }
either = { version = "1.3", optional = true } either = { version = "1.3", default-features = false, optional = true }
uuid = { version = "0.8", default-features = false, optional = true }
[dev-dependencies] [dev-dependencies]
pretty_assertions = "0.6.1" pretty_assertions = "0.6.1"
@ -41,6 +42,10 @@ required-features = ["indexmap"]
name = "either" name = "either"
required-features = ["either"] required-features = ["either"]
[[test]]
name = "uuid"
required-features = ["uuid"]
[[test]] [[test]]
name = "schema_for_schema" name = "schema_for_schema"
required-features = ["impl_json_schema"] required-features = ["impl_json_schema"]

View file

@ -40,6 +40,8 @@ mod chrono;
mod indexmap; mod indexmap;
#[cfg(feature = "either")] #[cfg(feature = "either")]
mod either; mod either;
#[cfg(feature = "uuid")]
mod uuid;
mod core; mod core;
mod ffi; mod ffi;
mod maps; mod maps;

View file

@ -0,0 +1,21 @@
use crate::gen::SchemaGenerator;
use crate::schema::*;
use crate::JsonSchema;
use uuid::Uuid;
impl JsonSchema for Uuid {
no_ref_schema!();
fn schema_name() -> String {
"Uuid".to_string()
}
fn json_schema(_: &mut SchemaGenerator) -> Schema {
SchemaObject {
instance_type: Some(InstanceType::String.into()),
format: Some("uuid".to_string()),
..Default::default()
}
.into()
}
}

View file

@ -0,0 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Uuid",
"type": "string",
"format": "uuid"
}

8
schemars/tests/uuid.rs Normal file
View file

@ -0,0 +1,8 @@
mod util;
use uuid::Uuid;
use util::*;
#[test]
fn uuid() -> TestResult {
test_default_generated_schema::<Uuid>("uuid")
}