feat(openapi): automatically generate OpenAPI spec from code (#318)

Co-authored-by: bernard eugine <bernard.eugine@bernard.eugine-MacBookPro>
Co-authored-by: Sanchith Hegde <sanchith.hegde@juspay.in>
This commit is contained in:
bernard-eugine
2023-01-09 16:09:49 +05:30
committed by GitHub
parent c807713a6f
commit 3fe60b5a48
15 changed files with 1401 additions and 14 deletions

View File

@ -1,22 +1,51 @@
use common_utils::custom_serde;
use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;
use utoipa::ToSchema;
use crate::enums;
#[derive(Default, Debug, Clone, Deserialize)]
#[derive(Default, Debug, ToSchema, Clone, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct RefundRequest {
/// Unique Identifier for the Refund. This is to ensure idempotency for multiple partial refund initiated against the same payment. If the identifiers is not defined by the merchant, this filed shall be auto generated and provide in the API response. It is recommended to generate uuid(v4) as the refund_id.
#[schema(
max_length = 30,
min_length = 30,
example = "ref_mbabizu24mvu3mela5njyhpit4"
)]
pub refund_id: Option<String>,
/// Total amount for which the refund is to be initiated. Amount for the payment in lowest denomination of the currency. (i.e) in cents for USD denomination, in paisa for INR denomination etc. If not provided, this will default to the full payment amount
#[schema(
max_length = 30,
min_length = 30,
example = "pay_mbabizu24mvu3mela5njyhpit4"
)]
pub payment_id: String,
/// The identifier for the Merchant Account
#[schema(max_length = 255, example = "y3oqhf46pyzuxjbcn2giaqnb44")]
pub merchant_id: Option<String>,
/// Total amount for which the refund is to be initiated. Amount for the payment in lowest denomination of the currency. (i.e) in cents for USD denomination, in paisa for INR denomination etc., If not provided, this will default to the full payment amount
#[schema(minimum = 100, example = 6540)]
pub amount: Option<i64>,
/// An arbitrary string attached to the object. Often useful for displaying to users and your customer support executive
#[schema(max_length = 255, example = "Customer returned the product")]
pub reason: Option<String>,
/// The type of refund based on waiting time for processing: Scheduled or Instant Refund
#[schema(default = "Instant", example = "Instant")]
pub refund_type: Option<RefundType>,
/// You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.
#[schema(value_type = Option<Object>, example = r#"{ "city": "NY", "unit": "245" }"#)]
pub metadata: Option<serde_json::Value>,
}
#[derive(Default, Debug, Clone, Deserialize)]
#[derive(Default, Debug, Clone, ToSchema, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum RefundType {
#[default]
@ -24,7 +53,7 @@ pub enum RefundType {
Instant,
}
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, ToSchema)]
pub struct RefundResponse {
pub refund_id: String,
pub payment_id: String,
@ -32,6 +61,7 @@ pub struct RefundResponse {
pub currency: String,
pub reason: Option<String>,
pub status: RefundStatus,
#[schema(value_type = Option<Object>)]
pub metadata: Option<serde_json::Value>,
pub error_message: Option<String>,
}
@ -65,7 +95,7 @@ pub struct RefundListResponse {
pub data: Vec<RefundResponse>,
}
#[derive(Debug, Eq, Clone, PartialEq, Default, Deserialize, Serialize)]
#[derive(Debug, Eq, Clone, PartialEq, Default, Deserialize, Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum RefundStatus {
Succeeded,