Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApiV2Schema failing to generate with Vec<Url> #333

Closed
patrickelectric opened this issue Sep 14, 2021 · 2 comments · Fixed by #334
Closed

ApiV2Schema failing to generate with Vec<Url> #333

patrickelectric opened this issue Sep 14, 2021 · 2 comments · Fixed by #334

Comments

@patrickelectric
Copy link
Contributor

patrickelectric commented Sep 14, 2021

error[E0599]: the function or associated item `raw_schema` exists for struct `Vec<url::Url>`, but its trait bounds were not satisfied
  --> src/stream/types.rs:37:59
   |
37 | #[derive(Clone, Debug, PartialEq, Deserialize, Serialize, Apiv2Schema)]
   |                                                           ^^^^^^^^^^^ function or associated item cannot be called on `Vec<url::Url>` due to unsatisfied trait bounds
   |
   = note: the following trait bounds were not satisfied:
           `&Vec<url::Url>: TypedData`
           which is required by `&Vec<url::Url>: Apiv2Schema`
           `&mut Vec<url::Url>: TypedData`
           which is required by `&mut Vec<url::Url>: Apiv2Schema`
   = note: this error originates in the derive macro `Apiv2Schema` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: the associated item `REQUIRED` exists for struct `Vec<url::Url>`, but its trait bounds were not satisfied
  --> src/stream/types.rs:37:59
   |
37 | #[derive(Clone, Debug, PartialEq, Deserialize, Serialize, Apiv2Schema)]
   |                                                           ^^^^^^^^^^^ associated item cannot be called on `Vec<url::Url>` due to unsatisfied trait bounds
   |
   = note: the following trait bounds were not satisfied:
           `&Vec<url::Url>: TypedData`
           which is required by `&Vec<url::Url>: Apiv2Schema`
           `&mut Vec<url::Url>: TypedData`
           which is required by `&mut Vec<url::Url>: Apiv2Schema`
   = note: this error originates in the derive macro `Apiv2Schema` (in Nightly builds, run with -Z macro-backtrace for more info)

With struct of type:

pub struct StreamInformation {
    pub endpoints: Vec<Url>,
}

Any idea of how to accomplish such thing ?

Url crate: https://docs.rs/url/2.2.2/url/

@tiagolobocastro
Copy link
Collaborator

Hmm, you either create a wrapper for url::Url where you manually implement the paperclip traits or you need to add support for url::Url into paperclip. Something like this:

diff --git a/core/src/v2/actix.rs b/core/src/v2/actix.rs
index 1d460fb..5547b04 100644
--- a/core/src/v2/actix.rs
+++ b/core/src/v2/actix.rs
@@ -210,6 +210,8 @@ mod manual_impl {
     impl_simple!(rust_decimal::Decimal);
     #[cfg(feature = "uuid")]
     impl_simple!(uuid::Uuid);
+    #[cfg(feature = "url")]
+    impl_simple!(url::Url);
 }
 
 #[cfg(feature = "chrono")]
diff --git a/core/src/v2/models.rs b/core/src/v2/models.rs
index f350aaf..996ba67 100644
--- a/core/src/v2/models.rs
+++ b/core/src/v2/models.rs
@@ -76,6 +76,7 @@ pub enum DataTypeFormat {
     DateTime,
     Password,
     Uuid,
+    Url,
     #[serde(other)]
     Other,
 }
diff --git a/core/src/v2/schema.rs b/core/src/v2/schema.rs
index 256993d..179a564 100644
--- a/core/src/v2/schema.rs
+++ b/core/src/v2/schema.rs
@@ -220,6 +220,9 @@ impl_type_simple!(
 #[cfg(feature = "uuid")]
 impl_type_simple!(uuid::Uuid, DataType::String, DataTypeFormat::Uuid);
 
+#[cfg(feature = "url")]
+impl_type_simple!(url::Url, DataType::String, DataTypeFormat::Url);
+
 #[cfg(feature = "chrono")]
 impl<T: chrono::offset::TimeZone> TypedData for chrono::DateTime<T> {
     fn data_type() -> DataType {

@patrickelectric
Copy link
Contributor Author

Thanks @tiagolobocastro! I'll take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants