Implement JsonSchema on Uuid
This commit is contained in:
parent
547f81fd67
commit
008d70e52a
8 changed files with 48 additions and 2 deletions
|
@ -19,7 +19,8 @@ serde_json = "1.0"
|
|||
|
||||
chrono = { version = "0.4", default-features = false, 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]
|
||||
pretty_assertions = "0.6.1"
|
||||
|
@ -41,6 +42,10 @@ required-features = ["indexmap"]
|
|||
name = "either"
|
||||
required-features = ["either"]
|
||||
|
||||
[[test]]
|
||||
name = "uuid"
|
||||
required-features = ["uuid"]
|
||||
|
||||
[[test]]
|
||||
name = "schema_for_schema"
|
||||
required-features = ["impl_json_schema"]
|
||||
|
|
|
@ -40,6 +40,8 @@ mod chrono;
|
|||
mod indexmap;
|
||||
#[cfg(feature = "either")]
|
||||
mod either;
|
||||
#[cfg(feature = "uuid")]
|
||||
mod uuid;
|
||||
mod core;
|
||||
mod ffi;
|
||||
mod maps;
|
||||
|
|
21
schemars/src/json_schema_impls/uuid.rs
Normal file
21
schemars/src/json_schema_impls/uuid.rs
Normal 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()
|
||||
}
|
||||
}
|
6
schemars/tests/expected/uuid.json
Normal file
6
schemars/tests/expected/uuid.json
Normal 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
8
schemars/tests/uuid.rs
Normal file
|
@ -0,0 +1,8 @@
|
|||
mod util;
|
||||
use uuid::Uuid;
|
||||
use util::*;
|
||||
|
||||
#[test]
|
||||
fn uuid() -> TestResult {
|
||||
test_default_generated_schema::<Uuid>("uuid")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue