-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from govlt/redoc-site
Generate ReDoc
- Loading branch information
Showing
5 changed files
with
120 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Prepare Python environment | ||
description: Setup python, poetry, SpatialLite and install dependencies | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Install poetry | ||
uses: abatilo/actions-poetry@v2 | ||
with: | ||
poetry-version: '1.8.*' | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version-file: pyproject.toml | ||
cache: poetry | ||
|
||
- name: Install dependencies | ||
run: poetry install --no-root | ||
shell: bash | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Adapted from https://www.doctave.com/blog/python-export-fastapi-openapi-spec | ||
|
||
import argparse | ||
import json | ||
import sys | ||
import yaml | ||
from uvicorn.importer import import_from_string | ||
|
||
parser = argparse.ArgumentParser(prog="extract-openapi.py") | ||
parser.add_argument("app", help='App import string. Eg. "src.main:app"', default="src.main:app") | ||
parser.add_argument("--app-dir", help="Directory containing the app", default=".") | ||
parser.add_argument("--out", help="Output file ending in .json or .yaml", default="openapi.yaml") | ||
|
||
if __name__ == "__main__": | ||
args = parser.parse_args() | ||
|
||
if args.app_dir is not None: | ||
print(f"adding {args.app_dir} to sys.path") | ||
sys.path.insert(0, args.app_dir) | ||
|
||
print(f"importing app from {args.app}") | ||
app = import_from_string(args.app) | ||
openapi = app.openapi() | ||
version = openapi.get("openapi", "unknown version") | ||
|
||
print(f"writing openapi spec v{version}") | ||
with open(args.out, "w") as f: | ||
if args.out.endswith(".json"): | ||
json.dump(openapi, f, indent=2) | ||
else: | ||
yaml.dump(openapi, f, sort_keys=False) | ||
|
||
print(f"spec written to {args.out}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters