Skip to content

Commit 4852312

Browse files
committed
Update NodeInfo schema definitions and protocol handling
Adds stricter schema validation for NodeInfo versions 1.0, 1.1, 2.0, 2.1, and 2.2, including enums, patterns, and minimums for properties. Introduces protocol handling hooks for NodeInfo 2.x versions and updates supported protocol/service lists. Adds homepage to software metadata for 2.1 and 2.2, and improves documentation with schema links.
1 parent e87028e commit 4852312

5 files changed

Lines changed: 276 additions & 54 deletions

File tree

includes/integration/class-nodeinfo10.php

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ public static function discovery_link( $links ) {
6363
/**
6464
* Adds the schema for this version.
6565
*
66+
* @link https://github.com/jhass/nodeinfo/blob/main/schemas/1.0/schema.json
67+
*
6668
* @param array $schema The schema.
6769
* @return array The modified schema.
6870
*/
@@ -78,7 +80,10 @@ public static function schema( $schema ) {
7880
'description' => 'Metadata about server software in use.',
7981
'type' => 'object',
8082
'properties' => array(
81-
'name' => array( 'type' => 'string' ),
83+
'name' => array(
84+
'type' => 'string',
85+
'enum' => array( 'diaspora', 'friendica', 'redmatrix' ),
86+
),
8287
'version' => array( 'type' => 'string' ),
8388
),
8489
),
@@ -88,11 +93,17 @@ public static function schema( $schema ) {
8893
'properties' => array(
8994
'inbound' => array(
9095
'type' => 'array',
91-
'items' => array( 'type' => 'string' ),
96+
'items' => array(
97+
'type' => 'string',
98+
'enum' => array( 'buddycloud', 'diaspora', 'friendica', 'gnusocial', 'libertree', 'mediagoblin', 'pumpio', 'redmatrix', 'smtp', 'tent' ),
99+
),
92100
),
93101
'outbound' => array(
94102
'type' => 'array',
95-
'items' => array( 'type' => 'string' ),
103+
'items' => array(
104+
'type' => 'string',
105+
'enum' => array( 'buddycloud', 'diaspora', 'friendica', 'gnusocial', 'libertree', 'mediagoblin', 'pumpio', 'redmatrix', 'smtp', 'tent' ),
106+
),
96107
),
97108
),
98109
),
@@ -102,11 +113,17 @@ public static function schema( $schema ) {
102113
'properties' => array(
103114
'inbound' => array(
104115
'type' => 'array',
105-
'items' => array( 'type' => 'string' ),
116+
'items' => array(
117+
'type' => 'string',
118+
'enum' => array( 'appnet', 'gnusocial', 'pumpio' ),
119+
),
106120
),
107121
'outbound' => array(
108122
'type' => 'array',
109-
'items' => array( 'type' => 'string' ),
123+
'items' => array(
124+
'type' => 'string',
125+
'enum' => array( 'appnet', 'blogger', 'buddycloud', 'diaspora', 'dreamwidth', 'drupal', 'facebook', 'friendica', 'gnusocial', 'google', 'insanejournal', 'libertree', 'linkedin', 'livejournal', 'mediagoblin', 'myspace', 'pinterest', 'posterous', 'pumpio', 'redmatrix', 'smtp', 'tent', 'tumblr', 'twitter', 'wordpress', 'xmpp' ),
126+
),
110127
),
111128
),
112129
),
@@ -121,13 +138,28 @@ public static function schema( $schema ) {
121138
'users' => array(
122139
'type' => 'object',
123140
'properties' => array(
124-
'total' => array( 'type' => 'integer' ),
125-
'activeMonth' => array( 'type' => 'integer' ),
126-
'activeHalfyear' => array( 'type' => 'integer' ),
141+
'total' => array(
142+
'type' => 'integer',
143+
'minimum' => 0,
144+
),
145+
'activeMonth' => array(
146+
'type' => 'integer',
147+
'minimum' => 0,
148+
),
149+
'activeHalfyear' => array(
150+
'type' => 'integer',
151+
'minimum' => 0,
152+
),
127153
),
128154
),
129-
'localPosts' => array( 'type' => 'integer' ),
130-
'localComments' => array( 'type' => 'integer' ),
155+
'localPosts' => array(
156+
'type' => 'integer',
157+
'minimum' => 0,
158+
),
159+
'localComments' => array(
160+
'type' => 'integer',
161+
'minimum' => 0,
162+
),
131163
),
132164
),
133165
'metadata' => array(

includes/integration/class-nodeinfo11.php

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@ public static function discovery_link( $links ) {
6363
/**
6464
* Adds the schema for NodeInfo 1.1.
6565
*
66+
* @link https://github.com/jhass/nodeinfo/blob/main/schemas/1.1/schema.json
67+
*
6668
* @param array $schema The schema.
6769
* @return array The modified schema.
6870
*/
6971
public static function schema( $schema ) {
70-
// NodeInfo 1.1 schema - same as 1.0, protocols uses inbound/outbound structure.
72+
// NodeInfo 1.1 schema - adds hubzilla to software enum and zot to protocols.
7173
$schema['properties'] = array_merge(
7274
$schema['properties'],
7375
array(
@@ -79,7 +81,10 @@ public static function schema( $schema ) {
7981
'description' => 'Metadata about server software in use.',
8082
'type' => 'object',
8183
'properties' => array(
82-
'name' => array( 'type' => 'string' ),
84+
'name' => array(
85+
'type' => 'string',
86+
'enum' => array( 'diaspora', 'friendica', 'hubzilla', 'redmatrix' ),
87+
),
8388
'version' => array( 'type' => 'string' ),
8489
),
8590
),
@@ -89,11 +94,17 @@ public static function schema( $schema ) {
8994
'properties' => array(
9095
'inbound' => array(
9196
'type' => 'array',
92-
'items' => array( 'type' => 'string' ),
97+
'items' => array(
98+
'type' => 'string',
99+
'enum' => array( 'buddycloud', 'diaspora', 'friendica', 'gnusocial', 'libertree', 'mediagoblin', 'pumpio', 'redmatrix', 'smtp', 'tent', 'zot' ),
100+
),
93101
),
94102
'outbound' => array(
95103
'type' => 'array',
96-
'items' => array( 'type' => 'string' ),
104+
'items' => array(
105+
'type' => 'string',
106+
'enum' => array( 'buddycloud', 'diaspora', 'friendica', 'gnusocial', 'libertree', 'mediagoblin', 'pumpio', 'redmatrix', 'smtp', 'tent', 'zot' ),
107+
),
97108
),
98109
),
99110
),
@@ -103,11 +114,17 @@ public static function schema( $schema ) {
103114
'properties' => array(
104115
'inbound' => array(
105116
'type' => 'array',
106-
'items' => array( 'type' => 'string' ),
117+
'items' => array(
118+
'type' => 'string',
119+
'enum' => array( 'appnet', 'gnusocial', 'pumpio' ),
120+
),
107121
),
108122
'outbound' => array(
109123
'type' => 'array',
110-
'items' => array( 'type' => 'string' ),
124+
'items' => array(
125+
'type' => 'string',
126+
'enum' => array( 'appnet', 'blogger', 'buddycloud', 'diaspora', 'dreamwidth', 'drupal', 'facebook', 'friendica', 'gnusocial', 'google', 'insanejournal', 'libertree', 'linkedin', 'livejournal', 'mediagoblin', 'myspace', 'pinterest', 'posterous', 'pumpio', 'redmatrix', 'smtp', 'tent', 'tumblr', 'twitter', 'wordpress', 'xmpp' ),
127+
),
111128
),
112129
),
113130
),
@@ -122,13 +139,28 @@ public static function schema( $schema ) {
122139
'users' => array(
123140
'type' => 'object',
124141
'properties' => array(
125-
'total' => array( 'type' => 'integer' ),
126-
'activeMonth' => array( 'type' => 'integer' ),
127-
'activeHalfyear' => array( 'type' => 'integer' ),
142+
'total' => array(
143+
'type' => 'integer',
144+
'minimum' => 0,
145+
),
146+
'activeMonth' => array(
147+
'type' => 'integer',
148+
'minimum' => 0,
149+
),
150+
'activeHalfyear' => array(
151+
'type' => 'integer',
152+
'minimum' => 0,
153+
),
128154
),
129155
),
130-
'localPosts' => array( 'type' => 'integer' ),
131-
'localComments' => array( 'type' => 'integer' ),
156+
'localPosts' => array(
157+
'type' => 'integer',
158+
'minimum' => 0,
159+
),
160+
'localComments' => array(
161+
'type' => 'integer',
162+
'minimum' => 0,
163+
),
132164
),
133165
),
134166
'metadata' => array(

includes/integration/class-nodeinfo20.php

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public static function init() {
2929
add_filter( 'nodeinfo_discovery_links', array( __CLASS__, 'discovery_link' ) );
3030
add_filter( 'nodeinfo_schema', array( __CLASS__, 'schema' ) );
3131
add_filter( 'nodeinfo_data_software', array( __CLASS__, 'software' ), 10, 2 );
32+
add_filter( 'nodeinfo_data_protocols', array( __CLASS__, 'protocols' ), 10, 2 );
3233
add_filter( 'nodeinfo_data_services', array( __CLASS__, 'services' ), 10, 2 );
3334
add_filter( 'nodeinfo_data_usage', array( __CLASS__, 'usage' ), 10, 2 );
3435
add_filter( 'nodeinfo_data_metadata', array( __CLASS__, 'metadata' ), 10, 2 );
@@ -62,11 +63,13 @@ public static function discovery_link( $links ) {
6263
/**
6364
* Adds the schema for NodeInfo 2.0.
6465
*
66+
* @link https://github.com/jhass/nodeinfo/blob/main/schemas/2.0/schema.json
67+
*
6568
* @param array $schema The schema.
6669
* @return array The modified schema.
6770
*/
6871
public static function schema( $schema ) {
69-
// NodeInfo 2.0 schema - protocols is a flat array, not inbound/outbound.
72+
// NodeInfo 2.0 schema - protocols is a flat array, software name is pattern-based.
7073
$schema['properties'] = array_merge(
7174
$schema['properties'],
7275
array(
@@ -78,26 +81,39 @@ public static function schema( $schema ) {
7881
'description' => 'Metadata about server software in use.',
7982
'type' => 'object',
8083
'properties' => array(
81-
'name' => array( 'type' => 'string' ),
84+
'name' => array(
85+
'type' => 'string',
86+
'pattern' => '^[a-z0-9-]+$',
87+
),
8288
'version' => array( 'type' => 'string' ),
8389
),
8490
),
8591
'protocols' => array(
8692
'description' => 'The protocols supported on this server.',
8793
'type' => 'array',
88-
'items' => array( 'type' => 'string' ),
94+
'minItems' => 1,
95+
'items' => array(
96+
'type' => 'string',
97+
'enum' => array( 'activitypub', 'buddycloud', 'dfrn', 'diaspora', 'libertree', 'ostatus', 'pumpio', 'tent', 'xmpp', 'zot' ),
98+
),
8999
),
90100
'services' => array(
91101
'description' => 'Third party sites this server can connect to.',
92102
'type' => 'object',
93103
'properties' => array(
94104
'inbound' => array(
95105
'type' => 'array',
96-
'items' => array( 'type' => 'string' ),
106+
'items' => array(
107+
'type' => 'string',
108+
'enum' => array( 'atom1.0', 'gnusocial', 'imap', 'pnut', 'pop3', 'pumpio', 'rss2.0', 'twitter' ),
109+
),
97110
),
98111
'outbound' => array(
99112
'type' => 'array',
100-
'items' => array( 'type' => 'string' ),
113+
'items' => array(
114+
'type' => 'string',
115+
'enum' => array( 'atom1.0', 'blogger', 'buddycloud', 'diaspora', 'dreamwidth', 'drupal', 'facebook', 'friendica', 'gnusocial', 'google', 'insanejournal', 'libertree', 'linkedin', 'livejournal', 'mediagoblin', 'myspace', 'pinterest', 'pnut', 'posterous', 'pumpio', 'redmatrix', 'rss2.0', 'smtp', 'tent', 'tumblr', 'twitter', 'wordpress', 'xmpp' ),
116+
),
101117
),
102118
),
103119
),
@@ -112,13 +128,28 @@ public static function schema( $schema ) {
112128
'users' => array(
113129
'type' => 'object',
114130
'properties' => array(
115-
'total' => array( 'type' => 'integer' ),
116-
'activeMonth' => array( 'type' => 'integer' ),
117-
'activeHalfyear' => array( 'type' => 'integer' ),
131+
'total' => array(
132+
'type' => 'integer',
133+
'minimum' => 0,
134+
),
135+
'activeMonth' => array(
136+
'type' => 'integer',
137+
'minimum' => 0,
138+
),
139+
'activeHalfyear' => array(
140+
'type' => 'integer',
141+
'minimum' => 0,
142+
),
118143
),
119144
),
120-
'localPosts' => array( 'type' => 'integer' ),
121-
'localComments' => array( 'type' => 'integer' ),
145+
'localPosts' => array(
146+
'type' => 'integer',
147+
'minimum' => 0,
148+
),
149+
'localComments' => array(
150+
'type' => 'integer',
151+
'minimum' => 0,
152+
),
122153
),
123154
),
124155
'metadata' => array(
@@ -150,6 +181,24 @@ public static function software( $software, $version ) {
150181
return $software;
151182
}
152183

184+
/**
185+
* Adds protocols.
186+
*
187+
* NodeInfo 2.0+ uses a flat array of protocol strings.
188+
*
189+
* @param array $protocols The protocols data.
190+
* @param string $version The NodeInfo version.
191+
* @return array The modified protocols data.
192+
*/
193+
public static function protocols( $protocols, $version ) {
194+
if ( self::VERSION !== $version ) {
195+
return $protocols;
196+
}
197+
198+
// Default protocols - can be extended via filter.
199+
return apply_filters( 'nodeinfo_protocols', array() );
200+
}
201+
153202
/**
154203
* Adds services.
155204
*

0 commit comments

Comments
 (0)