mirror of https://github.com/LemmyNet/lemmy.git
Accept single object as to for arrays too (#2048)
parent
19ccaf767c
commit
272dc3e7a6
|
@ -112,6 +112,25 @@ where
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn deserialize_one<'de, T, D>(deserializer: D) -> Result<[T; 1], D::Error>
|
||||||
|
where
|
||||||
|
T: Deserialize<'de>,
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
enum MaybeArray<T> {
|
||||||
|
Simple(T),
|
||||||
|
Array([T; 1]),
|
||||||
|
}
|
||||||
|
|
||||||
|
let result: MaybeArray<T> = Deserialize::deserialize(deserializer)?;
|
||||||
|
Ok(match result {
|
||||||
|
MaybeArray::Simple(value) => [value],
|
||||||
|
MaybeArray::Array(value) => value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub enum EndpointType {
|
pub enum EndpointType {
|
||||||
Community,
|
Community,
|
||||||
Person,
|
Person,
|
||||||
|
|
|
@ -12,6 +12,7 @@ use url::Url;
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Report {
|
pub struct Report {
|
||||||
pub(crate) actor: ObjectId<ApubPerson>,
|
pub(crate) actor: ObjectId<ApubPerson>,
|
||||||
|
#[serde(deserialize_with = "crate::deserialize_one")]
|
||||||
pub(crate) to: [ObjectId<ApubCommunity>; 1],
|
pub(crate) to: [ObjectId<ApubCommunity>; 1],
|
||||||
pub(crate) object: ObjectId<PostOrComment>,
|
pub(crate) object: ObjectId<PostOrComment>,
|
||||||
pub(crate) summary: String,
|
pub(crate) summary: String,
|
||||||
|
|
|
@ -11,6 +11,7 @@ use url::Url;
|
||||||
pub struct CreateOrUpdatePrivateMessage {
|
pub struct CreateOrUpdatePrivateMessage {
|
||||||
pub(crate) id: Url,
|
pub(crate) id: Url,
|
||||||
pub(crate) actor: ObjectId<ApubPerson>,
|
pub(crate) actor: ObjectId<ApubPerson>,
|
||||||
|
#[serde(deserialize_with = "crate::deserialize_one")]
|
||||||
pub(crate) to: [ObjectId<ApubPerson>; 1],
|
pub(crate) to: [ObjectId<ApubPerson>; 1],
|
||||||
pub(crate) object: ChatMessage,
|
pub(crate) object: ChatMessage,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
|
|
|
@ -11,6 +11,7 @@ use url::Url;
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct DeletePrivateMessage {
|
pub struct DeletePrivateMessage {
|
||||||
pub(crate) actor: ObjectId<ApubPerson>,
|
pub(crate) actor: ObjectId<ApubPerson>,
|
||||||
|
#[serde(deserialize_with = "crate::deserialize_one")]
|
||||||
pub(crate) to: [ObjectId<ApubPerson>; 1],
|
pub(crate) to: [ObjectId<ApubPerson>; 1],
|
||||||
pub(crate) object: ObjectId<ApubPrivateMessage>,
|
pub(crate) object: ObjectId<ApubPrivateMessage>,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
|
|
|
@ -11,6 +11,7 @@ use url::Url;
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct UndoDeletePrivateMessage {
|
pub struct UndoDeletePrivateMessage {
|
||||||
pub(crate) actor: ObjectId<ApubPerson>,
|
pub(crate) actor: ObjectId<ApubPerson>,
|
||||||
|
#[serde(deserialize_with = "crate::deserialize_one")]
|
||||||
pub(crate) to: [ObjectId<ApubPerson>; 1],
|
pub(crate) to: [ObjectId<ApubPerson>; 1],
|
||||||
pub(crate) object: DeletePrivateMessage,
|
pub(crate) object: DeletePrivateMessage,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
|
|
|
@ -14,6 +14,7 @@ pub struct ChatMessage {
|
||||||
pub(crate) r#type: ChatMessageType,
|
pub(crate) r#type: ChatMessageType,
|
||||||
pub(crate) id: ObjectId<ApubPrivateMessage>,
|
pub(crate) id: ObjectId<ApubPrivateMessage>,
|
||||||
pub(crate) attributed_to: ObjectId<ApubPerson>,
|
pub(crate) attributed_to: ObjectId<ApubPerson>,
|
||||||
|
#[serde(deserialize_with = "crate::deserialize_one")]
|
||||||
pub(crate) to: [ObjectId<ApubPerson>; 1],
|
pub(crate) to: [ObjectId<ApubPerson>; 1],
|
||||||
pub(crate) content: String,
|
pub(crate) content: String,
|
||||||
pub(crate) media_type: Option<MediaTypeHtml>,
|
pub(crate) media_type: Option<MediaTypeHtml>,
|
||||||
|
|
Loading…
Reference in New Issue