diff --git a/crates/cdk-axum/src/lib.rs b/crates/cdk-axum/src/lib.rs index 9863c98d..182f4f78 100644 --- a/crates/cdk-axum/src/lib.rs +++ b/crates/cdk-axum/src/lib.rs @@ -47,6 +47,8 @@ mod swagger_imports { MeltQuoteBolt11Request, MeltQuoteBolt11Response, MintQuoteBolt11Request, MintQuoteBolt11Response, }; + #[cfg(feature = "auth")] + pub use cdk::nuts::MintAuthRequest; pub use cdk::nuts::{nut04, nut05, nut15, MeltQuoteState, MintQuoteState}; } @@ -66,9 +68,47 @@ pub struct MintState { } #[cfg(feature = "swagger")] -#[derive(utoipa::OpenApi)] -#[openapi( - components(schemas( +macro_rules! define_api_doc { + ( + schemas: [$($schema:ty),* $(,)?] + $(, auth_schemas: [$($auth_schema:ty),* $(,)?])? + $(, paths: [$($path:path),* $(,)?])? + $(, auth_paths: [$($auth_path:path),* $(,)?])? + ) => { + #[derive(utoipa::OpenApi)] + #[openapi( + components(schemas( + $($schema,)* + $($($auth_schema,)*)? + )), + info(description = "Cashu CDK mint APIs", title = "cdk-mintd"), + paths( + get_keys, + get_keyset_pubkeys, + get_keysets, + get_mint_info, + post_mint_bolt11_quote, + get_check_mint_bolt11_quote, + post_mint_bolt11, + post_melt_bolt11_quote, + get_check_melt_bolt11_quote, + post_melt_bolt11, + post_swap, + post_check, + post_restore + $(,$($path,)*)? + $(,$($auth_path,)*)? + ) + )] + /// Swagger api docs + pub struct ApiDoc; + }; +} + +// Configuration without auth feature +#[cfg(all(feature = "swagger", not(feature = "auth")))] +define_api_doc! { + schemas: [ Amount, BlindedMessage, BlindSignature, @@ -118,26 +158,70 @@ pub struct MintState { nut04::Settings, nut05::Settings, nut15::Settings - )), - info(description = "Cashu CDK mint APIs", title = "cdk-mintd",), - paths( - get_keys, - get_keyset_pubkeys, - get_keysets, - get_mint_info, - post_mint_bolt11_quote, - get_check_mint_bolt11_quote, - post_mint_bolt11, - post_melt_bolt11_quote, - get_check_melt_bolt11_quote, - post_melt_bolt11, - post_swap, - post_check, - post_restore - ) -)] -/// OpenAPI spec for the mint's v1 APIs -pub struct ApiDocV1; + ] +} + +// Configuration with auth feature +#[cfg(all(feature = "swagger", feature = "auth"))] +define_api_doc! { + schemas: [ + Amount, + BlindedMessage, + BlindSignature, + BlindSignatureDleq, + CheckStateRequest, + CheckStateResponse, + ContactInfo, + CurrencyUnit, + ErrorCode, + ErrorResponse, + HTLCWitness, + Keys, + KeysResponse, + KeysetResponse, + KeySet, + KeySetInfo, + MeltRequest, + MeltQuoteBolt11Request, + MeltQuoteBolt11Response, + MeltQuoteState, + MeltMethodSettings, + MintRequest, + MintResponse, + MintInfo, + MintQuoteBolt11Request, + MintQuoteBolt11Response, + MintQuoteState, + MintMethodSettings, + MintVersion, + Mpp, + MppMethodSettings, + Nuts, + P2PKWitness, + PaymentMethod, + Proof, + ProofDleq, + ProofState, + PublicKey, + RestoreRequest, + RestoreResponse, + SecretKey, + State, + SupportedSettings, + SwapRequest, + SwapResponse, + Witness, + nut04::Settings, + nut05::Settings, + nut15::Settings + ], + auth_schemas: [MintAuthRequest], + auth_paths: [ + crate::auth::get_auth_keysets, + crate::auth::get_blind_auth_keys, + crate::auth::post_mint_auth + ] +} /// Create mint [`Router`] with required endpoints for cashu mint with the default cache pub async fn create_mint_router(mint: Arc, include_bolt12: bool) -> Result { diff --git a/crates/cdk-mintd/src/main.rs b/crates/cdk-mintd/src/main.rs index 7c270043..ab332c6b 100644 --- a/crates/cdk-mintd/src/main.rs +++ b/crates/cdk-mintd/src/main.rs @@ -747,7 +747,7 @@ async fn start_services( if settings.info.enable_swagger_ui.unwrap_or(false) { mint_service = mint_service.merge( utoipa_swagger_ui::SwaggerUi::new("/swagger-ui") - .url("/api-docs/openapi.json", cdk_axum::ApiDocV1::openapi()), + .url("/api-docs/openapi.json", cdk_axum::ApiDoc::openapi()), ); } } diff --git a/crates/cdk/src/mint/builder.rs b/crates/cdk/src/mint/builder.rs index f028a587..b0cc1903 100644 --- a/crates/cdk/src/mint/builder.rs +++ b/crates/cdk/src/mint/builder.rs @@ -52,7 +52,8 @@ impl MintBuilder { .nut09(true) .nut10(true) .nut11(true) - .nut12(true), + .nut12(true) + .nut20(true), ..Default::default() };