Support Bytes (#68)
This commit is contained in:
parent
9c68e080d6
commit
0e3938798f
7 changed files with 33 additions and 0 deletions
|
@ -273,3 +273,4 @@ Schemars can implement `JsonSchema` on types from several popular crates, enable
|
|||
- [`smallvec`](https://crates.io/crates/smallvec) (^1.0)
|
||||
- [`arrayvec`](https://crates.io/crates/arrayvec) (^0.5)
|
||||
- [`url`](https://crates.io/crates/url) (^2.0)
|
||||
- [`bytes`](https://crates.io/crates/bytes) (^1.0)
|
||||
|
|
|
@ -27,3 +27,4 @@ Schemars can implement `JsonSchema` on types from several popular crates, enable
|
|||
- [`smallvec`](https://crates.io/crates/smallvec) (^1.0)
|
||||
- [`arrayvec`](https://crates.io/crates/arrayvec) (^0.5)
|
||||
- [`url`](https://crates.io/crates/url) (^2.0)
|
||||
- [`bytes`](https://crates.io/crates/bytes) (^1.0)
|
||||
|
|
|
@ -25,6 +25,7 @@ uuid = { version = "0.8", default-features = false, optional = true }
|
|||
smallvec = { version = "1.0", optional = true }
|
||||
arrayvec = { version = "0.5", default-features = false, optional = true }
|
||||
url = { version = "2.0", default-features = false, optional = true }
|
||||
bytes = { version = "1.0", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
pretty_assertions = "0.6.1"
|
||||
|
@ -66,6 +67,10 @@ required-features = ["uuid"]
|
|||
name = "smallvec"
|
||||
required-features = ["smallvec"]
|
||||
|
||||
[[test]]
|
||||
name = "bytes"
|
||||
required-features = ["bytes"]
|
||||
|
||||
[[test]]
|
||||
name = "arrayvec"
|
||||
required-features = ["arrayvec"]
|
||||
|
|
6
schemars/src/json_schema_impls/bytes.rs
Normal file
6
schemars/src/json_schema_impls/bytes.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
use crate::gen::SchemaGenerator;
|
||||
use crate::schema::*;
|
||||
use crate::JsonSchema;
|
||||
use bytes::Bytes;
|
||||
|
||||
forward_impl!((JsonSchema for Bytes) => Vec<u8>);
|
|
@ -46,6 +46,8 @@ mod array;
|
|||
mod arrayvec;
|
||||
#[cfg(std_atomic)]
|
||||
mod atomic;
|
||||
#[cfg(feature = "bytes")]
|
||||
mod bytes;
|
||||
#[cfg(feature = "chrono")]
|
||||
mod chrono;
|
||||
mod core;
|
||||
|
|
8
schemars/tests/bytes.rs
Normal file
8
schemars/tests/bytes.rs
Normal file
|
@ -0,0 +1,8 @@
|
|||
mod util;
|
||||
use bytes::Bytes;
|
||||
use util::*;
|
||||
|
||||
#[test]
|
||||
fn bytes() -> TestResult {
|
||||
test_default_generated_schema::<Bytes>("bytes")
|
||||
}
|
10
schemars/tests/expected/bytes.json
Normal file
10
schemars/tests/expected/bytes.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Array_of_uint8",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer",
|
||||
"format": "uint8",
|
||||
"minimum": 0.0
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue