Skip to main content

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#![deny(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
8#![cfg_attr(
9    not(test),
10    deny(
11        clippy::unwrap_used,
12        clippy::unreachable,
13        clippy::expect_used,
14        clippy::panic,
15        clippy::unimplemented,
16        clippy::todo
17    )
18)]
19
20extern crate proc_macro;
21
22use proc_macro::TokenStream;
23
24#[cfg(all(feature = "openapi", debug_assertions))]
25use quote::quote;
26
27#[cfg(all(feature = "openapi", debug_assertions))]
28/// Expands to `#[utoipa::path(...)]` when OpenAPI generation is enabled for debug builds.
29#[proc_macro_attribute]
30pub fn path(attr: TokenStream, item: TokenStream) -> TokenStream {
31    let attr = proc_macro2::TokenStream::from(attr);
32    let item = proc_macro2::TokenStream::from(item);
33
34    quote! {
35        #[utoipa::path(#attr)]
36        #item
37    }
38    .into()
39}
40
41#[cfg(not(all(feature = "openapi", debug_assertions)))]
42/// Leaves the annotated item unchanged when OpenAPI generation is disabled.
43#[proc_macro_attribute]
44pub fn path(_attr: TokenStream, item: TokenStream) -> TokenStream {
45    item
46}