square_ox/
response.rs

1/*!
2This defines the possible responses you could receive from the
3[Square API](https://developer.squareup.com).
4
5The most of the structs have almost all of their fields set as optional as this makes dealing
6with the [Square API](https://developer.squareup.com)'s response pattern more manageable.
7 */
8
9use serde::{Deserialize, Serialize};
10
11#[derive(Clone, Debug, Serialize, Deserialize)]
12#[non_exhaustive]
13/// The [SquareResponse](SquareResponse) response defines the generic response type that encompasses
14/// almost all possible [Square API](https://developer.squareup.com) responses. All fields are
15/// optional to allow for handling of possible errors returned by the
16/// [Square API](https://developer.squareup.com).
17pub struct SquareResponse {
18    #[serde(flatten)]
19    pub response: Option<crate::objects::Response>,
20    #[serde(flatten)]
21    pub opt_response01: Option<crate::objects::Response>,
22    #[serde(flatten)]
23    pub opt_response02: Option<crate::objects::Response>,
24    #[serde(flatten)]
25    pub opt_response03: Option<crate::objects::Response>,
26    #[serde(default)]
27    pub errors: Option<Vec<ResponseError>>,
28    #[serde(default)]
29    pub cursor: Option<String>,
30    #[serde(default)]
31    pub id_mapping: Option<Vec<(String, String)>>,
32    #[serde(default)]
33    pub id: Option<String>,
34    #[serde(default)]
35    pub cancelled_order_id: Option<String>,
36    #[serde(default)]
37    pub deleted_object_ids: Option<Vec<String>>,
38    #[serde(default)]
39    pub deleted_at: Option<String>,
40    #[serde(default)]
41    pub latest_time: Option<String>,
42}
43
44
45/// The [ResponseError](ResponseError) defines the error schema returned by the
46/// [Square API](https://developer.squareup.com) should an error occur. This makes error handling
47/// possible by checking if the error field of the [SquareResponse](SquareResponse) is some.
48#[derive(Clone, Debug, Serialize, Deserialize)]
49pub struct ResponseError {
50    pub category: String,
51    pub code: String,
52    #[serde(default)]
53    pub detail: Option<String>,
54    #[serde(default)]
55    pub field: Option<String>,
56}