Skip to content

Commit 7a9a37c

Browse files
authored
rust: Some fixes for the new Ingest Source API (#1804)
Follow-up to #1754, #1797.
2 parents 74bac68 + 37c8796 commit 7a9a37c

File tree

6 files changed

+240
-12
lines changed

6 files changed

+240
-12
lines changed

rust/src/models/ingest_source_in.rs

+25
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,55 @@ pub struct IngestSourceIn {
2323
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
2424
#[serde(tag = "type", content = "config")]
2525
pub enum IngestSourceInConfig {
26+
#[serde(rename = "generic-webhook")]
2627
GenericWebhook,
28+
#[serde(rename = "cron")]
2729
Cron(CronConfig),
30+
#[serde(rename = "adobe-sign")]
2831
AdobeSign(AdobeSignConfig),
32+
#[serde(rename = "beehiiv")]
2933
Beehiiv(SvixConfig),
34+
#[serde(rename = "brex")]
3035
Brex(SvixConfig),
36+
#[serde(rename = "clerk")]
3137
Clerk(SvixConfig),
38+
#[serde(rename = "docusign")]
3239
Docusign(DocusignConfig),
40+
#[serde(rename = "github")]
3341
Github(GithubConfig),
42+
#[serde(rename = "guesty")]
3443
Guesty(SvixConfig),
44+
#[serde(rename = "hubspot")]
3545
Hubspot(HubspotConfig),
46+
#[serde(rename = "incident-io")]
3647
IncidentIo(SvixConfig),
48+
#[serde(rename = "lithic")]
3749
Lithic(SvixConfig),
50+
#[serde(rename = "nash")]
3851
Nash(SvixConfig),
52+
#[serde(rename = "pleo")]
3953
Pleo(SvixConfig),
54+
#[serde(rename = "replicate")]
4055
Replicate(SvixConfig),
56+
#[serde(rename = "resend")]
4157
Resend(SvixConfig),
58+
#[serde(rename = "safebase")]
4259
Safebase(SvixConfig),
60+
#[serde(rename = "sardine")]
4361
Sardine(SvixConfig),
62+
#[serde(rename = "segment")]
4463
Segment(SegmentConfig),
64+
#[serde(rename = "shopify")]
4565
Shopify(ShopifyConfig),
66+
#[serde(rename = "slack")]
4667
Slack(SlackConfig),
68+
#[serde(rename = "stripe")]
4769
Stripe(StripeConfig),
70+
#[serde(rename = "stych")]
4871
Stych(SvixConfig),
72+
#[serde(rename = "svix")]
4973
Svix(SvixConfig),
74+
#[serde(rename = "zoom")]
5075
Zoom(ZoomConfig),
5176
}
5277

rust/src/models/ingest_source_out.rs

+25
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,55 @@ pub struct IngestSourceOut {
3838
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
3939
#[serde(tag = "type", content = "config")]
4040
pub enum IngestSourceOutConfig {
41+
#[serde(rename = "generic-webhook")]
4142
GenericWebhook,
43+
#[serde(rename = "cron")]
4244
Cron(CronConfig),
45+
#[serde(rename = "adobe-sign")]
4346
AdobeSign(AdobeSignConfigOut),
47+
#[serde(rename = "beehiiv")]
4448
Beehiiv(SvixConfigOut),
49+
#[serde(rename = "brex")]
4550
Brex(SvixConfigOut),
51+
#[serde(rename = "clerk")]
4652
Clerk(SvixConfigOut),
53+
#[serde(rename = "docusign")]
4754
Docusign(DocusignConfigOut),
55+
#[serde(rename = "github")]
4856
Github(GithubConfigOut),
57+
#[serde(rename = "guesty")]
4958
Guesty(SvixConfigOut),
59+
#[serde(rename = "hubspot")]
5060
Hubspot(HubspotConfigOut),
61+
#[serde(rename = "incident-io")]
5162
IncidentIo(SvixConfigOut),
63+
#[serde(rename = "lithic")]
5264
Lithic(SvixConfigOut),
65+
#[serde(rename = "nash")]
5366
Nash(SvixConfigOut),
67+
#[serde(rename = "pleo")]
5468
Pleo(SvixConfigOut),
69+
#[serde(rename = "replicate")]
5570
Replicate(SvixConfigOut),
71+
#[serde(rename = "resend")]
5672
Resend(SvixConfigOut),
73+
#[serde(rename = "safebase")]
5774
Safebase(SvixConfigOut),
75+
#[serde(rename = "sardine")]
5876
Sardine(SvixConfigOut),
77+
#[serde(rename = "segment")]
5978
Segment(SegmentConfigOut),
79+
#[serde(rename = "shopify")]
6080
Shopify(ShopifyConfigOut),
81+
#[serde(rename = "slack")]
6182
Slack(SlackConfigOut),
83+
#[serde(rename = "stripe")]
6284
Stripe(StripeConfigOut),
85+
#[serde(rename = "stych")]
6386
Stych(SvixConfigOut),
87+
#[serde(rename = "svix")]
6488
Svix(SvixConfigOut),
89+
#[serde(rename = "zoom")]
6590
Zoom(ZoomConfigOut),
6691
}
6792

rust/src/models/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ pub mod message_attempt_endpoint_out;
117117
pub mod message_events_out;
118118
pub mod validation_error;
119119

120-
#[rustfmt::skip]
121120
pub use self::{
122121
adobe_sign_config::AdobeSignConfig,
123122
adobe_sign_config_out::AdobeSignConfigOut,
@@ -177,8 +176,8 @@ pub use self::{
177176
ingest_endpoint_secret_out::IngestEndpointSecretOut,
178177
ingest_endpoint_update::IngestEndpointUpdate,
179178
ingest_source_consumer_portal_access_in::IngestSourceConsumerPortalAccessIn,
180-
ingest_source_in::IngestSourceIn,
181-
ingest_source_out::IngestSourceOut,
179+
ingest_source_in::{IngestSourceIn, IngestSourceInConfig},
180+
ingest_source_out::{IngestSourceOut, IngestSourceOutConfig},
182181
integration_in::IntegrationIn,
183182
integration_key_out::IntegrationKeyOut,
184183
integration_out::IntegrationOut,
@@ -227,11 +226,12 @@ pub use self::{
227226
svix_config_out::SvixConfigOut,
228227
zoom_config::ZoomConfig,
229228
zoom_config_out::ZoomConfigOut,
230-
// not currently generated
231-
message_events_out::MessageEventsOut,
232-
message_attempt_endpoint_out::MessageAttemptEndpointOut,
229+
};
230+
231+
// not currently generated
232+
pub use self::{
233+
http_error_out::HttpErrorOut, http_validation_error::HttpValidationError,
233234
list_response_message_attempt_endpoint_out::ListResponseMessageAttemptEndpointOut,
234-
http_error_out::HttpErrorOut,
235-
http_validation_error::HttpValidationError,
235+
message_attempt_endpoint_out::MessageAttemptEndpointOut, message_events_out::MessageEventsOut,
236236
validation_error::ValidationError,
237237
};

rust/templates/component_type_summary.rs.jinja

+10-3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,20 @@ pub mod http_error_out;
1313
pub mod http_validation_error;
1414
pub mod validation_error;
1515

16-
#[rustfmt::skip]
1716
pub use self::{
1817
{% for _, type in types | items -%}
19-
{{ type.name | to_snake_case }}::{{ type.name | to_upper_camel_case }},
18+
{% set type_name = type.name | to_upper_camel_case -%}
19+
{{ type.name | to_snake_case }}::{
20+
{{ type_name }},
21+
{% if type.kind == "struct_enum" and type.fields | length > 0 -%}
22+
{{ type_name }}{{ type.content_field | to_upper_camel_case }}
23+
{% endif -%}
24+
},
2025
{% endfor -%}
26+
};
2127

22-
// not currently generated
28+
// not currently generated
29+
pub use self::{
2330
message_events_out::MessageEventsOut,
2431
message_attempt_endpoint_out::MessageAttemptEndpointOut,
2532
list_response_message_attempt_endpoint_out::ListResponseMessageAttemptEndpointOut,

rust/templates/types/struct_enum.rs.jinja

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use super::{
3030
#[serde(tag = "{{ type.discriminator_field }}", content = "{{ type.content_field }}")]
3131
pub enum {{ enum_type_name }} {
3232
{% for variant in type.variants -%}
33+
#[serde(rename = "{{ variant.name }}")]
3334
{{ variant.name | to_upper_camel_case -}}
3435
{% if variant.schema_ref is defined -%}
3536
({{ variant.schema_ref | to_upper_camel_case }})

rust/tests/it/model_serialization.rs

+171-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
use svix::api::ListResponseApplicationOut;
1+
use std::fmt::Debug;
2+
3+
use serde::de::DeserializeOwned;
4+
use serde_json::json;
5+
use svix::api::{
6+
CronConfig, IngestSourceIn, IngestSourceInConfig, IngestSourceOut, IngestSourceOutConfig,
7+
ListResponseApplicationOut, SegmentConfig, SegmentConfigOut, SvixConfig, SvixConfigOut,
8+
};
29

310
#[test]
411
fn test_list_response_xxx_out() {
@@ -28,3 +35,166 @@ fn test_list_response_xxx_out() {
2835

2936
assert_eq!(expected_model, loaded_json);
3037
}
38+
39+
#[test]
40+
fn test_ingest_source_in() {
41+
assert_eq!(
42+
json!(IngestSourceIn {
43+
name: "foo".to_owned(),
44+
uid: None,
45+
config: IngestSourceInConfig::GenericWebhook,
46+
}),
47+
json!({
48+
"name": "foo",
49+
"type": "generic-webhook",
50+
}),
51+
);
52+
53+
assert_eq!(
54+
json!(IngestSourceIn {
55+
name: "foo".to_owned(),
56+
uid: None,
57+
config: IngestSourceInConfig::Svix(SvixConfig {
58+
secret: "xxx".to_owned()
59+
}),
60+
}),
61+
json!({
62+
"name": "foo",
63+
"type": "svix",
64+
"config": { "secret": "xxx" },
65+
}),
66+
);
67+
68+
assert_eq!(
69+
json!(IngestSourceIn {
70+
name: "foo".to_owned(),
71+
uid: None,
72+
config: IngestSourceInConfig::Segment(SegmentConfig { secret: None })
73+
}),
74+
json!({
75+
"name": "foo",
76+
"type": "segment",
77+
"config": {},
78+
}),
79+
);
80+
81+
assert_eq!(
82+
json!(IngestSourceIn {
83+
name: "foo".to_owned(),
84+
uid: None,
85+
config: IngestSourceInConfig::Cron(CronConfig {
86+
content_type: None,
87+
payload: "💣".to_owned(),
88+
schedule: "* * * * *".to_owned(),
89+
})
90+
}),
91+
json!({
92+
"name": "foo",
93+
"type": "cron",
94+
"config": {
95+
"payload": "💣",
96+
"schedule": "* * * * *",
97+
},
98+
}),
99+
);
100+
}
101+
102+
#[test]
103+
fn test_ingest_source_out() {
104+
assert_deserializes_to(
105+
json!({
106+
"id": "Rjb52OFZK6aYPfF4EpqYqD8Ptcyr",
107+
"createdAt": "2006-01-02T15:04:05Z",
108+
"updatedAt": "2006-01-02T15:04:05Z",
109+
"name": "foo",
110+
"ingestUrl": "https://in.example.invalid/xyz",
111+
"type": "generic-webhook",
112+
}),
113+
IngestSourceOut {
114+
created_at: "2006-01-02T15:04:05Z".to_owned(),
115+
id: "Rjb52OFZK6aYPfF4EpqYqD8Ptcyr".to_owned(),
116+
ingest_url: Some("https://in.example.invalid/xyz".to_owned()),
117+
name: "foo".to_owned(),
118+
uid: None,
119+
updated_at: "2006-01-02T15:04:05Z".to_owned(),
120+
config: IngestSourceOutConfig::GenericWebhook,
121+
},
122+
);
123+
124+
assert_deserializes_to(
125+
json!({
126+
"id": "Rjb52OFZK6aYPfF4EpqYqD8Ptcyr",
127+
"createdAt": "2006-01-02T15:04:05Z",
128+
"updatedAt": "2006-01-02T15:04:05Z",
129+
"name": "foo",
130+
"ingestUrl": "https://in.example.invalid/xyz",
131+
"type": "svix",
132+
"config": { "secret": "xxx" },
133+
}),
134+
IngestSourceOut {
135+
created_at: "2006-01-02T15:04:05Z".to_owned(),
136+
id: "Rjb52OFZK6aYPfF4EpqYqD8Ptcyr".to_owned(),
137+
ingest_url: Some("https://in.example.invalid/xyz".to_owned()),
138+
name: "foo".to_owned(),
139+
uid: None,
140+
updated_at: "2006-01-02T15:04:05Z".to_owned(),
141+
config: IngestSourceOutConfig::Svix(SvixConfigOut {}),
142+
},
143+
);
144+
145+
assert_deserializes_to(
146+
json!({
147+
"id": "Rjb52OFZK6aYPfF4EpqYqD8Ptcyr",
148+
"createdAt": "2006-01-02T15:04:05Z",
149+
"updatedAt": "2006-01-02T15:04:05Z",
150+
"name": "foo",
151+
"ingestUrl": "https://in.example.invalid/xyz",
152+
"type": "segment",
153+
"config": {},
154+
}),
155+
IngestSourceOut {
156+
created_at: "2006-01-02T15:04:05Z".to_owned(),
157+
id: "Rjb52OFZK6aYPfF4EpqYqD8Ptcyr".to_owned(),
158+
ingest_url: Some("https://in.example.invalid/xyz".to_owned()),
159+
name: "foo".to_owned(),
160+
uid: None,
161+
updated_at: "2006-01-02T15:04:05Z".to_owned(),
162+
config: IngestSourceOutConfig::Segment(SegmentConfigOut::default()),
163+
},
164+
);
165+
166+
assert_deserializes_to(
167+
json!({
168+
"id": "Rjb52OFZK6aYPfF4EpqYqD8Ptcyr",
169+
"createdAt": "2006-01-02T15:04:05Z",
170+
"updatedAt": "2006-01-02T15:04:05Z",
171+
"name": "foo",
172+
"type": "cron",
173+
"config": {
174+
"payload": "💣",
175+
"schedule": "* * * * *",
176+
},
177+
}),
178+
IngestSourceOut {
179+
created_at: "2006-01-02T15:04:05Z".to_owned(),
180+
id: "Rjb52OFZK6aYPfF4EpqYqD8Ptcyr".to_owned(),
181+
ingest_url: None,
182+
name: "foo".to_owned(),
183+
uid: None,
184+
updated_at: "2006-01-02T15:04:05Z".to_owned(),
185+
config: IngestSourceOutConfig::Cron(CronConfig {
186+
content_type: None,
187+
payload: "💣".to_owned(),
188+
schedule: "* * * * *".to_owned(),
189+
}),
190+
},
191+
);
192+
}
193+
194+
fn assert_deserializes_to<T: Debug + PartialEq + DeserializeOwned>(
195+
value: serde_json::Value,
196+
expected: T,
197+
) {
198+
let actual = T::deserialize(value).unwrap();
199+
assert_eq!(actual, expected);
200+
}

0 commit comments

Comments
 (0)