refactor(openapi): move openapi to separate crate to decrease compile times (#3110)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Sai Harsha Vardhan <56996463+sai-harsha-vardhan@users.noreply.github.com>
Co-authored-by: Sahkal Poddar <sahkalplanet@gmail.com>
Co-authored-by: Amisha Prabhat <55580080+Aprabhat19@users.noreply.github.com>
Co-authored-by: Sarthak Soni <76486416+Sarthak1799@users.noreply.github.com>
Co-authored-by: shashank_attarde <shashank.attarde@juspay.in>
Co-authored-by: Aprabhat19 <amishaprabhat@gmail.com>
Co-authored-by: sai-harsha-vardhan <harsha111hero@gmail.com>
Co-authored-by: Sahkal Poddar <sahkal.poddar@juspay.in>
Co-authored-by: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com>
This commit is contained in:
Narayan Bhat
2024-01-29 16:20:43 +05:30
committed by GitHub
parent dd0d2dc2dd
commit 7d8d68faba
48 changed files with 6620 additions and 1197 deletions

View File

@ -16,6 +16,7 @@ serde = { version = "1.0.193", features = ["derive", "rc"] }
serde_json = "1.0.108"
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" }

View File

@ -4,6 +4,7 @@ pub mod parser;
use common_enums::RoutableConnectors;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
use crate::types::{DataType, Metadata};
@ -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
@ -60,7 +61,7 @@ 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,
@ -68,7 +69,7 @@ pub struct NumberComparison {
}
/// 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,
@ -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"
@ -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,
}
@ -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>>,
}
@ -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")]
@ -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")]
#[serde(skip)]
pub choice_kind: RoutableChoiceKind,
#[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>),
}