Skip to content

Commit

Permalink
add feature for serde_bytes::ByteBuf
Browse files Browse the repository at this point in the history
  • Loading branch information
ratmice committed Nov 7, 2024
1 parent a479e6c commit 3b3a6ae
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions schemars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ smallvec1 = { version = "1.0", default-features = false, optional = true, packag
smol_str02 = { version = "0.2.1", default-features = false, optional = true, package = "smol_str" }
url2 = { version = "2.0", default-features = false, optional = true, package = "url" }
uuid1 = { version = "1.0", default-features = false, optional = true, package = "uuid" }
serde_bytes = { version = "0.11.12", optional = true }

[dev-dependencies]
pretty_assertions = "1.2.1"
Expand Down Expand Up @@ -76,13 +77,19 @@ preserve_order = ["serde_json/preserve_order"]
# Implements `JsonSchema` on `serde_json::value::RawValue`
raw_value = ["serde_json/raw_value"]

serde_bytes = ["dep:serde_bytes"]

# For internal/CI use only
_ui_test = []

[[test]]
name = "ui"
required-features = ["_ui_test"]

[[test]]
name = "serde_bytes"
required-features = ["serde_bytes"]

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--extend-css", "docs-rs-custom.css"]
2 changes: 2 additions & 0 deletions schemars/src/json_schema_impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ mod maps;
mod nonzero;
mod primitives;
mod sequences;
#[cfg(feature = "serde_bytes")]
mod serde_bytes;
mod serdejson;
mod std_time;
mod tuple;
Expand Down
11 changes: 11 additions & 0 deletions schemars/src/json_schema_impls/serde_bytes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use crate::gen::SchemaGenerator;
use crate::schema::*;
use crate::JsonSchema;
use serde_bytes::ByteBuf;

forward_impl!((JsonSchema for ByteBuf) => Vec<u8>);
// Because Bytes is a wrapper around [u8] which is not `Sized`
// I couldn't get it through the testsuite to check if this actually works.
//
// use serde_bytes::Bytes;
// forward_impl!((JsonSchema for Bytes) => Vec<u8>);
8 changes: 8 additions & 0 deletions schemars/tests/serde_bytes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mod util;
use serde_bytes::ByteBuf;
use util::*;

#[test]
fn bytes() -> TestResult {
test_default_generated_schema::<(ByteBuf, ByteBuf)>("bytes")
}

0 comments on commit 3b3a6ae

Please sign in to comment.