Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add feature for serde_bytes::ByteBuf #349

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 9 additions & 0 deletions schemars/src/json_schema_impls/serde_bytes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use crate::JsonSchema;
use serde_bytes::ByteBuf;

forward_impl!((JsonSchema for ByteBuf) => alloc::vec::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")
}
Loading