Repository: svix/svix-webhooks (language: rust)

Issue:
Message attempt serde error in Rust library
## Bug Report

The Svix Rust library does not deserialize Svix's response correctly causing an exception. I suspect the issue is because status and responseStatusCode JSON are integers whereas Rust tries to deserialize strings into their respective structs.

### Version

Svix 1.6.0

### Platform

Linux/Debian

### Description

Reproduction steps:

```rust
use std::env;

use svix::api::Svix;

#[tokio::main]
async fn main() {
    let auth_token = env::var("SVIX_AUTH_TOKEN")
        .unwrap_or_else(|_| "my-api-key".to_string());

    let svix = Svix::new(auth_token, None);

    let app_uid = "some-app-uid";
    let endpoint_id = "some-endpoint-id";

    let list_message_attempt_out = svix
        .message_attempt()
        .list_by_endpoint(app_uid.to_string(), endpoint_id.to_string(), None)
        .await;

    // Print the result
    match list_message_attempt_out {
        Ok(list_message_attempt_out) => println!("{:#?}", list_message_attempt_out),
        Err(e) => println!("Error: {}", e),
    }
}
```

Error:
```
Error: error in serde: expected value at line 1 column 131
```

Note this assumes the list is not empty and there are message attempts.


Discussion / hints:
I believe I've found the issue. We should have a fix out soon.

Fix patch:
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index 567c18265..49efc8d2f 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -24,6 +24,7 @@ http = "0.2"
 serde = "^1.0"
 serde_derive = "^1.0"
 serde_json = "^1.0"
+serde_repr = "^0.1"
 url = "^2.2"
 reqwest = { version = "^0.11", features = ["json", "multipart"], default-features = false }
 
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index f1acea385..e77839b5b 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -6,6 +6,8 @@
 
 #[macro_use]
 extern crate serde_derive;
+#[macro_use]
+extern crate serde_repr;
 
 extern crate reqwest;
 extern crate serde;
diff --git a/rust/templates/model.mustache b/rust/templates/model.mustache
index 1bd2b8db9..53a65099a 100644
--- a/rust/templates/model.mustache
+++ b/rust/templates/model.mustache
@@ -8,6 +8,7 @@
 {{!-- for enum schemas --}}
 {{#isEnum}}
 /// {{{description}}}
+{{#isString}}
 #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
 pub enum {{{classname}}} {
 {{#allowableValues}}
@@ -16,6 +17,17 @@ pub enum {{{classname}}} {
     {{{name}}},
 {{/enumVars}}{{/allowableValues}}
 }
+{{/isString}}
+{{#isInteger}}
+#[repr(i16)]
+#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize_repr, Deserialize_repr)]
+pub enum {{{classname}}} {
+{{#allowableValues}}
+{{#enumVars}}
+    {{{name}}} = {{{value}}},
+{{/enumVars}}{{/allowableValues}}
+}
+{{/isInteger}}
 
 impl ToString for {{{classname}}} {
     fn to_string(&self) -> String {


Test patch: