From a0bfe11c457dfdf4e6a77a59a8552171eea2a636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Bour?= Date: Wed, 18 Dec 2024 15:49:16 +0100 Subject: [PATCH] Use a re-exported serde_json dependency in macros (#1243) Re-exports `serde_json` to enable users to not directly depend on `serde_json`. Fixes #1172 --- .../Cargo.toml | 1 - examples/actix-web-scopes-binding/Cargo.toml | 1 - examples/axum-multipart/Cargo.toml | 1 - examples/axum-utoipa-bindings/Cargo.toml | 1 - .../axum-utoipa-nesting-vendored/Cargo.toml | 1 - examples/generics-actix/Cargo.toml | 1 - examples/todo-actix/Cargo.toml | 1 - examples/todo-axum/Cargo.toml | 1 - examples/todo-warp-rapidoc/Cargo.toml | 1 - .../Cargo.toml | 1 - examples/todo-warp/Cargo.toml | 1 - examples/warp-multiple-api-docs/Cargo.toml | 1 - utoipa-gen/CHANGELOG.md | 18 ++++++------------ utoipa-gen/src/component/schema.rs | 2 +- utoipa-gen/src/component/schema/enums.rs | 2 +- utoipa-gen/src/lib.rs | 4 ++-- utoipa/CHANGELOG.md | 4 ++++ utoipa/src/gen.rs | 1 + utoipa/src/lib.rs | 6 ++++++ 19 files changed, 21 insertions(+), 28 deletions(-) create mode 100644 utoipa/src/gen.rs diff --git a/examples/actix-web-multiple-api-docs-with-scopes/Cargo.toml b/examples/actix-web-multiple-api-docs-with-scopes/Cargo.toml index e3539782..1984b3d5 100644 --- a/examples/actix-web-multiple-api-docs-with-scopes/Cargo.toml +++ b/examples/actix-web-multiple-api-docs-with-scopes/Cargo.toml @@ -13,7 +13,6 @@ authors = [ [dependencies] actix-web = "4" serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" env_logger = "0.11.0" log = "0.4" futures = "0.3" diff --git a/examples/actix-web-scopes-binding/Cargo.toml b/examples/actix-web-scopes-binding/Cargo.toml index 3891e228..4e417f82 100644 --- a/examples/actix-web-scopes-binding/Cargo.toml +++ b/examples/actix-web-scopes-binding/Cargo.toml @@ -7,7 +7,6 @@ edition = "2021" [dependencies] actix-web = "4" serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" env_logger = "0.11.0" log = "0.4" futures = "0.3" diff --git a/examples/axum-multipart/Cargo.toml b/examples/axum-multipart/Cargo.toml index 68ce51b2..9ebc76be 100644 --- a/examples/axum-multipart/Cargo.toml +++ b/examples/axum-multipart/Cargo.toml @@ -11,6 +11,5 @@ utoipa = { version = "5", features = ["axum_extras"] } utoipa-swagger-ui = { version = "8", features = ["axum"] } utoipa-axum = "0.1" serde = { features = ["derive"], version = "1" } -serde_json = "1" [workspace] diff --git a/examples/axum-utoipa-bindings/Cargo.toml b/examples/axum-utoipa-bindings/Cargo.toml index f8e667e6..9c94167a 100644 --- a/examples/axum-utoipa-bindings/Cargo.toml +++ b/examples/axum-utoipa-bindings/Cargo.toml @@ -11,6 +11,5 @@ utoipa = { path = "../../utoipa", features = ["axum_extras", "debug"] } utoipa-swagger-ui = { path = "../../utoipa-swagger-ui", features = ["axum"] } utoipa-axum = { path = "../../utoipa-axum" ,features = ["debug"] } serde = "1" -serde_json = "1" [workspace] diff --git a/examples/axum-utoipa-nesting-vendored/Cargo.toml b/examples/axum-utoipa-nesting-vendored/Cargo.toml index 90b1a7d1..533157d6 100644 --- a/examples/axum-utoipa-nesting-vendored/Cargo.toml +++ b/examples/axum-utoipa-nesting-vendored/Cargo.toml @@ -15,7 +15,6 @@ tower = "0.5" utoipa = { path = "../../utoipa", features = ["axum_extras"] } utoipa-swagger-ui = { path = "../../utoipa-swagger-ui", features = ["axum", "vendored"], default-features = false } serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" env_logger = "0.11" log = "0.4" diff --git a/examples/generics-actix/Cargo.toml b/examples/generics-actix/Cargo.toml index 050bd6c6..58c3e186 100644 --- a/examples/generics-actix/Cargo.toml +++ b/examples/generics-actix/Cargo.toml @@ -15,7 +15,6 @@ actix-web = "4" env_logger = "0.10.0" geo-types = { version = "0.7", features = ["serde"] } serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" utoipa = { path = "../../utoipa", features = ["actix_extras", "non_strict_integers"] } utoipa-swagger-ui = { path = "../../utoipa-swagger-ui", features = ["actix-web"] } diff --git a/examples/todo-actix/Cargo.toml b/examples/todo-actix/Cargo.toml index 92bdfd5d..1b476cae 100644 --- a/examples/todo-actix/Cargo.toml +++ b/examples/todo-actix/Cargo.toml @@ -11,7 +11,6 @@ authors = ["Example "] [dependencies] actix-web = "4" serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" env_logger = "0.11" log = "0.4" futures = "0.3" diff --git a/examples/todo-axum/Cargo.toml b/examples/todo-axum/Cargo.toml index 67e76ed9..7646c7d5 100644 --- a/examples/todo-axum/Cargo.toml +++ b/examples/todo-axum/Cargo.toml @@ -20,6 +20,5 @@ utoipa-redoc = { path = "../../utoipa-redoc", features = ["axum"] } utoipa-rapidoc = { path = "../../utoipa-rapidoc", features = ["axum"] } utoipa-scalar = { path = "../../utoipa-scalar", features = ["axum"] } serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" [workspace] diff --git a/examples/todo-warp-rapidoc/Cargo.toml b/examples/todo-warp-rapidoc/Cargo.toml index 023400f1..9b688a23 100644 --- a/examples/todo-warp-rapidoc/Cargo.toml +++ b/examples/todo-warp-rapidoc/Cargo.toml @@ -12,7 +12,6 @@ authors = [ tokio = { version = "1", features = ["full"] } warp = "0.3" serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" env_logger = "0.11.0" log = "0.4" futures = "0.3" diff --git a/examples/todo-warp-redoc-with-file-config/Cargo.toml b/examples/todo-warp-redoc-with-file-config/Cargo.toml index 91d33fc5..fd73391f 100644 --- a/examples/todo-warp-redoc-with-file-config/Cargo.toml +++ b/examples/todo-warp-redoc-with-file-config/Cargo.toml @@ -12,7 +12,6 @@ authors = ["Elli Example "] tokio = { version = "1", features = ["full"] } warp = "0.3" serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" env_logger = "0.11.0" log = "0.4" futures = "0.3" diff --git a/examples/todo-warp/Cargo.toml b/examples/todo-warp/Cargo.toml index 032a670a..c7523b3d 100644 --- a/examples/todo-warp/Cargo.toml +++ b/examples/todo-warp/Cargo.toml @@ -14,7 +14,6 @@ authors = [ tokio = { version = "1", features = ["full"] } warp = "0.3" serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" env_logger = "0.11.0" log = "0.4" futures = "0.3" diff --git a/examples/warp-multiple-api-docs/Cargo.toml b/examples/warp-multiple-api-docs/Cargo.toml index 52939fb3..1c249215 100644 --- a/examples/warp-multiple-api-docs/Cargo.toml +++ b/examples/warp-multiple-api-docs/Cargo.toml @@ -14,7 +14,6 @@ authors = [ tokio = { version = "1", features = ["full"] } warp = "0.3" serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" env_logger = "0.10.0" log = "0.4" futures = "0.3" diff --git a/utoipa-gen/CHANGELOG.md b/utoipa-gen/CHANGELOG.md index f235c5ef..8f14456f 100644 --- a/utoipa-gen/CHANGELOG.md +++ b/utoipa-gen/CHANGELOG.md @@ -2,27 +2,21 @@ ## Unreleased +### Fixed + +* Fix tagged enum with flatten fields (https://github.com/juhaku/utoipa/pull/1208) + ### Added * Add `encoding` support for `request_body` (https://github.com/juhaku/utoipa/pull/1237) +* Add support for `#[schema(pattern = "...")]` on new type structs (https://github.com/juhaku/utoipa/pull/1241) ### Changed +* Use a re-exported `serde_json` dependency in macros instead of implicitly requiring it as dependency in end projects (https://github.com/juhaku/utoipa/pull/1243) * Simplified `ToTokensDiagnostics` for `request_body` (https://github.com/juhaku/utoipa/pull/1235) -* Make `parse_named_attributes` a method of `MediaTypeAttr` (https://github.com/juhaku/utoipa/pull/1236) - -### Fixed - -* Fix tagged enum with flatten fields (https://github.com/juhaku/utoipa/pull/1208) - -### Changed - * `Info::from_env()` sets `License::identifier` (https://github.com/juhaku/utoipa/pull/1233) -### Added - -* Add support for `#[schema(pattern = "...")]` on new type structs (https://github.com/juhaku/utoipa/pull/1241) - ## 5.2.0 - Nov 2024 ### Fixed diff --git a/utoipa-gen/src/component/schema.rs b/utoipa-gen/src/component/schema.rs index f60d07d3..9f09bc2b 100644 --- a/utoipa-gen/src/component/schema.rs +++ b/utoipa-gen/src/component/schema.rs @@ -281,7 +281,7 @@ impl UnitStructVariant { let mut tokens = quote! { utoipa::openapi::Object::builder() .schema_type(utoipa::openapi::schema::SchemaType::AnyValue) - .default(Some(serde_json::Value::Null)) + .default(Some(utoipa::gen::serde_json::Value::Null)) }; let mut features = features::parse_schema_features_with(root.attributes, |input| { diff --git a/utoipa-gen/src/component/schema/enums.rs b/utoipa-gen/src/component/schema/enums.rs index 54602199..224925ce 100644 --- a/utoipa-gen/src/component/schema/enums.rs +++ b/utoipa-gen/src/component/schema/enums.rs @@ -774,7 +774,7 @@ where tokens.extend(quote! { utoipa::openapi::schema::Object::builder() .schema_type(utoipa::openapi::schema::Type::Null) - .default(Some(serde_json::Value::Null)) + .default(Some(utoipa::gen::serde_json::Value::Null)) }) } diff --git a/utoipa-gen/src/lib.rs b/utoipa-gen/src/lib.rs index 3838760a..a21487be 100644 --- a/utoipa-gen/src/lib.rs +++ b/utoipa-gen/src/lib.rs @@ -3341,14 +3341,14 @@ impl ToTokens for AnyValue { fn to_tokens(&self, tokens: &mut TokenStream2) { match self { Self::Json(json) => tokens.extend(quote! { - serde_json::json!(#json) + utoipa::gen::serde_json::json!(#json) }), Self::String(string) => string.to_tokens(tokens), Self::DefaultTrait { struct_ident, field_ident, } => tokens.extend(quote! { - serde_json::to_value(#struct_ident::default().#field_ident).unwrap() + utoipa::gen::serde_json::to_value(#struct_ident::default().#field_ident).unwrap() }), } } diff --git a/utoipa/CHANGELOG.md b/utoipa/CHANGELOG.md index 20bec0e5..3def3719 100644 --- a/utoipa/CHANGELOG.md +++ b/utoipa/CHANGELOG.md @@ -9,6 +9,10 @@ to look into changes introduced to **`utoipa-gen`**. * Fix diverging axum route and openapi spec (https://github.com/juhaku/utoipa/pull/1199) +### Changed + +* Use a re-exported `serde_json` dependency in macros instead of implicitly requiring it as dependency in end projects (https://github.com/juhaku/utoipa/pull/1243) + ## 5.2.0 - Nov 2024 ### Changed diff --git a/utoipa/src/gen.rs b/utoipa/src/gen.rs new file mode 100644 index 00000000..90a3875d --- /dev/null +++ b/utoipa/src/gen.rs @@ -0,0 +1 @@ +pub use serde_json; diff --git a/utoipa/src/lib.rs b/utoipa/src/lib.rs index 37a8d176..251c7d1f 100644 --- a/utoipa/src/lib.rs +++ b/utoipa/src/lib.rs @@ -234,6 +234,12 @@ pub mod openapi; +#[cfg(feature = "macros")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "macros")))] +#[doc(hidden)] +/// Public re-exports for utoipa-gen. +pub mod gen; + use std::borrow::Cow; use std::collections::BTreeMap; use std::option::Option;