Repository: fMeow/arangors (language: rust)

Issue:
Database::create_edge_collection creates regular document collection
Title says it all.

Unexpectedly, a regular document collection is created.


Discussion / hints:
Thanks to your PR(#27), it should be fixed now. I also add a minimal e2e test to ensure the `create_edge_collection` performs correctly. 
Great. 

Due to the complexity of the API, it might be worthwile to investigate auto-generating base code from the official Swagger/OpenAPI specification, and then providing a nicer API on top.

I don't think the current OpenAPI Rust code generators are of great quality though...
Hello, thank you for your work !!! 
I think this is broken again.
@fMeow 
Looking at the code it seems that the server expects an integer but the code serializes a string for the fields.

Perhaps using serde_repr rather than just aliasing the fields to 1 or 2.


Fix patch:
diff --git a/Cargo.lock b/Cargo.lock
index 6a4e664..9b567c1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -153,6 +153,7 @@ dependencies = [
  "serde",
  "serde_json",
  "serde_qs 0.10.1",
+ "serde_repr",
  "surf",
  "thiserror",
  "tokio",
@@ -1912,6 +1913,17 @@ dependencies = [
  "thiserror",
 ]
 
+[[package]]
+name = "serde_repr"
+version = "0.1.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.52",
+]
+
 [[package]]
 name = "serde_urlencoded"
 version = "0.7.1"
diff --git a/Cargo.toml b/Cargo.toml
index 8718ec5..4f60617 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -44,6 +44,7 @@ thiserror = "1"
 typed-builder = "0.10"
 url = "2"
 uclient = "0.1"
+serde_repr = "0.1"
 
   [dependencies.serde]
   version = "1"
diff --git a/src/collection/mod.rs b/src/collection/mod.rs
index 1eaadbb..bee46ab 100644
--- a/src/collection/mod.rs
+++ b/src/collection/mod.rs
@@ -6,7 +6,7 @@ use std::{convert::TryFrom, sync::Arc};
 
 use http::Request;
 use maybe_async::maybe_async;
-use serde::{de::DeserializeOwned, Deserialize, Deserializer, Serialize};
+use serde::{de::DeserializeOwned, Deserialize, Serialize};
 use serde_json::json;
 use uclient::ClientExt;
 use url::Url;
@@ -806,27 +806,9 @@ fn make_header_from_options(
     }
 }
 
-#[derive(Debug, Clone, PartialEq, Eq, Copy, Serialize)]
+#[derive(Debug, Clone, PartialEq, Eq, Copy, serde_repr::Serialize_repr, serde_repr::Deserialize_repr)]
+#[repr(u8)]
 pub enum CollectionType {
-    #[serde(rename = "2")]
     Document = 2,
-    #[serde(rename = "3")]
     Edge = 3,
 }
-
-impl<'de> Deserialize<'de> for CollectionType {
-    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
-    where
-        D: Deserializer<'de>,
-    {
-        let value = u8::deserialize(deserializer)?;
-        match value {
-            2 => Ok(CollectionType::Document),
-            3 => Ok(CollectionType::Edge),
-            _ => Err(serde::de::Error::custom(
-                "Undefined behavior. If the crate breaks after an upgrade of ArangoDB, please \
-                 contact the author.",
-            )),
-        }
-    }
-}


Test patch: