You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/contribute-to-core-lightning/coding-style-guidelines/writing-json-schemas.md
+50-14Lines changed: 50 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,22 +62,58 @@ To add conditional fields:
62
62
it can be defined as `"dependentUpon": { "index": ["start", "limit"] }` in the json and it will
63
63
generate the Markdown syntax as `[*index* [*start*] [*limit*]]`.
64
64
65
-
### Re-generate examples listed in rpc schemas (doc/schemas/lightning-*.json)
66
-
67
-
1. The `autogenerate-rpc-examples.py` script regenerates RPC examples for methods listed in `doc/schemas/lightning-*.json` files.
68
-
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. If you have added an RPC, make sure to add its use to the scripts here.
70
-
4. To prevent accidental overwriting of examples with other tests, set the environment variable `GENERATE_EXAMPLES=True` before running the script.
71
-
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.
72
-
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.
73
-
7. To run the script using Poetry, use the following command:
65
+
## Generating Examples in Schema
66
+
The `tests/autogenerate-rpc-examples.py` test script regenerates RPC examples for methods defined
67
+
in `doc/schemas/lightning-*.json`. These examples are located at the end of each schema page,
68
+
detailing `shell` and `json` request formats along with their corresponding `json` responses.
69
+
The script utilizes the pytest suite to automate this task by running a test, `test_generate_examples`,
70
+
that sets up test nodes, records RPC requests, and captures responses. Any new RPC command's examples
71
+
should also be included in this scripts. This test only executes example generation if `GENERATE_EXAMPLES=True`
72
+
is set, preventing accidental overwrites from unrelated tests.
73
+
74
+
### Adding New Examples
75
+
1. Define a New Function (if needed):
76
+
- If adding multiple examples for the same feature (e.g., `askrene`), create a new function. Otherwise, use an existing relevant function.
77
+
2. Add the update_example Method:
78
+
- Define examples using `update_example` with parameters: `node method params [res] [description]`.
79
+
`node`: Specifies the node to execute the RPC.
80
+
`method`: The RPC method name.
81
+
`params`: RPC parameters in JSON or list format.
82
+
`response (optional)`: Specify for wait commands or pre-recorded responses.
83
+
`description (optional)`: Brief explanation of the example.
84
+
3. Update the Ignore List:
85
+
- Remove the RPC method name from `IGNORE_RPCS_LIST` to include it in the example generation.
86
+
4. Run and Refine:
87
+
- Run the test multiple times to detect variable values in responses:
0 commit comments