Skip to content
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
2 changes: 2 additions & 0 deletions utoipa-gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ axum = { version = "0.8.0", default-features = false, features = [
paste = "1"
rocket = { version = "0.5", features = ["json"] }
smallvec = { version = "1.10", features = ["serde"] }
bigdecimal = ">= 0.0.13, < 0.5.0"
rust_decimal = { version = "1", default-features = false }
chrono = { version = "0.4", features = ["serde"] }
time = { version = "0.3", features = ["serde-human-readable"] }
Expand All @@ -61,6 +62,7 @@ debug = ["syn/extra-traits"]
actix_extras = ["regex", "syn/extra-traits"]
chrono = []
yaml = []
bigdecimal = []
decimal = []
decimal_float = []
rocket_extras = ["regex", "syn/extra-traits"]
Expand Down
5 changes: 5 additions & 0 deletions utoipa-gen/src/schema_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,11 @@ impl PrimitiveType {
syn::parse_quote!(String)
}

#[cfg(feature = "bigdecimal")]
"BigDecimal" => {
syn::parse_quote!(String)
}

#[cfg(feature = "decimal")]
"Decimal" => {
syn::parse_quote!(String)
Expand Down
19 changes: 19 additions & 0 deletions utoipa-gen/tests/schema_derive_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,25 @@ fn derive_struct_with_rust_decimal_float_with_type_override() {
}
}

#[cfg(feature = "bigdecimal")]
#[test]
fn derive_struct_with_rust_bigdecimal_with_type_override() {
let post = api_doc! {
struct Post {
id: i32,
#[schema(value_type = String)]
rating: bigdecimal::BigDecimal,
}
};

assert_value! {post=>
"properties.id.type" = r#""integer""#, "Post id type"
"properties.id.format" = r#""int32""#, "Post id format"
"properties.rating.type" = r#""string""#, "Post rating type"
"properties.rating.format" = r#"null"#, "Post rating format"
}
}

#[cfg(feature = "uuid")]
#[test]
fn derive_struct_with_uuid_type() {
Expand Down
1 change: 1 addition & 0 deletions utoipa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ actix_extras = ["utoipa-gen?/actix_extras"]
rocket_extras = ["utoipa-gen?/rocket_extras"]
axum_extras = ["utoipa-gen?/axum_extras"]
chrono = ["utoipa-gen?/chrono"]
bigdecimal = ["utoipa-gen?/bigdecimal"]
decimal = ["utoipa-gen?/decimal"]
decimal_float = ["utoipa-gen?/decimal_float"]
non_strict_integers = ["utoipa-gen?/non_strict_integers"]
Expand Down
Loading