MCPcopy Create free account
hub / github.com/ElementsProject/lightning / generate_from_schema

Function generate_from_schema

tools/fromschema.py:208–255  ·  view source on GitHub ↗

This is not general, but works for us

(schema)

Source from the content-addressed store, hash-verified

206
207
208def generate_from_schema(schema):
209 """This is not general, but works for us"""
210 if schema['type'] != 'object':
211 # 'stop' returns a single string!
212 output_member(None, schema, False, '', prefix='On success, returns a single element')
213 return
214
215 toplevels = []
216 warnings = []
217 props = schema['properties']
218
219 # We handle warnings on top-level objects with a separate section,
220 # so collect them now and remove them
221 for toplevel in list(props.keys()):
222 if toplevel.startswith('warning'):
223 warnings.append((toplevel, props[toplevel]['description']))
224 del props[toplevel]
225 else:
226 toplevels.append(toplevel)
227
228 # No properties -> empty object.
229 if toplevels == []:
230 output('On success, an empty object is returned.\n')
231 sub = schema
232 elif len(toplevels) == 1 and props[toplevels[0]]['type'] == 'object':
233 output('On success, an object containing {} is returned. It is an object containing:\n\n'.format(fmt_propname(toplevels[0])))
234 # Don't have a description field here, it's not used.
235 assert 'description' not in toplevels[0]
236 sub = props[toplevels[0]]
237 elif len(toplevels) == 1 and props[toplevels[0]]['type'] == 'array':
238 output('On success, an object containing {} is returned. It is an array of objects, where each object contains:\n\n'.format(fmt_propname(toplevels[0])))
239 # Don't have a description field here, it's not used.
240 assert 'description' not in toplevels[0]
241 sub = props[toplevels[0]]['items']
242 else:
243 output('On success, an object is returned, containing:\n\n')
244 sub = schema
245
246 output_members(sub)
247
248 if warnings:
249 outputs(['\n', 'The following warnings may also be returned:\n\n'])
250 for w, desc in warnings:
251 output("- {}: {}\n".format(fmt_propname(w), desc))
252
253 # GH markdown rendering gets upset if there isn't a blank line
254 # between a list and the end comment.
255 output('\n')
256
257
258def main(schemafile, markdownfile):

Callers 1

mainFunction · 0.85

Calls 5

output_memberFunction · 0.85
outputFunction · 0.85
fmt_propnameFunction · 0.85
output_membersFunction · 0.85
outputsFunction · 0.85

Tested by

no test coverage detected