Skip to content

Commit 873e8b4

Browse files
evansmjShahanaFarooqui
authored andcommitted
docs: clarify writing-json-schemas.md and autogenerate-rpc-examples.py
Spelling and clarity on how to update schemas when adding RPCs.
1 parent 66d4d0f commit 873e8b4

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

doc/contribute-to-core-lightning/coding-style-guidelines/writing-json-schemas.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ You should always list all fields which are _always_ present in `"required"`.
2626

2727
We extend the basic types; see [fixtures.py](https://github.com/ElementsProject/lightning/tree/master/contrib/pyln-testing/pyln/testing/fixtures.py).
2828

29-
In addition, before committing a new schema or a new version of it, make sure that it is well formatted. If you don't want do it by hand, use `make fmt-schema` that uses jq under the hood.
29+
In addition, before committing a new schema or a new version of it, make sure that it is well formatted. If you don't want to do it by hand, use `make fmt-schema` that uses jq under the hood.
3030

3131
### Using Conditional Fields
3232

3333
Sometimes one field is only sometimes present; if you can, you should make the schema know when it should (and should not!) be there.
3434

35-
There are two kinds of conditional fields expressable: fields which are only present if another field is present, or fields only present if another field has certain values.
35+
There are two kinds of conditional fields expressible: fields which are only present if another field is present, or fields only present if another field has certain values.
3636

3737
To add conditional fields:
3838

@@ -43,11 +43,11 @@ To add conditional fields:
4343
5. If a field requires another field value, use the pattern
4444
`"properties": { "field": { "enum": [ "val1", "val2" ] } }` inside the "if".
4545
6. Inside the "then", use `"additionalProperties": false` and place empty `{}` for all the other possible properties.
46-
7. If you haven't covered all the possibilties with `if` statements, add an `else` with `"additionalProperties": false` which simply mentions every allowable property. This ensures that the fields can _only_ be present when conditions are met.
46+
7. If you haven't covered all the possibilities with `if` statements, add an `else` with `"additionalProperties": false` which simply mentions every allowable property. This ensures that the fields can _only_ be present when conditions are met.
4747

4848
### Exceptions in dynamic schema generation
4949

50-
- If response (`RETURN VALUE`) should not be generated dynamically and you want it to be a custom text message instead. You can use `return_value_notes` to add custom text with empty `properties`. Examples: `setpsbtversion`, `commando`, `recover`.
50+
- If response (`RETURN VALUE`) should not be generated dynamically, and you want it to be a custom text message instead. You can use `return_value_notes` to add custom text with empty `properties`. Examples: `setpsbtversion`, `commando`, `recover`.
5151
- If only one of multiple request parameters can be provided then utilize `oneOfMany`
5252
key with condition defining arrays. For example, `plugin` command defines it as
5353
`"oneOfMany": [["plugin", "directory"]]` and it prints the parameter output as
@@ -60,13 +60,13 @@ To add conditional fields:
6060
use `dependentUpon` key where object key can be mapped with the array of dependent params.
6161
For example, `listforwards` command has `start` and `limit` params dependent upon `index` and
6262
it can be defined as `"dependentUpon": { "index": ["start", "limit"] }` in the json and it will
63-
generate the markdown syntax as `[*index* [*start*] [*limit*]]`.
63+
generate the Markdown syntax as `[*index* [*start*] [*limit*]]`.
6464

6565
### Re-generate examples listed in rpc schemas (doc/schemas/lightning-*.json)
6666

6767
1. The `autogenerate-rpc-examples.py` script regenerates RPC examples for methods listed in `doc/schemas/lightning-*.json` files.
6868
2. It uses our pre-existing pytest suite to perform this task.
69-
3. The script runs a test named `test_generate_examples`, which sets up test nodes, records RPC requests, and captures responses.
69+
3. The script runs a test named `test_generate_examples`, which sets up test nodes, records RPC requests, and captures responses. If you have added an RPC, make sure to add its use to the scripts here.
7070
4. To prevent accidental overwriting of examples with other tests, set the environment variable `GENERATE_EXAMPLES=True` before running the script.
7171
5. By default, all methods are regenerated. To specify which methods to regenerate, set the `REGENERATE` environment variable with a comma-separated list of method names. Eg. `REGENERATE='getinfo,connect'` will only regenerate examples for the getinfo and connect RPCs.
7272
6. The dev-bitcoind-poll is set to 3 seconds. Ensure the `TIMEOUT` environment variable is set to more than 3 seconds to avoid test failures due to a short waiting time for bitcoind responses.
@@ -75,7 +75,7 @@ To add conditional fields:
7575
rm -rf /tmp/ltests* && REGENERATE='getinfo,connect' VALGRIND=0 TIMEOUT=10 TEST_DEBUG=1 pytest -vvv -s -p no:logging -n 6 tests/autogenerate-rpc-examples.py
7676
```
7777
8. The script saves logs in a file named `autogenerate-examples-status.log`, located in the root directory.
78-
9. After running the script, execute make to ensure that the schema has been updated in all relevant locations, such as `...msggen/schema.json`.
78+
9. After running the script, execute `make` to ensure that the schema has been updated in all relevant locations, such as `...msggen/schema.json`.
7979

8080
### JSON Drinking Game!
8181

tests/autogenerate-rpc-examples.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def format_json_with_jq(json_data):
138138
res = node.rpc.call(method, params)
139139
logger.info(f'{method} response: {res}')
140140
# Return response without updating the file because user doesn't want to update the example
141-
# Executing the method and returing the response is useful for further example updates
141+
# Executing the method and returning the response is useful for further example updates
142142
if method not in REGENERATING_RPCS:
143143
return res
144144
else:
@@ -1150,7 +1150,7 @@ def list_missing_examples():
11501150
logger.error(f'Error in listing missing examples: {e}')
11511151

11521152
def clear_existing_examples():
1153-
"""Clear existing examples in JSON files to regenrate them later"""
1153+
"""Clear existing examples in JSON files to regenerate them later"""
11541154
global REGENERATING_RPCS
11551155
for rpc in REGENERATING_RPCS:
11561156
try:

0 commit comments

Comments
 (0)