Skip to content

Commit dea8fd9

Browse files
committed
Script to fix OpenAPI documentation
1 parent 72c0428 commit dea8fd9

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ format: ## Format the code into unified format
3636
schema: ## Generate OpenAPI schema file
3737
uv run scripts/generate_openapi_schema.py docs/openapi.json
3838

39-
openapi-doc: docs/openapi.json ## Generate OpenAPI documentation
40-
openapi-to-markdown --input_file docs/openapi.json --output_file docs/output.md
39+
openapi-doc: docs/openapi.json scripts/fix_openapi_doc.py ## Generate OpenAPI documentation
40+
openapi-to-markdown --input_file docs/openapi.json --output_file output.md
41+
python3 scripts/fix_openapi_doc.py < output.md > docs/output.md
42+
rm output.md
4143

4244
# TODO uv migration
4345
requirements.txt: pyproject.toml pdm.lock ## Generate requirements.txt file containing hashes for all non-devel packages

scripts/fix_openapi_doc.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python3
2+
3+
"""Filter to fix the generated OpenAPI documentation."""
4+
5+
import fileinput
6+
7+
TABLE_ROW_CONTINUATION_LINE = " |"
8+
9+
lines = list(fileinput.input())
10+
11+
lines_count = len(lines)
12+
13+
for i in range(lines_count):
14+
current_line = lines[i].rstrip("\r\n")
15+
16+
# limit check
17+
if i == lines_count - 1:
18+
print(current_line)
19+
break
20+
21+
# the next line must exists -> read it
22+
next_line = lines[i + 1].rstrip("\r\n")
23+
24+
# skip the continuation line as it was used already
25+
# during previous line processing
26+
if current_line == TABLE_ROW_CONTINUATION_LINE:
27+
continue
28+
29+
# check if table row continuation line is present
30+
if next_line == TABLE_ROW_CONTINUATION_LINE:
31+
print(current_line + TABLE_ROW_CONTINUATION_LINE)
32+
else:
33+
print(current_line)

0 commit comments

Comments
 (0)