mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-23 19:31:33 +00:00
Use serde(skip) instead of skip_serializing, add placeholder values (#3362)
* Use serde(skip) instead of skip_serializing The latter breaks lemmy_crawler as the field is not included in the Lemmy API, but is required when attempting to parse API responses. Should only use serde(skip) to avoid this problem * use option * add placeholders * no unwrap
This commit is contained in:
parent
6405761891
commit
cb91eedd24
3 changed files with 24 additions and 5 deletions
|
@ -1,6 +1,9 @@
|
||||||
use crate::newtypes::{CommunityId, DbUrl, InstanceId, PersonId};
|
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
use crate::schema::{community, community_follower, community_moderator, community_person_ban};
|
use crate::schema::{community, community_follower, community_moderator, community_person_ban};
|
||||||
|
use crate::{
|
||||||
|
newtypes::{CommunityId, DbUrl, InstanceId, PersonId},
|
||||||
|
source::placeholder_apub_url,
|
||||||
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_with::skip_serializing_none;
|
use serde_with::skip_serializing_none;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
|
@ -42,9 +45,9 @@ pub struct Community {
|
||||||
pub icon: Option<DbUrl>,
|
pub icon: Option<DbUrl>,
|
||||||
/// A URL for a banner.
|
/// A URL for a banner.
|
||||||
pub banner: Option<DbUrl>,
|
pub banner: Option<DbUrl>,
|
||||||
#[serde(skip_serializing)]
|
#[serde(skip, default = "placeholder_apub_url")]
|
||||||
pub followers_url: DbUrl,
|
pub followers_url: DbUrl,
|
||||||
#[serde(skip_serializing)]
|
#[serde(skip, default = "placeholder_apub_url")]
|
||||||
pub inbox_url: DbUrl,
|
pub inbox_url: DbUrl,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub shared_inbox_url: Option<DbUrl>,
|
pub shared_inbox_url: Option<DbUrl>,
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
use crate::newtypes::DbUrl;
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
pub mod activity;
|
pub mod activity;
|
||||||
pub mod actor_language;
|
pub mod actor_language;
|
||||||
|
@ -30,3 +33,13 @@ pub mod registration_application;
|
||||||
pub mod secret;
|
pub mod secret;
|
||||||
pub mod site;
|
pub mod site;
|
||||||
pub mod tagline;
|
pub mod tagline;
|
||||||
|
|
||||||
|
/// Default value for columns like [community::Community.inbox_url] which are marked as serde(skip).
|
||||||
|
///
|
||||||
|
/// This is necessary so they can be successfully deserialized from API responses, even though the
|
||||||
|
/// value is not sent by Lemmy. Necessary for crates which rely on Rust API such as lemmy-stats-crawler.
|
||||||
|
fn placeholder_apub_url() -> DbUrl {
|
||||||
|
DbUrl(Box::new(
|
||||||
|
Url::parse("http://example.com").expect("parse placeholer url"),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
use crate::newtypes::{DbUrl, InstanceId, PersonId};
|
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
use crate::schema::{person, person_follower};
|
use crate::schema::{person, person_follower};
|
||||||
|
use crate::{
|
||||||
|
newtypes::{DbUrl, InstanceId, PersonId},
|
||||||
|
source::placeholder_apub_url,
|
||||||
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_with::skip_serializing_none;
|
use serde_with::skip_serializing_none;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
|
@ -40,7 +43,7 @@ pub struct Person {
|
||||||
pub banner: Option<DbUrl>,
|
pub banner: Option<DbUrl>,
|
||||||
/// Whether the person is deleted.
|
/// Whether the person is deleted.
|
||||||
pub deleted: bool,
|
pub deleted: bool,
|
||||||
#[serde(skip_serializing)]
|
#[serde(skip, default = "placeholder_apub_url")]
|
||||||
pub inbox_url: DbUrl,
|
pub inbox_url: DbUrl,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub shared_inbox_url: Option<DbUrl>,
|
pub shared_inbox_url: Option<DbUrl>,
|
||||||
|
|
Loading…
Reference in a new issue