feat(docs): add multiple examples support and webhook schema (#1864)

This commit is contained in:
Narayan Bhat
2023-08-09 11:25:56 +05:30
committed by GitHub
parent 27692fda85
commit f8ef52c645
6 changed files with 317 additions and 12 deletions

View File

@ -1,6 +1,7 @@
use common_utils::custom_serde;
use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;
use utoipa::ToSchema;
use crate::{disputes, enums as api_enums, payments, refunds};
@ -81,20 +82,33 @@ pub struct IncomingWebhookDetails {
pub resource_object: Vec<u8>,
}
#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone, Serialize, ToSchema)]
pub struct OutgoingWebhook {
/// The merchant id of the merchant
pub merchant_id: String,
/// The unique event id for each webhook
pub event_id: String,
/// The type of event this webhook corresponds to.
#[schema(value_type = EventType)]
pub event_type: api_enums::EventType,
/// This is specific to the flow, for ex: it will be `PaymentsResponse` for payments flow
pub content: OutgoingWebhookContent,
#[serde(default, with = "custom_serde::iso8601")]
/// The time at which webhook was sent
pub timestamp: PrimitiveDateTime,
}
#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone, Serialize, ToSchema)]
#[serde(tag = "type", content = "object", rename_all = "snake_case")]
pub enum OutgoingWebhookContent {
#[schema(value_type = PaymentsResponse)]
PaymentDetails(payments::PaymentsResponse),
#[schema(value_type = RefundResponse)]
RefundDetails(refunds::RefundResponse),
#[schema(value_type = DisputeResponse)]
DisputeDetails(Box<disputes::DisputeResponse>),
}