openzeppelin_relayer/
openapi.rs

1use crate::{
2    api::routes::{
3        docs::{
4            health_docs, network_docs, notification_docs, plugin_docs, relayer_docs, signer_docs,
5        },
6        metrics,
7    },
8    domain, models,
9    services::plugins,
10};
11use utoipa::{
12    openapi::security::{Http, HttpAuthScheme, SecurityScheme},
13    Modify, OpenApi,
14};
15
16const API_VERSION: &str = env!("CARGO_PKG_VERSION");
17
18struct VersionFromEnv;
19
20impl Modify for VersionFromEnv {
21    fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) {
22        openapi.info.version = API_VERSION.to_string();
23    }
24}
25struct SecurityAddon;
26
27impl Modify for SecurityAddon {
28    fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) {
29        if let Some(components) = openapi.components.as_mut() {
30            components.add_security_scheme(
31                "bearer_auth",
32                SecurityScheme::Http(Http::new(HttpAuthScheme::Bearer)),
33            );
34        }
35    }
36}
37/// # OpenAPI Specification Generator
38///
39/// This utility generates an OpenAPI specification JSON file from the
40/// OpenZeppelin Relayer API definitions.
41#[derive(OpenApi)]
42#[openapi(
43    modifiers(&SecurityAddon, &VersionFromEnv),
44    tags(
45      (name = "Relayers", description = "Relayers are the core components of the OpenZeppelin Relayer API. They are responsible for executing transactions on behalf of users and providing a secure and reliable way to interact with the blockchain."),
46      (name = "Plugins", description = "Plugins are TypeScript functions that can be used to extend the OpenZeppelin Relayer API functionality."),
47      (name = "Notifications", description = "Notifications are responsible for showing the notifications related to the relayers."),
48      (name = "Signers", description = "Signers are responsible for signing the transactions related to the relayers."),
49      (name = "Networks", description = "Networks represent blockchain network configurations including RPC endpoints and network-specific settings."),
50      (name = "Metrics", description = "Metrics are responsible for showing the metrics related to the relayers."),
51      (name = "Health", description = "Health is responsible for showing the health of the relayers.")
52    ),
53    info(description = "OpenZeppelin Relayer API", version = "0.0.0", title = "OpenZeppelin Relayer API",  license(
54        name = "AGPL-3.0 license",
55        url = "https://github.com/OpenZeppelin/openzeppelin-relayer/blob/main/LICENSE"
56    ),
57    contact(
58        name = "OpenZeppelin",
59        url = "https://www.openzeppelin.com",
60    ),
61    terms_of_service = "https://www.openzeppelin.com/tos"),
62    paths(
63        relayer_docs::doc_get_relayer,
64        relayer_docs::doc_list_relayers,
65        relayer_docs::doc_create_relayer,
66        relayer_docs::doc_update_relayer,
67        relayer_docs::doc_delete_relayer,
68        relayer_docs::doc_get_relayer_balance,
69        relayer_docs::doc_get_transaction_by_nonce,
70        relayer_docs::doc_get_transaction_by_id,
71        relayer_docs::doc_list_transactions,
72        relayer_docs::doc_get_relayer_status,
73        relayer_docs::doc_sign_typed_data,
74        relayer_docs::doc_sign,
75        relayer_docs::doc_sign_transaction,
76        relayer_docs::doc_cancel_transaction,
77        relayer_docs::doc_delete_pending_transactions,
78        relayer_docs::doc_rpc,
79        relayer_docs::doc_send_transaction,
80        relayer_docs::doc_replace_transaction,
81        relayer_docs::doc_quote_sponsored_transaction,
82        relayer_docs::doc_build_sponsored_transaction,
83        health_docs::doc_health,
84        health_docs::doc_readiness,
85        metrics::list_metrics,
86        metrics::metric_detail,
87        metrics::scrape_metrics,
88        plugin_docs::doc_call_plugin,
89        plugin_docs::doc_call_plugin_get,
90        plugin_docs::doc_list_plugins,
91        plugin_docs::doc_get_plugin,
92        plugin_docs::doc_update_plugin,
93        notification_docs::doc_list_notifications,
94        notification_docs::doc_get_notification,
95        notification_docs::doc_create_notification,
96        notification_docs::doc_update_notification,
97        notification_docs::doc_delete_notification,
98        signer_docs::doc_list_signers,
99        signer_docs::doc_get_signer,
100        signer_docs::doc_create_signer,
101        signer_docs::doc_update_signer,
102        signer_docs::doc_delete_signer,
103        network_docs::doc_list_networks,
104        network_docs::doc_get_network,
105        network_docs::doc_update_network,
106    ),
107    components(schemas(
108        models::RelayerResponse,
109        models::CreateRelayerRequest,
110        models::NetworkPolicyResponse,
111        models::EvmPolicyResponse,
112        models::SolanaPolicyResponse,
113        models::StellarPolicyResponse,
114        models::UpdateRelayerRequest,
115        models::NetworkResponse,
116        models::UpdateNetworkRequest,
117        models::RpcUrlEntry,
118        domain::SignDataRequest,
119        domain::SignTypedDataRequest,
120        domain::SignTransactionRequest,
121        domain::SignTransactionExternalResponse,
122        models::PluginCallRequest,
123        models::PluginMetadata,
124        models::UpdatePluginRequest,
125        plugins::PluginHandlerError,
126        plugins::LogEntry,
127        plugins::LogLevel
128    ))
129)]
130pub struct ApiDoc;