Skip to content

Commit

Permalink
Add Url feature
Browse files Browse the repository at this point in the history
Allow the usage of the Url object on the API

Signed-off-by: Patrick José Pereira <[email protected]>
  • Loading branch information
patrickelectric committed Oct 5, 2021
1 parent 7289bf3 commit 44c64f4
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ serde_json = "1.0"
serde_yaml = "0.8"
structopt = { version = "0.3", optional = true }
tinytemplate = { version = "1.1", optional = true }
url = ">=1.7,<3"
url_dep = { version = ">=1.7,<3", package = "url" }
thiserror = "1.0"
anyhow = "1.0"
once_cell = "1.4"
Expand Down Expand Up @@ -75,6 +75,7 @@ actix-session = ["paperclip-core/actix-session"]
actix-files = ["paperclip-core/actix-files"]
chrono = ["paperclip-core/chrono"]
rust_decimal = ["paperclip-core/rust_decimal"]
url = ["paperclip-core/url"]
uuid = ["paperclip-core/uuid"]
serde_qs = ["paperclip-core/serde_qs"]

Expand Down
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ regex = "1.3"
serde = { version = "1.0", features = ["derive", "rc"] }
serde_json = "1.0"
serde_yaml = "0.8"
url = { version = "2", optional = true }
uuid = { version = "0", optional = true }
thiserror = "1.0"
serde_qs = { version = "0", optional = true }
Expand Down
2 changes: 2 additions & 0 deletions core/src/v2/actix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ mod manual_impl {
impl_simple!(chrono::NaiveDateTime);
#[cfg(feature = "rust_decimal")]
impl_simple!(rust_decimal::Decimal);
#[cfg(feature = "url")]
impl_simple!(url::Url);
#[cfg(feature = "uuid")]
impl_simple!(uuid::Uuid);
}
Expand Down
1 change: 1 addition & 0 deletions core/src/v2/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub enum DataTypeFormat {
#[serde(rename = "date-time")]
DateTime,
Password,
Url,
Uuid,
#[serde(other)]
Other,
Expand Down
3 changes: 3 additions & 0 deletions core/src/v2/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ impl_type_simple!(
DataTypeFormat::Float
);

#[cfg(feature = "url")]
impl_type_simple!(url::Url, DataType::String, DataTypeFormat::Url);

#[cfg(feature = "uuid")]
impl_type_simple!(uuid::Uuid, DataType::String, DataTypeFormat::Uuid);

Expand Down
2 changes: 1 addition & 1 deletion src/build/cli_main.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ enum ClientError \{
#[error("Client error: \{}", _0)]
Reqwest(reqwest::Error),
#[error("URL error: \{}", _0)]
Url(url::ParseError),
Url(url_dep::ParseError),
#[error("\{}", _0)]
Api(self::client::ApiError<reqwest::Response>),
#[error("")]
Expand Down
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ pub enum PaperClipError {
MissingParametersInPath(String, HashSet<String>),
/// Invalid host for URL.
#[error("Cannot parse host {:?}: {}", _0, _1)]
InvalidHost(String, url::ParseError),
InvalidHost(String, url_dep::ParseError),
/// Invalid base path URL.
#[error("Cannot set URL {:?}: {}", _0, _1)]
#[allow(clippy::upper_case_acronyms)]
InvalidBasePathURL(String, url::ParseError),
InvalidBasePathURL(String, url_dep::ParseError),
/// The given schema object is an array, but the `items` field is missing.
#[error("Mising item schema for array: {:?}", _0)]
MissingArrayItem(Option<String>),
Expand Down
2 changes: 1 addition & 1 deletion src/v2/codegen/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ pub trait Emitter: Sized {

if let Some(port) = parts.next() {
let p = port.parse::<u16>().map_err(|_| {
PaperClipError::InvalidHost(h.into(), url::ParseError::InvalidPort)
PaperClipError::InvalidHost(h.into(), url_dep::ParseError::InvalidPort)
})?;
u.set_port(Some(p)).expect("expected valid port in URL?");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ enum ClientError {
#[error("Client error: {}", _0)]
Reqwest(reqwest::Error),
#[error("URL error: {}", _0)]
Url(url::ParseError),
Url(url_dep::ParseError),
#[error("{}", _0)]
Api(self::client::ApiError<reqwest::Response>),
#[error("")]
Expand Down

0 comments on commit 44c64f4

Please sign in to comment.