Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(routing): Updated openapi spec to include routing APIs #3012

Merged
merged 29 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e7af4d5
feat(routing): Updated openapi spec to include routing APIs
Sarthak1799 Nov 29, 2023
0d14152
Merge branch 'main' of github.com:juspay/hyperswitch into open-api-ro…
Sarthak1799 Nov 29, 2023
8b96e66
fix(routing): Fixed trait errors
Sarthak1799 Nov 29, 2023
86d54ed
fix(routing): Fixed spec
Sarthak1799 Nov 29, 2023
152fba1
fix(routing): Temp schema changes for ast
Sarthak1799 Nov 30, 2023
dadb4bf
chore: run formatter
hyperswitch-bot[bot] Nov 30, 2023
1165e62
fix(routing): Implemented additional types in ast for openapi
Sarthak1799 Dec 1, 2023
ae95aa5
fix(routing): Fixed errors
Sarthak1799 Dec 1, 2023
942e88a
fix(routing): Fixed errors
Sarthak1799 Dec 1, 2023
7401da3
Merge branch 'main' of github.com:juspay/hyperswitch into open-api-ro…
Sarthak1799 Dec 5, 2023
df1ffa5
fix(routing): Added query params
Sarthak1799 Dec 5, 2023
76813a1
Merge branch 'main' into open-api-routing
Sarthak1799 Dec 7, 2023
abc08cf
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Dec 7, 2023
6fb4bc2
fix(routing): Resolved comments
Sarthak1799 Dec 8, 2023
181fb9d
Merge branch 'main' into open-api-routing
Sarthak1799 Dec 11, 2023
66d2bcf
refactor(routing): remove stale routing openapi docs
vspecky Dec 11, 2023
2efd0a9
refactor(routing): remove stale routing openapi docs
vspecky Dec 11, 2023
b27cf40
refactor(openapi): update routing docs in openapi spec
vspecky Dec 11, 2023
3ae9650
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Dec 11, 2023
f59f4cd
refactor(api_models): change routing field example for payments request
vspecky Dec 12, 2023
51893d2
Merge branch 'move_openapi_to_crate' into open-api-routing
Narayanbhat166 Dec 19, 2023
17e1e41
moved the api for routing to tehopenapi crate
Aprabhat19 Dec 19, 2023
01e4fbb
clippy runs
Aprabhat19 Dec 19, 2023
a09ebd3
add routing routes
Aprabhat19 Dec 19, 2023
241f499
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Dec 19, 2023
b27b0c3
updated spec
Aprabhat19 Dec 19, 2023
8182801
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Dec 19, 2023
dd9dc8d
minor fixes
Aprabhat19 Dec 19, 2023
3b966de
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Dec 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ pub struct MerchantAccountCreate {
pub webhook_details: Option<WebhookDetails>,

/// The routing algorithm to be used for routing payments to desired connectors
#[schema(value_type = Option<Object>,example = json!({"type": "single", "data": "stripe"}))]
#[serde(skip)]
#[schema(deprecated)]
pub routing_algorithm: Option<serde_json::Value>,

/// The routing algorithm to be used for routing payouts to desired connectors
Expand Down Expand Up @@ -135,7 +136,8 @@ pub struct MerchantAccountUpdate {
pub webhook_details: Option<WebhookDetails>,

/// The routing algorithm to be used for routing payments to desired connectors
#[schema(value_type = Option<Object>,example = json!({"type": "single", "data": "stripe"}))]
#[serde(skip)]
#[schema(deprecated)]
pub routing_algorithm: Option<serde_json::Value>,

/// The routing algorithm to be used for routing payouts to desired connectors
Expand Down Expand Up @@ -232,7 +234,8 @@ pub struct MerchantAccountResponse {
pub webhook_details: Option<serde_json::Value>,

/// The routing algorithm to be used to process the incoming request from merchant to outgoing payment processor or payment method. The default is 'Custom'
#[schema(value_type = Option<RoutingAlgorithm>, max_length = 255, example = "custom")]
#[serde(skip)]
#[schema(deprecated)]
pub routing_algorithm: Option<serde_json::Value>,

/// The routing algorithm to be used for routing payouts to desired connectors
Expand Down
2 changes: 0 additions & 2 deletions crates/api_models/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ use utoipa::ToSchema;
serde::Serialize,
strum::Display,
strum::EnumString,
ToSchema,
)]

/// The routing algorithm to be used to process the incoming request from merchant to outgoing payment processor or payment method. The default is 'Custom'
#[schema(example = "custom")]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum RoutingAlgorithm {
Expand Down
32 changes: 17 additions & 15 deletions crates/api_models/src/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ use euclid::{
},
};
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

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

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[serde(tag = "type", content = "data", rename_all = "snake_case")]
pub enum ConnectorSelection {
Priority(Vec<RoutableConnectorChoice>),
Expand All @@ -31,15 +32,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 @@ -60,19 +61,19 @@ pub struct RoutingRetrieveLinkQuery {
pub profile_id: Option<String>,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
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 @@ -153,14 +154,14 @@ impl EuclidAnalysable for ConnectorSelection {
}
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct ConnectorVolumeSplit {
pub connector: RoutableConnectorChoice,
pub split: u8,
}

#[cfg(feature = "connector_choice_bcompat")]
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema)]
pub enum RoutableChoiceKind {
OnlyConnector,
FullStruct,
Expand All @@ -180,7 +181,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 @@ -322,7 +323,7 @@ impl DetailedConnectorChoice {
}
}

#[derive(Debug, Copy, Clone, serde::Serialize, serde::Deserialize, strum::Display)]
#[derive(Debug, Copy, Clone, serde::Serialize, serde::Deserialize, strum::Display, ToSchema)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum RoutingAlgorithmKind {
Expand All @@ -339,7 +340,7 @@ pub struct RoutingPayloadWrapper {
pub profile_id: String,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
#[serde(
tag = "type",
content = "data",
Expand All @@ -350,6 +351,7 @@ pub enum RoutingAlgorithm {
Single(Box<RoutableConnectorChoice>),
Priority(Vec<RoutableConnectorChoice>),
VolumeSplit(Vec<ConnectorVolumeSplit>),
#[schema(value_type=ProgramConnectorSelection)]
Advanced(euclid::frontend::ast::Program<ConnectorSelection>),
}

Expand Down Expand Up @@ -390,7 +392,7 @@ impl TryFrom<RoutingAlgorithmSerde> for RoutingAlgorithm {
}
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
#[serde(
tag = "type",
content = "data",
Expand Down Expand Up @@ -516,7 +518,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 @@ -529,14 +531,14 @@ pub struct RoutingDictionaryRecord {
pub modified_at: i64,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct RoutingDictionary {
pub merchant_id: String,
pub active_id: Option<String>,
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
1 change: 1 addition & 0 deletions crates/common_enums/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub enum AttemptStatus {
strum::EnumString,
strum::EnumIter,
strum::EnumVariantNames,
ToSchema,
)]
#[router_derive::diesel_enum(storage_type = "db_enum")]
#[serde(rename_all = "snake_case")]
Expand Down
1 change: 1 addition & 0 deletions crates/euclid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ serde = { version = "1.0.163", features = ["derive", "rc"] }
serde_json = "1.0.96"
strum = { version = "0.25", features = ["derive"] }
thiserror = "1.0.43"
utoipa = { version = "3.3.0", features = ["preserve_order"] }

# First party dependencies
common_enums = { version = "0.1.0", path = "../common_enums" }
Expand Down
53 changes: 45 additions & 8 deletions crates/euclid/src/frontend/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod parser;

use common_enums::RoutableConnectors;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

use crate::types::{DataType, Metadata};

Expand All @@ -14,14 +15,14 @@ pub struct ConnectorChoice {
pub sub_label: Option<String>,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ToSchema)]
pub struct MetadataValue {
pub key: String,
pub value: String,
}

/// Represents a value in the DSL
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ToSchema)]
#[serde(tag = "type", content = "value", rename_all = "snake_case")]
pub enum ValueType {
/// Represents a number literal
Expand Down Expand Up @@ -60,15 +61,15 @@ impl ValueType {
}

/// Represents a number comparison for "NumberComparisonArrayValue"
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct NumberComparison {
pub comparison_type: ComparisonType,
pub number: i64,
}

/// Conditional comparison type
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum ComparisonType {
Equal,
Expand All @@ -80,7 +81,7 @@ pub enum ComparisonType {
}

/// Represents a single comparison condition.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct Comparison {
/// The left hand side which will always be a domain input identifier like "payment.method.cardtype"
Expand All @@ -92,6 +93,7 @@ pub struct Comparison {
/// Additional metadata that the Static Analyzer and Backend does not touch.
/// This can be used to store useful information for the frontend and is required for communication
/// between the static analyzer and the frontend.
#[schema(value_type=HashMap<String, serde_json::Value>)]
pub metadata: Metadata,
}

Expand All @@ -112,9 +114,10 @@ pub type IfCondition = Vec<Comparison>;
/// }
/// }
/// ```
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct IfStatement {
#[schema(value_type=Vec<Comparison>)]
pub condition: IfCondition,
pub nested: Option<Vec<IfStatement>>,
}
Expand All @@ -134,8 +137,9 @@ pub struct IfStatement {
/// }
/// ```

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
#[serde(rename_all = "camelCase")]
#[aliases(RuleConnectorSelection = Rule<ConnectorSelection>)]
pub struct Rule<O> {
pub name: String,
#[serde(alias = "routingOutput")]
Expand All @@ -145,10 +149,43 @@ pub struct Rule<O> {

/// The program, having a default connector selection and
/// a bunch of rules. Also can hold arbitrary metadata.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
#[serde(rename_all = "camelCase")]
#[aliases(ProgramConnectorSelection = Program<ConnectorSelection>)]
pub struct Program<O> {
pub default_selection: O,
#[schema(value_type=RuleConnectorSelection)]
pub rules: Vec<Rule<O>>,
#[schema(value_type=HashMap<String, serde_json::Value>)]
pub metadata: Metadata,
}

#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct RoutableConnectorChoice {
#[cfg(feature = "connector_choice_bcompat")]
pub choice_kind: RoutableChoiceKind,
// pub connector: RoutableConnectors,
#[cfg(feature = "connector_choice_mca_id")]
pub merchant_connector_id: Option<String>,
#[cfg(not(feature = "connector_choice_mca_id"))]
pub sub_label: Option<String>,
}

#[derive(Debug, Clone, Deserialize, Serialize, ToSchema)]
pub enum RoutableChoiceKind {
OnlyConnector,
FullStruct,
}

#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct ConnectorVolumeSplit {
pub connector: RoutableConnectorChoice,
pub split: u8,
}

#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[serde(tag = "type", content = "data", rename_all = "snake_case")]
pub enum ConnectorSelection {
Priority(Vec<RoutableConnectorChoice>),
VolumeSplit(Vec<ConnectorVolumeSplit>),
}
Loading
Loading