From 00ff8250236cdc19df6bc38a83f457d626b28016 Mon Sep 17 00:00:00 2001 From: ShahanaFarooqui Date: Tue, 23 Jan 2024 21:58:54 -0800 Subject: [PATCH] doc: msggen and pyln-testing script updates --- Makefile | 2 +- contrib/msggen/msggen/utils/utils.py | 13 +++++----- contrib/pyln-testing/pyln/testing/fixtures.py | 24 +++++++------------ 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index fd2b38e41546..55da5090930f 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/contrib/msggen/msggen/utils/utils.py b/contrib/msggen/msggen/utils/utils.py index a2679bf5e9e9..8beb1200ba67 100644 --- a/contrib/msggen/msggen/utils/utils.py +++ b/contrib/msggen/msggen/utils/utils.py @@ -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. @@ -33,7 +32,7 @@ def load_jsonrpc_service(schema_dir: str): "SendPay", "ListChannels", "AddGossip", - "AutoCleanInvoice", + # "AutoCleanInvoice", "CheckMessage", "Close", "Connect", diff --git a/contrib/pyln-testing/pyln/testing/fixtures.py b/contrib/pyln-testing/pyln/testing/fixtures.py index c0b0f9cfb134..3974b10d6ad3 100644 --- a/contrib/pyln-testing/pyln/testing/fixtures.py +++ b/contrib/pyln-testing/pyln/testing/fixtures.py @@ -412,15 +412,16 @@ 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: @@ -428,20 +429,11 @@ def jsonschemas(): 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