diff --git a/docs/source/conf.py b/docs/source/conf.py index 753272f5a457bdf7ed1d19cc817da88e3d19b9eb..886c27c24903cbd2482cb12c35adcd47038c40eb 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -14,14 +14,43 @@ # import sys # sys.path.insert(0, os.path.abspath('.')) +from importlib import import_module +from docutils.parsers.rst import Directive +from docutils import nodes +from sphinx import addnodes +import json import os import sys + sys.path.insert(0, os.path.abspath( os.path.join( os.path.dirname(__file__), '..', '..', 'inventory_provider'))) +class RenderAsJSON(Directive): + # cf. https://stackoverflow.com/a/59883833 + + required_arguments = 1 + + def run(self): + module_path, member_name = self.arguments[0].rsplit('.', 1) + + member_data = getattr(import_module(module_path), member_name) + code = json.dumps(member_data, indent=2) + + literal = nodes.literal_block(code, code) + literal['language'] = 'json' + + return [ + addnodes.desc_name(text=member_name), + addnodes.desc_content('', literal) + ] + + +def setup(app): + app.add_directive('asjson', RenderAsJSON) + # -- Project information ----------------------------------------------------- diff --git a/inventory_provider/config.py b/inventory_provider/config.py index aa6ef5ffe623a9037c39fef4bdba1156e22b5ba1..d8ce6e9f5ba1200789cb74ad565c947632f2d6a9 100644 --- a/inventory_provider/config.py +++ b/inventory_provider/config.py @@ -1,5 +1,4 @@ import json - import jsonschema CONFIG_SCHEMA = { @@ -142,10 +141,14 @@ CONFIG_SCHEMA = { def load(f): """ - loads, validates and returns configuration parameters + Loads, validates and returns configuration parameters. + + Input is validated against this jsonschema: + + .. asjson:: inventory_provider.config.CONFIG_SCHEMA :param f: file-like object that produces the config file - :return: + :return: a dict containing the parsed configuration parameters """ config = json.loads(f.read()) jsonschema.validate(config, CONFIG_SCHEMA)