Skip to content
Merged
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
39 changes: 39 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions benzina/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ features = [
"postgres",
"mysql",
"serde",
"schemars",
"typed-uuid",
"example-generated",
"dangerous-construction",
Expand All @@ -26,6 +27,7 @@ rustdoc-args = ["--cfg", "docsrs"]
diesel = { version = "2.3", default-features = false, optional = true }
serde_core = { version = "1.0.221", optional = true }
serde_json = { version = "1.0.144", optional = true }
schemars = { version = "1", default-features = false, optional = true }
utoipa = { version = "5", optional = true }
benzina-derive = { path = "../benzina-derive", version = "=0.4.4", optional = true }
uuid = { version = ">=0.7.0, <2.0.0", default-features = false, optional = true }
Expand All @@ -47,6 +49,7 @@ typed-uuid = ["postgres", "diesel/uuid", "dep:uuid"]
mysql = ["benzina-derive?/mysql"]

serde = ["dep:serde_core", "uuid?/serde"]
schemars = ["dep:schemars"]
utoipa = ["dep:utoipa"]

example-generated = ["typed-uuid"]
Expand Down
2 changes: 2 additions & 0 deletions benzina/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub mod example_generated;
mod int;
#[cfg(feature = "json")]
mod json;
#[cfg(all(feature = "schemars", feature = "postgres"))]
mod schemars;
#[cfg(all(feature = "serde", feature = "postgres"))]
mod serde;
#[cfg(feature = "postgres")]
Expand Down
32 changes: 32 additions & 0 deletions benzina/src/schemars.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use std::borrow::Cow;

use schemars::{JsonSchema, Schema, SchemaGenerator, json_schema};

use crate::{U15, U31, U63};

macro_rules! impl_schemars_numbers {
($($type:ident => $format:literal),*) => {
$(
impl JsonSchema for $type {
fn schema_name() -> Cow<'static, str> {
stringify!($type).into()
}

fn json_schema(_: &mut SchemaGenerator) -> Schema {
json_schema!({
"type": "integer",
"format": $format,
"minimum": $type::MIN.get(),
"maximum": $type::MAX.get()
})
}
}
)*
}
}

impl_schemars_numbers! {
U15 => "int16",
U31 => "int32",
U63 => "int64"
}