aster_forge_api_docs_macros/
lib.rs

1//! `OpenAPI` attribute macros shared by Aster services.
2//!
3//! The crate keeps route annotations lightweight in production builds while preserving
4//! `utoipa::path` metadata when the `openapi` feature is enabled for debug builds. This lets
5//! application code keep a single annotation path without pulling `OpenAPI` generation into normal
6//! release binaries.
7#![cfg_attr(
8    not(test),
9    deny(
10        clippy::unwrap_used,
11        clippy::unreachable,
12        clippy::expect_used,
13        clippy::panic,
14        clippy::unimplemented,
15        clippy::todo
16    )
17)]
18
19extern crate proc_macro;
20
21use proc_macro::TokenStream;
22
23#[cfg(all(feature = "openapi", debug_assertions))]
24use quote::quote;
25
26#[cfg(all(feature = "openapi", debug_assertions))]
27/// Expands to `#[utoipa::path(...)]` when `OpenAPI` generation is enabled for debug builds.
28#[proc_macro_attribute]
29pub fn path(attr: TokenStream, item: TokenStream) -> TokenStream {
30    let attr = proc_macro2::TokenStream::from(attr);
31    let item = proc_macro2::TokenStream::from(item);
32
33    quote! {
34        #[utoipa::path(#attr)]
35        #item
36    }
37    .into()
38}
39
40#[cfg(not(all(feature = "openapi", debug_assertions)))]
41/// Leaves the annotated item unchanged when OpenAPI generation is disabled.
42#[proc_macro_attribute]
43pub fn path(_attr: TokenStream, item: TokenStream) -> TokenStream {
44    item
45}