Skip to content

Commit

Permalink
generate openapi spec
Browse files Browse the repository at this point in the history
  • Loading branch information
hrithikesh026 committed Dec 3, 2023
1 parent a3260f1 commit b4f74fe
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/common_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ strum = { version = "0.24.1", features = ["derive"] }
thiserror = "1.0.40"
time = { version = "0.3.21", features = ["serde", "serde-well-known", "std"] }
tokio = { version = "1.28.2", features = ["macros", "rt-multi-thread"], optional = true }
utoipa = { version = "3.3.0", features = ["preserve_order"] }

# First party crates
common_enums = { version = "0.1.0", path = "../common_enums" }
Expand Down
5 changes: 3 additions & 2 deletions crates/common_utils/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//! Types that can be used in other crates
use error_stack::{IntoReport, ResultExt};
use serde::{de::Visitor, Deserialize, Deserializer};
use utoipa::ToSchema;

use crate::{
consts,
errors::{CustomResult, PercentageError},
};

/// Represents Percentage Value between 0 and 100 both inclusive
#[derive(Clone, Default, Debug, PartialEq, serde::Serialize)]
#[derive(Clone, Default, Debug, PartialEq, serde::Serialize, ToSchema)]
pub struct Percentage<const PRECISION: u8> {
// this value will range from 0 to 100, decimal length defined by precision macro
/// Percentage value ranging between 0 and 100
Expand Down Expand Up @@ -141,7 +142,7 @@ impl<'de, const PRECISION: u8> Deserialize<'de> for Percentage<PRECISION> {
}

/// represents surcharge type and value
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]
#[serde(rename_all = "snake_case", tag = "type", content = "value")]
pub enum Surcharge {
/// Fixed Surcharge value
Expand Down
5 changes: 4 additions & 1 deletion crates/router/src/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payments::CaptureResponse,
api_models::payment_methods::RequiredFieldInfo,
api_models::payment_methods::MaskedBankDetails,
api_models::payment_methods::SurchargeDetailsResponse,
api_models::refunds::RefundListRequest,
api_models::refunds::RefundListResponse,
api_models::payments::TimeRange,
Expand Down Expand Up @@ -361,7 +362,9 @@ 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,
common_utils::types::Surcharge,
common_utils::types::Percentage<{common_utils::consts::SURCHARGE_PERCENTAGE_PRECISION_LENGTH}>
)),
modifiers(&SecurityAddon)
)]
Expand Down
105 changes: 105 additions & 0 deletions openapi/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -5102,6 +5102,14 @@
],
"nullable": true
},
"surcharge_details": {
"allOf": [
{
"$ref": "#/components/schemas/SurchargeDetailsResponse"
}
],
"nullable": true
},
"requires_cvv": {
"type": "boolean",
"description": "Whether this payment method requires CVV to be collected",
Expand Down Expand Up @@ -11158,6 +11166,20 @@
}
}
},
"Percentage": {
"type": "object",
"description": "Represents Percentage Value between 0 and 100 both inclusive",
"required": [
"percentage"
],
"properties": {
"percentage": {
"type": "number",
"format": "float",
"description": "Percentage value ranging between 0 and 100"
}
}
},
"PhoneDetails": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -11975,6 +11997,89 @@
}
}
},
"Surcharge": {
"oneOf": [
{
"type": "object",
"required": [
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"fixed"
]
},
"value": {
"type": "integer",
"format": "int64",
"description": "Fixed Surcharge value"
}
}
},
{
"type": "object",
"required": [
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"rate"
]
},
"value": {
"$ref": "#/components/schemas/Percentage"
}
}
}
],
"description": "represents surcharge type and value",
"discriminator": {
"propertyName": "type"
}
},
"SurchargeDetailsResponse": {
"type": "object",
"required": [
"surcharge",
"display_surcharge_amount",
"display_tax_on_surcharge_amount",
"display_final_amount"
],
"properties": {
"surcharge": {
"$ref": "#/components/schemas/Surcharge"
},
"tax_on_surcharge": {
"allOf": [
{
"$ref": "#/components/schemas/Percentage"
}
],
"nullable": true
},
"display_surcharge_amount": {
"type": "number",
"format": "double",
"description": "surcharge amount for this payment"
},
"display_tax_on_surcharge_amount": {
"type": "number",
"format": "double",
"description": "tax on surcharge amount for this payment"
},
"display_final_amount": {
"type": "number",
"format": "double",
"description": "sum of original amount,"
}
}
},
"SwishQrData": {
"type": "object"
},
Expand Down

0 comments on commit b4f74fe

Please sign in to comment.