From e386313d9067e97da047acda78d1488f281e39ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B0=D1=85=D0=B0=D1=80=D0=BE=D0=B2=20=D0=90=D0=BD?= =?UTF-8?q?=D0=B4=D1=80=D0=B5=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0?= =?UTF-8?q?=D0=BD=D0=B4=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Wed, 11 Jun 2025 22:03:55 +0300 Subject: [PATCH 1/3] #22 drop a lazy_static dependency --- okapi-operation-macro/Cargo.toml | 3 ++- .../src/operation/request_body/axum.rs | 17 +++++++++++++++++ okapi-operation/Cargo.toml | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/okapi-operation-macro/Cargo.toml b/okapi-operation-macro/Cargo.toml index bb709ba..557bbb3 100644 --- a/okapi-operation-macro/Cargo.toml +++ b/okapi-operation-macro/Cargo.toml @@ -15,7 +15,7 @@ proc-macro = true [dependencies] darling = "0.20" -lazy_static = "1" +lazy_static = { version = "1", optional = true} proc-macro2 = "1" quote = "1" syn = { version = "2", features = ["full"] } @@ -23,6 +23,7 @@ thiserror = "1" [features] axum = [] +legacy_lazy = ["lazy_static"] [dev-dependencies] assert_matches = "1" diff --git a/okapi-operation-macro/src/operation/request_body/axum.rs b/okapi-operation-macro/src/operation/request_body/axum.rs index d17133c..38a8a8f 100644 --- a/okapi-operation-macro/src/operation/request_body/axum.rs +++ b/okapi-operation-macro/src/operation/request_body/axum.rs @@ -1,10 +1,27 @@ use std::collections::HashSet; +#[cfg(not(feature = "legacy_lazy"))] +use std::sync::LazyLock; use syn::{PatType, Type}; use super::{RequestBody, RequestBodyAttrs}; use crate::error::Error; +#[cfg(not(feature = "legacy_lazy"))] +// NOTE: `Form` is not enabled because it have different content types +// based on method https://docs.rs/axum/latest/axum/struct.Form.html#as-extractor +static KNOWN_BODY_TYPES: LazyLock> = LazyLock::new(|| [ + // std types + "String", + + // axum types + "Json", + + // 3rd party types + "Bytes", +].into_iter().collect()); + +#[cfg(feature = "legacy_lazy")] lazy_static::lazy_static! { // NOTE: `Form` is not enabled because it have different content types // based on method https://docs.rs/axum/latest/axum/struct.Form.html#as-extractor diff --git a/okapi-operation/Cargo.toml b/okapi-operation/Cargo.toml index 945f5aa..ac08c79 100644 --- a/okapi-operation/Cargo.toml +++ b/okapi-operation/Cargo.toml @@ -38,6 +38,7 @@ macro = ["okapi-operation-macro"] yaml = ["serde_yaml"] axum = ["dep:axum", "paste", "tower", "okapi-operation-macro/axum"] +legacy_lazy = ["okapi-operation-macro/legacy_lazy"] # Deprecated, use feature `axum` instead axum-integration = ["axum"] From 50358e726e9f1595fb971cc17512e87a5cfaef27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B0=D1=85=D0=B0=D1=80=D0=BE=D0=B2=20=D0=90=D0=BD?= =?UTF-8?q?=D0=B4=D1=80=D0=B5=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0?= =?UTF-8?q?=D0=BD=D0=B4=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Wed, 11 Jun 2025 22:09:08 +0300 Subject: [PATCH 2/3] fmt fixes --- .../src/operation/request_body/axum.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/okapi-operation-macro/src/operation/request_body/axum.rs b/okapi-operation-macro/src/operation/request_body/axum.rs index 38a8a8f..f09a1e3 100644 --- a/okapi-operation-macro/src/operation/request_body/axum.rs +++ b/okapi-operation-macro/src/operation/request_body/axum.rs @@ -10,16 +10,15 @@ use crate::error::Error; #[cfg(not(feature = "legacy_lazy"))] // NOTE: `Form` is not enabled because it have different content types // based on method https://docs.rs/axum/latest/axum/struct.Form.html#as-extractor -static KNOWN_BODY_TYPES: LazyLock> = LazyLock::new(|| [ - // std types - "String", - - // axum types - "Json", - - // 3rd party types - "Bytes", -].into_iter().collect()); +static KNOWN_BODY_TYPES: LazyLock> = LazyLock::new(|| { + [ + "String", // std types + "Json", // 3rd party types + "Bytes", // 3rd party types + ] + .into_iter() + .collect() +}); #[cfg(feature = "legacy_lazy")] lazy_static::lazy_static! { From 5afa23c25a5af6693ec892e98eada62888956b4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B0=D1=85=D0=B0=D1=80=D0=BE=D0=B2=20=D0=90=D0=BD?= =?UTF-8?q?=D0=B4=D1=80=D0=B5=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0?= =?UTF-8?q?=D0=BD=D0=B4=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Sun, 15 Jun 2025 15:33:44 +0300 Subject: [PATCH 3/3] totally drop lazy_static --- okapi-operation-macro/Cargo.toml | 2 -- .../src/operation/request_body/axum.rs | 21 +------------------ okapi-operation/Cargo.toml | 1 - 3 files changed, 1 insertion(+), 23 deletions(-) diff --git a/okapi-operation-macro/Cargo.toml b/okapi-operation-macro/Cargo.toml index fd86897..91638bd 100644 --- a/okapi-operation-macro/Cargo.toml +++ b/okapi-operation-macro/Cargo.toml @@ -15,7 +15,6 @@ proc-macro = true [dependencies] darling = "0.20" -lazy_static = { version = "1", optional = true} proc-macro2 = "1" quote = "1" syn = { version = "2", features = ["full"] } @@ -23,7 +22,6 @@ thiserror = "2" [features] axum = [] -legacy_lazy = ["lazy_static"] [dev-dependencies] assert_matches = "1" diff --git a/okapi-operation-macro/src/operation/request_body/axum.rs b/okapi-operation-macro/src/operation/request_body/axum.rs index f09a1e3..787493c 100644 --- a/okapi-operation-macro/src/operation/request_body/axum.rs +++ b/okapi-operation-macro/src/operation/request_body/axum.rs @@ -1,13 +1,10 @@ -use std::collections::HashSet; -#[cfg(not(feature = "legacy_lazy"))] -use std::sync::LazyLock; +use std::{collections::HashSet, sync::LazyLock}; use syn::{PatType, Type}; use super::{RequestBody, RequestBodyAttrs}; use crate::error::Error; -#[cfg(not(feature = "legacy_lazy"))] // NOTE: `Form` is not enabled because it have different content types // based on method https://docs.rs/axum/latest/axum/struct.Form.html#as-extractor static KNOWN_BODY_TYPES: LazyLock> = LazyLock::new(|| { @@ -20,22 +17,6 @@ static KNOWN_BODY_TYPES: LazyLock> = LazyLock::new(|| { .collect() }); -#[cfg(feature = "legacy_lazy")] -lazy_static::lazy_static! { - // NOTE: `Form` is not enabled because it have different content types - // based on method https://docs.rs/axum/latest/axum/struct.Form.html#as-extractor - static ref KNOWN_BODY_TYPES: HashSet<&'static str> = [ - // std types - "String", - - // axum types - "Json", - - // 3rd party types - "Bytes", - ].into_iter().collect(); -} - impl RequestBody { pub(super) fn try_find_axum(pt: &PatType) -> Result, Error> { let Type::Path(ref path) = *pt.ty else { diff --git a/okapi-operation/Cargo.toml b/okapi-operation/Cargo.toml index ac0dc72..11522d6 100644 --- a/okapi-operation/Cargo.toml +++ b/okapi-operation/Cargo.toml @@ -38,7 +38,6 @@ macro = ["okapi-operation-macro"] yaml = ["serde_yaml"] axum = ["dep:axum", "paste", "tower", "okapi-operation-macro/axum"] -legacy_lazy = ["okapi-operation-macro/legacy_lazy"] # Deprecated, use feature `axum` instead axum-integration = ["axum"]