Skip to content

Commit

Permalink
doc: fix all JSON schemas to enforce no additional properties.
Browse files Browse the repository at this point in the history
Without this, we have hardly any enforcement.  This is why the schema
mistake fixed in the previous patches weren't spotted immediately.

The hard work was done by:

```
$ for f in lightning-*.json; do grep -v '^  "additionalProperties": false,' $f | bagto $f; done
$ for f in lightning-*.json; do sed 's/"properties": {/"additionalProperties": false, "properties": {/' $f | bagto $f; done
$ make fmt-schemas
```

Then checking where 'additionalProperties: true' had been turned to
false (we deliberately use it in some places where there are if
statements in the schema, or occasionally where there can be arbitrary
fields).

[Including doc/rpc-schema-draft.json update by Shahana]
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Oct 30, 2024
1 parent 7b2c791 commit b327bd3
Show file tree
Hide file tree
Showing 139 changed files with 730 additions and 298 deletions.
519 changes: 368 additions & 151 deletions contrib/msggen/msggen/schema.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions doc/rpc-schema-draft.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@
"type": "object",
"additionalProperties": false,
"properties": {
"additionalProperties": {
"type": "boolean"
},
"required": {
"type": "array",
"items": {
Expand Down Expand Up @@ -290,6 +293,9 @@
"type": "object",
"additionalProperties": false,
"properties": {
"additionalProperties": {
"type": "boolean"
},
"required": {
"type": "array",
"items": {
Expand Down
3 changes: 2 additions & 1 deletion doc/schemas/lightning-addgossip.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"$schema": "../rpc-schema-draft.json",
"type": "object",
"additionalProperties": false,
"rpc": "addgossip",
"title": "Command for injecting a gossip message (low-level)",
"description": [
Expand All @@ -15,6 +14,7 @@
"required": [
"message"
],
"additionalProperties": false,
"properties": {
"message": {
"type": "hex",
Expand All @@ -25,6 +25,7 @@
}
},
"response": {
"additionalProperties": false,
"properties": {}
},
"author": [
Expand Down
3 changes: 2 additions & 1 deletion doc/schemas/lightning-addpsbtoutput.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"$schema": "../rpc-schema-draft.json",
"type": "object",
"additionalProperties": false,
"added": "v23.11",
"rpc": "addpsbtoutput",
"title": "Command to populate PSBT outputs from the wallet",
Expand All @@ -14,6 +13,7 @@
"required": [
"satoshi"
],
"additionalProperties": false,
"properties": {
"satoshi": {
"type": "sat",
Expand Down Expand Up @@ -47,6 +47,7 @@
"estimated_added_weight",
"outnum"
],
"additionalProperties": false,
"properties": {
"psbt": {
"type": "string",
Expand Down
3 changes: 2 additions & 1 deletion doc/schemas/lightning-askrene-age.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"$schema": "../rpc-schema-draft.json",
"type": "object",
"additionalProperties": false,
"rpc": "askrene-age",
"title": "Command for expiring information in a layer (EXPERIMENTAL)",
"description": [
Expand All @@ -14,6 +13,7 @@
"layer",
"cutoff"
],
"additionalProperties": false,
"properties": {
"layer": {
"type": "string",
Expand All @@ -34,6 +34,7 @@
"layer",
"num_removed"
],
"additionalProperties": false,
"properties": {
"layer": {
"type": "string",
Expand Down
3 changes: 2 additions & 1 deletion doc/schemas/lightning-askrene-create-channel.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"$schema": "../rpc-schema-draft.json",
"type": "object",
"additionalProperties": false,
"rpc": "askrene-create-channel",
"title": "Command to add a channel to layer (EXPERIMENTAL)",
"description": [
Expand All @@ -17,6 +16,7 @@
"short_channel_id",
"capacity_msat"
],
"additionalProperties": false,
"properties": {
"layer": {
"type": "string",
Expand Down Expand Up @@ -53,6 +53,7 @@
},
"response": {
"required": [],
"additionalProperties": false,
"properties": {}
},
"see_also": [
Expand Down
6 changes: 5 additions & 1 deletion doc/schemas/lightning-askrene-create-layer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"$schema": "../rpc-schema-draft.json",
"type": "object",
"additionalProperties": false,
"rpc": "askrene-create-layer",
"title": "Command to create a new layer (EXPERIMENTAL)",
"description": [
Expand All @@ -13,6 +12,7 @@
"required": [
"layer"
],
"additionalProperties": false,
"properties": {
"layer": {
"type": "string",
Expand All @@ -26,6 +26,7 @@
"required": [
"layers"
],
"additionalProperties": false,
"properties": {
"layers": {
"type": "array",
Expand Down Expand Up @@ -74,6 +75,7 @@
"short_channel_id",
"capacity_msat"
],
"additionalProperties": false,
"properties": {
"source": {
"type": "pubkey",
Expand Down Expand Up @@ -109,6 +111,7 @@
"required": [
"short_channel_id_dir"
],
"additionalProperties": false,
"properties": {
"htlc_minimum_msat": {
"type": "msat",
Expand Down Expand Up @@ -151,6 +154,7 @@
"short_channel_id",
"direction"
],
"additionalProperties": false,
"properties": {
"short_channel_id": {
"type": "short_channel_id",
Expand Down
3 changes: 2 additions & 1 deletion doc/schemas/lightning-askrene-disable-node.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"$schema": "../rpc-schema-draft.json",
"type": "object",
"additionalProperties": false,
"rpc": "askrene-disable-node",
"title": "Command to disable all channels to/from a node in a layer (EXPERIMENTAL)",
"description": [
Expand All @@ -14,6 +13,7 @@
"layer",
"node"
],
"additionalProperties": false,
"properties": {
"layer": {
"type": "string",
Expand All @@ -31,6 +31,7 @@
},
"response": {
"required": [],
"additionalProperties": false,
"properties": {}
},
"see_also": [
Expand Down
4 changes: 3 additions & 1 deletion doc/schemas/lightning-askrene-inform-channel.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"$schema": "../rpc-schema-draft.json",
"type": "object",
"additionalProperties": false,
"rpc": "askrene-inform-channel",
"title": "Command to add channel capacity restrictions to layer (EXPERIMENTAL)",
"description": [
Expand All @@ -16,6 +15,7 @@
"amount_msat",
"inform"
],
"additionalProperties": false,
"properties": {
"layer": {
"type": "string",
Expand Down Expand Up @@ -52,6 +52,7 @@
"required": [
"constraints"
],
"additionalProperties": false,
"properties": {
"constraints": {
"type": "array",
Expand All @@ -62,6 +63,7 @@
"short_channel_id_dir",
"timestamp"
],
"additionalProperties": false,
"properties": {
"short_channel_id_dir": {
"type": "short_channel_id_dir",
Expand Down
6 changes: 5 additions & 1 deletion doc/schemas/lightning-askrene-listlayers.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"$schema": "../rpc-schema-draft.json",
"type": "object",
"additionalProperties": false,
"rpc": "askrene-listlayers",
"title": "Command to display information about layers (EXPERIMENTAL)",
"description": [
Expand All @@ -11,6 +10,7 @@
],
"request": {
"required": [],
"additionalProperties": false,
"properties": {
"layer": {
"type": "string",
Expand All @@ -24,6 +24,7 @@
"required": [
"layers"
],
"additionalProperties": false,
"properties": {
"layers": {
"type": "array",
Expand Down Expand Up @@ -72,6 +73,7 @@
"short_channel_id",
"capacity_msat"
],
"additionalProperties": false,
"properties": {
"source": {
"type": "pubkey",
Expand Down Expand Up @@ -107,6 +109,7 @@
"required": [
"short_channel_id_dir"
],
"additionalProperties": false,
"properties": {
"short_channel_id_dir": {
"type": "short_channel_id_dir",
Expand Down Expand Up @@ -160,6 +163,7 @@
"required": [
"short_channel_id_dir"
],
"additionalProperties": false,
"properties": {
"short_channel_id_dir": {
"type": "short_channel_id_dir",
Expand Down
5 changes: 3 additions & 2 deletions doc/schemas/lightning-askrene-listreservations.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"$schema": "../rpc-schema-draft.json",
"type": "object",
"additionalProperties": false,
"rpc": "askrene-listreservations",
"title": "Command to display information about reservations (EXPERIMENTAL)",
"description": [
Expand All @@ -11,24 +10,26 @@
],
"request": {
"required": [],
"additionalProperties": false,
"properties": {}
},
"response": {
"required": [
"reservations"
],
"additionalProperties": false,
"properties": {
"reservations": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"required": [
"short_channel_id_dir",
"amount_msat",
"age_in_seconds",
"command_id"
],
"additionalProperties": false,
"properties": {
"short_channel_id_dir": {
"type": "short_channel_id_dir",
Expand Down
3 changes: 2 additions & 1 deletion doc/schemas/lightning-askrene-remove-layer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"$schema": "../rpc-schema-draft.json",
"type": "object",
"additionalProperties": false,
"rpc": "askrene-remove-layer",
"title": "Command to destroy a layer (EXPERIMENTAL)",
"description": [
Expand All @@ -13,6 +12,7 @@
"required": [
"layer"
],
"additionalProperties": false,
"properties": {
"layer": {
"type": "string",
Expand All @@ -24,6 +24,7 @@
},
"response": {
"required": [],
"additionalProperties": false,
"properties": {}
},
"see_also": [
Expand Down
5 changes: 3 additions & 2 deletions doc/schemas/lightning-askrene-reserve.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"$schema": "../rpc-schema-draft.json",
"type": "object",
"additionalProperties": false,
"rpc": "askrene-reserve",
"title": "Command for informing askrene that you are trying a path (EXPERIMENTAL)",
"description": [
Expand All @@ -15,12 +14,13 @@
"required": [
"path"
],
"additionalProperties": false,
"properties": {
"path": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": true,
"additionalProperties": false,
"required": [
"short_channel_id_dir",
"amount_msat"
Expand All @@ -45,6 +45,7 @@
},
"response": {
"required": [],
"additionalProperties": false,
"properties": {}
},
"see_also": [
Expand Down
5 changes: 3 additions & 2 deletions doc/schemas/lightning-askrene-unreserve.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"$schema": "../rpc-schema-draft.json",
"type": "object",
"additionalProperties": false,
"rpc": "askrene-unreserve",
"title": "Command for informing askrene that you are no longer trying a path (EXPERIMENTAL)",
"description": [
Expand All @@ -15,12 +14,13 @@
"required": [
"path"
],
"additionalProperties": false,
"properties": {
"path": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": true,
"additionalProperties": false,
"required": [
"short_channel_id_dir",
"amount_msat"
Expand All @@ -45,6 +45,7 @@
},
"response": {
"required": [],
"additionalProperties": false,
"properties": {}
},
"see_also": [
Expand Down
Loading

0 comments on commit b327bd3

Please sign in to comment.