Skip to content

Commit

Permalink
doc: msggen and pyln-testing script updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ShahanaFarooqui committed Jan 24, 2024
1 parent 35f2f1f commit 00ff825
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ ifneq ($(RUST),0)
include cln-rpc/Makefile
include cln-grpc/Makefile

$(MSGGEN_GENALL)&: doc/schemas/*.request.json doc/schemas/*.schema.json
$(MSGGEN_GENALL)&: doc/schemas/lightning-*.json
PYTHONPATH=contrib/msggen $(PYTHON) contrib/msggen/msggen/__main__.py

# The compiler assumes that the proto files are in the same
Expand Down
13 changes: 6 additions & 7 deletions contrib/msggen/msggen/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@


def load_jsonrpc_method(name, schema_dir: Path):
"""Load a method based on the file naming conventions for the JSON-RPC.
"""
"""Load a method based on the file naming conventions for the JSON-RPC."""
base_path = schema_dir
req_file = base_path / f"{name.lower()}.request.json"
resp_file = base_path / f"{name.lower()}.schema.json"
request = CompositeField.from_js(json.load(open(req_file)), path=name)
response = CompositeField.from_js(json.load(open(resp_file)), path=name)
json_file = base_path / f"lightning-{name.lower()}.json"
file_data = json.load(open(json_file))
request = CompositeField.from_js(file_data.get('request', {}), path=name)
response = CompositeField.from_js(file_data.get('response', {}), path=name)

# Normalize the method request and response typename so they no
# longer conflict.
Expand All @@ -33,7 +32,7 @@ def load_jsonrpc_service(schema_dir: str):
"SendPay",
"ListChannels",
"AddGossip",
"AutoCleanInvoice",
# "AutoCleanInvoice",
"CheckMessage",
"Close",
"Connect",
Expand Down
24 changes: 8 additions & 16 deletions contrib/pyln-testing/pyln/testing/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,36 +412,28 @@ def is_msat_or_any(checker, instance):
type_checker=type_checker)


def _load_schema(filename, is_request):
def _load_schema(filename):
"""Load the schema from @filename and create a validator for it"""
with open(filename, 'r') as f:
return _extra_validator(is_request)(json.load(f))
data = json.load(f)
return [_extra_validator(False)(data.get('response', {})), _extra_validator(True)(data.get('request', {}))]


@pytest.fixture(autouse=True)
def jsonschemas():
"""Load schema files if they exist: returns request/response schemas by pairs"""
"""Load schema file if it exist: returns response/request schemas by pairs"""
try:
schemafiles = os.listdir('doc/schemas')
except FileNotFoundError:
schemafiles = []

schemas = {}
for fname in schemafiles:
if fname.endswith('.schema.json'):
base = fname.rpartition('.schema')[0]
is_request = False
index = 1
elif fname.endswith('.request.json'):
base = fname.rpartition('.request')[0]
is_request = True
index = 0
else:
continue
if base not in schemas:
if fname.startswith('lightning-') and fname.endswith('.json'):
base = fname.replace('lightning-', '').replace('.json', '')
# Response is 0 and request is 1
schemas[base] = [None, None]
schemas[base][index] = _load_schema(os.path.join('doc/schemas', fname),
is_request)
schemas[base] = _load_schema(os.path.join('doc/schemas', fname))
return schemas


Expand Down

0 comments on commit 00ff825

Please sign in to comment.