diff --git a/utoipa-gen/Cargo.toml b/utoipa-gen/Cargo.toml index 96328ac8..f19db64e 100644 --- a/utoipa-gen/Cargo.toml +++ b/utoipa-gen/Cargo.toml @@ -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"] } @@ -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"] diff --git a/utoipa-gen/src/schema_type.rs b/utoipa-gen/src/schema_type.rs index e5d0b19c..d216b007 100644 --- a/utoipa-gen/src/schema_type.rs +++ b/utoipa-gen/src/schema_type.rs @@ -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) diff --git a/utoipa-gen/tests/schema_derive_test.rs b/utoipa-gen/tests/schema_derive_test.rs index 301681ce..c19b9fb0 100644 --- a/utoipa-gen/tests/schema_derive_test.rs +++ b/utoipa-gen/tests/schema_derive_test.rs @@ -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() { diff --git a/utoipa/Cargo.toml b/utoipa/Cargo.toml index e913d114..72d855c1 100644 --- a/utoipa/Cargo.toml +++ b/utoipa/Cargo.toml @@ -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"]