Skip to content

Commit

Permalink
[JsonGen] Fix documentation from .json with index (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaszm authored Oct 14, 2024
1 parent 2031a64 commit 67c91e3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion JsonGenerator/GenerateDocs.bat
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if not exist JsonGenerator.py (
exit /b 0
)

set COMMAND=python JsonGenerator.py --docs -i ../../Source/interfaces/json -j ../../Source/interfaces -o doc
set COMMAND=python JsonGenerator.py --docs -i ../../Source/interfaces/json -i ../../Source/interfaces/qa_json -j ../../Source/interfaces -j ../../Source/qa_interfaces -I ../../Source -o doc

if "%1"=="" (
echo Usage %0 [JSONFILE] OR [DIRECTORY]
Expand Down
4 changes: 2 additions & 2 deletions JsonGenerator/GenerateDocs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

command -v ./JsonGenerator.py >/dev/null 2>&1 || { echo >&2 "JsonGenerator.py is not available. Aborting."; exit 1; }

if [ -d ]; then
if [ $# -eq 1 ] && [ -d $1 ]; then
files=`find $1 -name "*Plugin.json"`
elif [ $# -gt 0 ]; then
files=$@
Expand All @@ -40,6 +40,6 @@ fi

echo "Generating Plugin markdown documentation..."

./JsonGenerator.py --docs -i ../../ThunderInterfaces/jsonrpc -j ../../ThunderInterfaces/interfaces -I ../../Thunder/Source -o doc --verbose $files
./JsonGenerator.py --docs -i ../../ThunderInterfaces/jsonrpc -i ../../ThunderInterfaces/qa_jsonrpc -j ../../ThunderInterfaces/interfaces -j ../../ThunderInterfaces/qa_interfaces -I ../../Thunder/Source -o doc --verbose $files

echo "Complete."
9 changes: 8 additions & 1 deletion JsonGenerator/source/documentation_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def _TableObj(name, obj, parentName="", parent=None, prefix="", parentOptional=F
obsolete = obj["obsolete"] if "obsolete" in obj else False
restricted = obj.get("range")

name = name.replace(' ','-')

if parent and not optional:
if parent["type"] == "object":
optional = ("required" not in parent and len(parent["properties"]) > 1) or (
Expand Down Expand Up @@ -333,8 +335,13 @@ def MethodDump(method, props, classname, section, header, is_notification=False,
if "name" not in props["index"][0] or "example" not in props["index"][0]:
raise DocumentationError("'%s': index field requires 'name' and 'example' properties" % method)

if "type" not in props["index"][0]:
props["index"][0]["type"] = "string"
if props["index"][1] and ("type" not in props["index"][1]):
props["index"][1]["type"] = "string"

extra_paragraph = "> The *%s* argument shall be passed as the index to the property, e.g. ``%s.1.%s@<%s>``." % (
props["index"][0]["name"].lower(), classname, method, props["index"][0]["name"].lower())
props["index"][0]["name"].lower(), classname, method, props["index"][0]["name"].lower().replace(' ', '-'))

if props["index"][0] and props["index"][0].get("optional") and props["index"][1] and props["index"][1].get("optional"):
extra_paragraph += " The index is optional."
Expand Down
21 changes: 12 additions & 9 deletions JsonGenerator/source/json_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1211,8 +1211,6 @@ def Scan(pairs):
# Need to prepend with 'file:' for jsonref to load an external file..
ref = v.split("#") if "#" in v else [v,""]

assert include_paths

ref_file = None

if "{interfacedir}" in ref[0]:
Expand Down Expand Up @@ -1250,8 +1248,6 @@ def Scan(pairs):
elif v.endswith(".h") or v.endswith(".h#"):
ref = v.replace("#", "").replace("{cppinterfacedir}", "{interfacedir}")

assert cpp_include_paths

ref_file = None

if "{interfacedir}" in ref:
Expand All @@ -1262,10 +1258,20 @@ def Scan(pairs):
ref_file = rf
break
else:
log.Info("failed to include '%s', file not found" %rf);
log.Info("failed to include '%s', file not found" %rf)

if not ref_file and "{currentdir}" in ref:
rf = ref.replace("{currentdir}", os.path.dirname(file))
if os.path.exists(rf):
ref_file = rf

if not ref_file:
rf = os.path.dirname(file) + os.sep + ref
if os.path.exists(rf):
ref_file = rf

if ref_file:
log.Info("including C++ header '%s'..." % rf);
log.Info("including C++ header '%s'..." % ref_file)
cppif, _ = header_loader.LoadInterface(ref_file, log, True, header_include_paths)

if cppif:
Expand Down Expand Up @@ -1303,9 +1309,6 @@ def Scan(pairs):
def Load(log, path, if_dirs = [], cpp_if_dirs = [], include_paths = []):
temp_files = []

if_dirs.append(os.path.dirname(path))
cpp_if_dirs.append(os.path.dirname(path))

if path.endswith(".h"):
schemas, additional_includes = header_loader.LoadInterface(path, log, False, include_paths)
else:
Expand Down

0 comments on commit 67c91e3

Please sign in to comment.