feat: update NodeInfo 2.0 response to include $schema field and bump version to 0.4.3
This commit is contained in:
@@ -6,6 +6,7 @@ use crate::data::FederationData;
|
||||
use crate::error::Error;
|
||||
|
||||
const NODEINFO_2_0_REL: &str = "http://nodeinfo.diaspora.software/ns/schema/2.0";
|
||||
const NODEINFO_2_0_SCHEMA: &str = "http://nodeinfo.diaspora.software/ns/schema/2.0#";
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct NodeInfoWellKnown {
|
||||
@@ -39,6 +40,8 @@ pub struct NodeInfoUsers {
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct NodeInfo {
|
||||
#[serde(rename = "$schema")]
|
||||
pub schema: String,
|
||||
pub version: String,
|
||||
pub software: NodeInfoSoftware,
|
||||
pub protocols: Vec<String>,
|
||||
@@ -63,6 +66,7 @@ pub async fn nodeinfo_handler(data: Data<FederationData>) -> Result<Json<NodeInf
|
||||
let local_posts = data.content_reader.count_local_posts().await.unwrap_or(0);
|
||||
|
||||
Ok(Json(NodeInfo {
|
||||
schema: NODEINFO_2_0_SCHEMA.to_string(),
|
||||
version: "2.0".to_string(),
|
||||
software: NodeInfoSoftware {
|
||||
name: data.software_name.clone(),
|
||||
|
||||
@@ -19,6 +19,7 @@ fn nodeinfo_well_known_serializes_correctly() {
|
||||
#[test]
|
||||
fn nodeinfo_serializes_camel_case() {
|
||||
let doc = NodeInfo {
|
||||
schema: "http://nodeinfo.diaspora.software/ns/schema/2.0#".to_string(),
|
||||
version: "2.0".to_string(),
|
||||
software: NodeInfoSoftware {
|
||||
name: "my-app".to_string(),
|
||||
@@ -32,6 +33,10 @@ fn nodeinfo_serializes_camel_case() {
|
||||
open_registrations: false,
|
||||
};
|
||||
let json = serde_json::to_value(&doc).unwrap();
|
||||
assert_eq!(
|
||||
json["$schema"],
|
||||
"http://nodeinfo.diaspora.software/ns/schema/2.0#"
|
||||
);
|
||||
assert_eq!(json["version"], "2.0");
|
||||
assert_eq!(json["software"]["name"], "my-app");
|
||||
assert_eq!(json["usage"]["users"]["total"], 3);
|
||||
|
||||
Reference in New Issue
Block a user