openzeppelin_relayer/
openapi.rs

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