Skip to content

Commit

Permalink
feat(routing): Updated openapi spec to include routing APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarthak1799 committed Nov 29, 2023
1 parent bd889c8 commit e7af4d5
Show file tree
Hide file tree
Showing 4 changed files with 2,063 additions and 866 deletions.
15 changes: 8 additions & 7 deletions crates/api_models/src/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use euclid::{
},
};
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

use crate::enums::{self, RoutableConnectors};

Expand All @@ -32,15 +33,15 @@ impl ConnectorSelection {
}
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct RoutingConfigRequest {
pub name: Option<String>,
pub description: Option<String>,
pub algorithm: Option<RoutingAlgorithm>,
pub profile_id: Option<String>,
}

#[derive(Debug, serde::Serialize)]
#[derive(Debug, serde::Serialize, ToSchema)]
pub struct ProfileDefaultRoutingConfig {
pub profile_id: String,
pub connectors: Vec<RoutableConnectorChoice>,
Expand All @@ -66,14 +67,14 @@ pub struct RoutingRetrieveResponse {
pub algorithm: Option<MerchantRoutingAlgorithm>,
}

#[derive(Debug, serde::Serialize)]
#[derive(Debug, serde::Serialize, ToSchema)]
#[serde(untagged)]
pub enum LinkedRoutingConfigRetrieveResponse {
MerchantAccountBased(RoutingRetrieveResponse),
ProfileBased(Vec<RoutingDictionaryRecord>),
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct MerchantRoutingAlgorithm {
pub id: String,
#[cfg(feature = "business_profile_routing")]
Expand Down Expand Up @@ -181,7 +182,7 @@ pub enum RoutableChoiceSerde {
},
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
#[cfg_attr(
feature = "connector_choice_bcompat",
serde(from = "RoutableChoiceSerde"),
Expand Down Expand Up @@ -581,7 +582,7 @@ impl RoutingAlgorithmRef {
}
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]

pub struct RoutingDictionaryRecord {
pub id: String,
Expand All @@ -601,7 +602,7 @@ pub struct RoutingDictionary {
pub records: Vec<RoutingDictionaryRecord>,
}

#[derive(serde::Serialize, serde::Deserialize, Debug)]
#[derive(serde::Serialize, serde::Deserialize, Debug, ToSchema)]
#[serde(untagged)]
pub enum RoutingKind {
Config(RoutingDictionary),
Expand Down
38 changes: 28 additions & 10 deletions crates/router/src/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,23 @@ Never share your secret api keys. Keep them guarded and secure.
// (name = "API Key", description = "Create and manage API Keys"),
(name = "Payouts", description = "Create and manage payouts"),
(name = "payment link", description = "Create payment link"),
(name = "Routing", description = "Create and manage routing configurations"),
),
paths(
crate::routes::refunds::refunds_create,
crate::routes::refunds::refunds_retrieve,
crate::routes::refunds::refunds_update,
crate::routes::refunds::refunds_list,
// Commenting this out as these are admin apis and not to be used by the merchant
// crate::routes::admin::merchant_account_create,
// crate::routes::admin::retrieve_merchant_account,
// crate::routes::admin::update_merchant_account,
// crate::routes::admin::delete_merchant_account,
// crate::routes::admin::payment_connector_create,
// crate::routes::admin::payment_connector_retrieve,
// crate::routes::admin::payment_connector_list,
// crate::routes::admin::payment_connector_update,
// crate::routes::admin::payment_connector_delete,
crate::routes::admin::merchant_account_create,
crate::routes::admin::retrieve_merchant_account,
crate::routes::admin::update_merchant_account,
crate::routes::admin::delete_merchant_account,
crate::routes::admin::payment_connector_create,
crate::routes::admin::payment_connector_retrieve,
crate::routes::admin::payment_connector_list,
crate::routes::admin::payment_connector_update,
crate::routes::admin::payment_connector_delete,
crate::routes::mandates::get_mandate,
crate::routes::mandates::revoke_mandate,
crate::routes::payments::payments_create,
Expand Down Expand Up @@ -119,6 +120,16 @@ Never share your secret api keys. Keep them guarded and secure.
crate::routes::gsm::get_gsm_rule,
crate::routes::gsm::update_gsm_rule,
crate::routes::gsm::delete_gsm_rule,
crate::routes::routing::routing_create_config,
crate::routes::routing::routing_link_config,
crate::routes::routing::routing_retrieve_config,
crate::routes::routing::routing_retrieve_dictionary,
crate::routes::routing::routing_unlink_config,
crate::routes::routing::routing_update_default_config,
crate::routes::routing::routing_retrieve_default_config,
crate::routes::routing::routing_retrieve_linked_config,
crate::routes::routing::routing_retrieve_default_config_for_profiles,
crate::routes::routing::routing_update_default_config_for_profile,
),
components(schemas(
crate::types::api::refunds::RefundRequest,
Expand Down Expand Up @@ -361,7 +372,14 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payments::PaymentLinkResponse,
api_models::payments::RetrievePaymentLinkResponse,
api_models::payments::PaymentLinkInitiateRequest,
api_models::payments::PaymentLinkObject
api_models::payments::PaymentLinkObject,
api_models::routing::RoutingConfigRequest,
api_models::routing::RoutingDictionaryRecord,
api_models::routing::RoutingKind,
api_models::routing::RoutableConnectorChoice,
api_models::routing::LinkedRoutingConfigRetrieveResponse,
api_models::routing::ProfileDefaultRoutingConfig,
api_models::routing::MerchantRoutingAlgorithm,
)),
modifiers(&SecurityAddon)
)]
Expand Down
144 changes: 144 additions & 0 deletions crates/router/src/routes/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ use crate::{
services::{api as oss_api, authentication as auth, authorization::permissions::Permission},
};

#[utoipa::path(
post,
path = "/routing",
request_body = RoutingConfigRequest,
responses(
(status = 200, description = "Routing config created", body = RoutingDictionaryRecord),
(status = 400, description = "Request body is malformed"),
(status = 500, description = "Internal server error"),
(status = 404, description = "Resource missing"),
(status = 422, description = "Unprocessable request"),
(status = 403, description = "Forbidden"),
),
tag = "Routing",
operation_id = "Create a routing config",
security(("api_key" = []), ("jwt_key" = []))
)]
#[cfg(feature = "olap")]
#[instrument(skip_all)]
pub async fn routing_create_config(
Expand Down Expand Up @@ -46,6 +62,22 @@ pub async fn routing_create_config(
.await
}

#[utoipa::path(
post,
path = "/routing/{algorithm_id}/activate",
params(
("algorithm_id" = String, Path, description = "The unique identifier for an algorithm"),
),
responses(
(status = 200, description = "Routing config activated", body = RoutingDictionaryRecord),
(status = 500, description = "Internal server error"),
(status = 404, description = "Resource missing"),
(status = 400, description = "Bad request")
),
tag = "Routing",
operation_id = "Activate a routing config",
security(("api_key" = []), ("jwt_key" = []))
)]
#[cfg(feature = "olap")]
#[instrument(skip_all)]
pub async fn routing_link_config(
Expand Down Expand Up @@ -81,6 +113,22 @@ pub async fn routing_link_config(
.await
}

#[utoipa::path(
get,
path = "/routing/{algorithm_id}",
params(
("algorithm_id" = String, Path, description = "The unique identifier for an algorithm"),
),
responses(
(status = 200, description = "Successfully fetched routing algorithm", body = MerchantRoutingAlgorithm),
(status = 500, description = "Internal server error"),
(status = 404, description = "Resource missing"),
(status = 403, description = "Forbidden")
),
tag = "Routing",
operation_id = "Retrieve a routing algorithm",
security(("api_key" = []), ("jwt_key" = []))
)]
#[cfg(feature = "olap")]
#[instrument(skip_all)]
pub async fn routing_retrieve_config(
Expand Down Expand Up @@ -111,6 +159,18 @@ pub async fn routing_retrieve_config(
.await
}

#[utoipa::path(
get,
path = "/routing",
responses(
(status = 200, description = "Successfully fetched routing dictionary", body = RoutingKind),
(status = 500, description = "Internal server error"),
(status = 404, description = "Resource missing")
),
tag = "Routing",
operation_id = "Retrieve routing dictionary",
security(("api_key" = []), ("jwt_key" = []))
)]
#[cfg(feature = "olap")]
#[instrument(skip_all)]
pub async fn routing_retrieve_dictionary(
Expand Down Expand Up @@ -171,6 +231,21 @@ pub async fn routing_retrieve_dictionary(
}
}

#[utoipa::path(
post,
path = "/routing/deactivate",
request_body = RoutingConfigRequest,
responses(
(status = 200, description = "Successfully deactivated routing config", body = RoutingDictionaryRecord),
(status = 500, description = "Internal server error"),
(status = 400, description = "Malformed request"),
(status = 403, description = "Malformed request"),
(status = 422, description = "Unprocessable request")
),
tag = "Routing",
operation_id = "Deactivate a routing config",
security(("api_key" = []), ("jwt_key" = []))
)]
#[cfg(feature = "olap")]
#[instrument(skip_all)]
pub async fn routing_unlink_config(
Expand Down Expand Up @@ -229,6 +304,20 @@ pub async fn routing_unlink_config(
}
}

#[utoipa::path(
post,
path = "/routing/default",
request_body = Vec<RoutableConnectorChoice>,
responses(
(status = 200, description = "Successfully updated default config", body = Vec<RoutableConnectorChoice>),
(status = 500, description = "Internal server error"),
(status = 400, description = "Malformed request"),
(status = 422, description = "Unprocessable request")
),
tag = "Routing",
operation_id = "Update default config",
security(("api_key" = []), ("jwt_key" = []))
)]
#[cfg(feature = "olap")]
#[instrument(skip_all)]
pub async fn routing_update_default_config(
Expand Down Expand Up @@ -257,6 +346,17 @@ pub async fn routing_update_default_config(
.await
}

#[utoipa::path(
get,
path = "/routing/default",
responses(
(status = 200, description = "Successfully retrieved default config", body = Vec<RoutableConnectorChoice>),
(status = 500, description = "Internal server error")
),
tag = "Routing",
operation_id = "Retrieve default config",
security(("api_key" = []), ("jwt_key" = []))
)]
#[cfg(feature = "olap")]
#[instrument(skip_all)]
pub async fn routing_retrieve_default_config(
Expand Down Expand Up @@ -474,6 +574,19 @@ pub async fn retrieve_decision_manager_config(
.await
}

#[utoipa::path(
get,
path = "/routing/active",
responses(
(status = 200, description = "Successfully retrieved active config", body = LinkedRoutingConfigRetrieveResponse),
(status = 500, description = "Internal server error"),
(status = 404, description = "Resource missing"),
(status = 403, description = "Forbidden")
),
tag = "Routing",
operation_id = "Retrieve active config",
security(("api_key" = []), ("jwt_key" = []))
)]
#[cfg(feature = "olap")]
#[instrument(skip_all)]
pub async fn routing_retrieve_linked_config(
Expand Down Expand Up @@ -531,6 +644,18 @@ pub async fn routing_retrieve_linked_config(
}
}

#[utoipa::path(
get,
path = "/routing/default/profile",
responses(
(status = 200, description = "Successfully retrieved default config", body = ProfileDefaultRoutingConfig),
(status = 500, description = "Internal server error"),
(status = 404, description = "Resource missing")
),
tag = "Routing",
operation_id = "Retrieve default config for profiles",
security(("api_key" = []), ("jwt_key" = []))
)]
#[cfg(feature = "olap")]
#[instrument(skip_all)]
pub async fn routing_retrieve_default_config_for_profiles(
Expand Down Expand Up @@ -562,6 +687,25 @@ pub async fn routing_retrieve_default_config_for_profiles(
.await
}

#[utoipa::path(
post,
path = "/routing/default/profile/{profile_id}",
request_body = Vec<RoutableConnectorChoice>,
params(
("profile_id" = String, Path, description = "The unique identifier for a profile"),
),
responses(
(status = 200, description = "Successfully updated default config for profile", body = ProfileDefaultRoutingConfig),
(status = 500, description = "Internal server error"),
(status = 404, description = "Resource missing"),
(status = 400, description = "Malformed request"),
(status = 422, description = "Unprocessable request"),
(status = 403, description = "Forbidden"),
),
tag = "Routing",
operation_id = "Update default config for profile",
security(("api_key" = []), ("jwt_key" = []))
)]
#[cfg(feature = "olap")]
#[instrument(skip_all)]
pub async fn routing_update_default_config_for_profile(
Expand Down
Loading

0 comments on commit e7af4d5

Please sign in to comment.