script: Updated sql-schema_gen and documented it's jq dependency.
This commit is contained in:
committed by
Rusty Russell
parent
04884ca664
commit
4c370022d0
@@ -225,16 +225,27 @@ plugins/recover: common/gossmap.o common/fp16.o $(PLUGIN_RECOVER_OBJS) $(PLUGIN
|
||||
|
||||
# This covers all the low-level list RPCs which return simple arrays
|
||||
SQL_LISTRPCS := listchannels listforwards listhtlcs listinvoices listnodes listoffers listpeers listpeerchannels listclosedchannels listtransactions listsendpays bkpr-listaccountevents bkpr-listincome
|
||||
SQL_LISTRPCS_SCHEMAS := $(foreach l,$(SQL_LISTRPCS),doc/schemas/$l.schema.json)
|
||||
# We squeeze:
|
||||
# descriptions (we don't need)
|
||||
# fields with no members (we don't need)
|
||||
# whitespace
|
||||
# We can't simply *remove* fields, since the extra comma left over can
|
||||
# make invalid JSON. Grr!
|
||||
# But these simple removals drop us from 100k to 29k.
|
||||
SQL_LISTRPCS_SCHEMAS := $(foreach l,$(SQL_LISTRPCS),doc/schemas/lightning-$l.json)
|
||||
|
||||
# RES_JSON is generated by:
|
||||
# 1: deleting description array (used for field details) but keeping description keys
|
||||
# 2: deleting additionalProperties, required, enum, maxLength, minLength, pre_return_value_notes, post_return_value_notes, anyOf, oneOf, hidden, untyped, default, comment, added, maximum, minimum, pattern, format
|
||||
# (We only need [field].type, [field].name, [field].deprecated, [field].allOf, [field].items.allOf and allOf from response.properties)
|
||||
# 3: deleting empty objects from .response.properties
|
||||
# But these simple removals drop us from 100k to 18k.
|
||||
plugins/sql-schema_gen.h: plugins/Makefile $(SQL_LISTRPCS_SCHEMAS)
|
||||
@$(call VERBOSE,GEN $@, (SEP=""; echo '"{'; for f in $(SQL_LISTRPCS); do echo "$$SEP\\\"$$f\\\":"; sed -e s/\"description\":\ *\".\*\"/\"\":\"\"/ -e s/\".*\":\ *{}/\"\":{}/ -e s/\"/\\\\\"/g < doc/schemas/$$f.schema.json; SEP=","; done; echo '}"') | tr -d ' \n' > $@)
|
||||
@$(call VERBOSE,GEN $@, \
|
||||
( \
|
||||
SEP=""; \
|
||||
echo '"{'; \
|
||||
for f in $(SQL_LISTRPCS); do \
|
||||
RES_JSON=$$(echo "$$(jq 'walk(if type == "object" then if has("description") and (.description | type) == "array" then del(.description) else . end else . end ) | walk(if type == "object" then del(.additionalProperties, .required, .enum, .maxLength, .minLength, .pre_return_value_notes, .post_return_value_notes, .anyOf, .oneOf, .hidden, .untyped, .default, .comment, .added, .maximum, .minimum, .pattern, .format) else . end) | walk(if type == "object" then with_entries(select(.value != {})) else . end) | .response.properties' < doc/schemas/lightning-$$f.json)" | sed 's/"/\\"/g'); \
|
||||
echo "$$SEP\\\"$$f\\\":{\\\"properties\\\": $$RES_JSON}"; \
|
||||
SEP=","; \
|
||||
done; \
|
||||
echo '}"' \
|
||||
) | tr -d ' \n' > $@ \
|
||||
)
|
||||
|
||||
plugins/sql.o: plugins/sql-schema_gen.h
|
||||
plugins/sql: $(PLUGIN_SQL_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) common/gossip_store.o gossipd/gossip_store_wiregen.o
|
||||
|
||||
Reference in New Issue
Block a user