feat: naive implementation of ssh_url deserialization
This commit is contained in:
parent
1c5506c707
commit
9b2864bd70
|
@ -63,7 +63,7 @@ pub fn create_struct_for_definition(
|
|||
crate::schema_subtype_name(spec, name, prop_name, value, &mut field_ty)?;
|
||||
crate::schema_subtypes(spec, name, prop_name, value, &mut subtypes)?;
|
||||
}
|
||||
if field_name.ends_with("url") && field_name != "ssh_url" && field_ty == "String" {
|
||||
if field_name.ends_with("url") && field_ty == "String" {
|
||||
field_ty = "url::Url".into()
|
||||
}
|
||||
if field_ty == name {
|
||||
|
@ -73,7 +73,16 @@ pub fn create_struct_for_definition(
|
|||
field_ty = format!("Option<{field_ty}>")
|
||||
}
|
||||
if field_ty == "Option<url::Url>" {
|
||||
fields.push_str("#[serde(deserialize_with = \"crate::none_if_blank_url\")]\n");
|
||||
if field_name == "ssh_url" {
|
||||
fields.push_str(
|
||||
"#[serde(deserialize_with = \"crate::deserialize_optional_ssh_url\")]\n",
|
||||
);
|
||||
} else {
|
||||
fields.push_str("#[serde(deserialize_with = \"crate::none_if_blank_url\")]\n");
|
||||
}
|
||||
}
|
||||
if field_ty == "url::Url" && field_name == "ssh_url" {
|
||||
fields.push_str("#[serde(deserialize_with = \"crate::deserialize_ssh_url\")]\n");
|
||||
}
|
||||
if field_ty == "time::OffsetDateTime" {
|
||||
fields.push_str("#[serde(with = \"time::serde::rfc3339\")]\n");
|
||||
|
@ -106,8 +115,8 @@ pub fn create_struct_for_definition(
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(additonal_schema) = &schema.additional_properties {
|
||||
let prop_ty = crate::schema_ref_type_name(spec, additonal_schema)?;
|
||||
if let Some(additional_schema) = &schema.additional_properties {
|
||||
let prop_ty = crate::schema_ref_type_name(spec, additional_schema)?;
|
||||
fields.push_str("#[serde(flatten)]\n");
|
||||
fields.push_str("pub additional: BTreeMap<String, ");
|
||||
fields.push_str(&prop_ty);
|
||||
|
|
|
@ -2278,7 +2278,8 @@ pub struct Repository {
|
|||
pub release_counter: Option<u64>,
|
||||
pub repo_transfer: Option<RepoTransfer>,
|
||||
pub size: Option<u64>,
|
||||
pub ssh_url: Option<String>,
|
||||
#[serde(deserialize_with = "crate::deserialize_optional_ssh_url")]
|
||||
pub ssh_url: Option<url::Url>,
|
||||
pub stars_count: Option<u64>,
|
||||
pub template: Option<bool>,
|
||||
#[serde(with = "time::serde::rfc3339::option")]
|
||||
|
|
26
src/lib.rs
26
src/lib.rs
|
@ -1,4 +1,5 @@
|
|||
use reqwest::{Client, Request, StatusCode};
|
||||
use serde::{Deserialize, Deserializer};
|
||||
use soft_assert::*;
|
||||
use url::Url;
|
||||
use zeroize::Zeroize;
|
||||
|
@ -254,6 +255,31 @@ fn none_if_blank_url<'de, D: serde::Deserializer<'de>>(
|
|||
deserializer.deserialize_str(EmptyUrlVisitor)
|
||||
}
|
||||
|
||||
#[allow(dead_code)] // not used yet, but it might appear in the future
|
||||
fn deserialize_ssh_url<'de, D, DE>(deserializer: D) -> Result<Url, DE>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
DE: serde::de::Error,
|
||||
{
|
||||
let raw_url: String = String::deserialize(deserializer).map_err(DE::custom)?;
|
||||
let url = format!("ssh://{url}", url = raw_url.replace(":", "/"));
|
||||
Url::parse(url.as_str()).map_err(DE::custom)
|
||||
}
|
||||
|
||||
fn deserialize_optional_ssh_url<'de, D, DE>(deserializer: D) -> Result<Option<Url>, DE>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
DE: serde::de::Error,
|
||||
{
|
||||
let raw_url: Option<String> = Option::deserialize(deserializer).map_err(DE::custom)?;
|
||||
raw_url
|
||||
.map(|raw_url| {
|
||||
let url = format!("ssh://{url}", url = raw_url.replace(":", "/"));
|
||||
Url::parse(url.as_str()).map_err(DE::custom).map(Some)
|
||||
})
|
||||
.unwrap_or(Ok(None))
|
||||
}
|
||||
|
||||
impl From<structs::DefaultMergeStyle> for structs::MergePullRequestOptionDo {
|
||||
fn from(value: structs::DefaultMergeStyle) -> Self {
|
||||
match value {
|
||||
|
|
Loading…
Reference in a new issue