diff --git a/docs/api_spec.md b/docs/api_spec.md new file mode 100644 index 00000000..cbaed76c --- /dev/null +++ b/docs/api_spec.md @@ -0,0 +1,17 @@ +# REST API Spec + +This is the spec for package version version **{{ env.config.version }}**, +exported from FastAPI in `conf.py` as follows + +```python +import yaml +from pangeo_forge_orchestrator.api import api + +api_spec = api.openapi() +with open("openapi.yaml", mode='w') as fp: + yaml.dump(api_spec, fp) +``` + +```{eval-rst} +.. openapi:: openapi.yaml +``` diff --git a/docs/conf.py b/docs/conf.py index 0f5453b4..6eb140e5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,9 +1,17 @@ # Compare: https://github.com/pangeo-forge/pangeo-forge-recipes/blob/master/docs/conf.py +from importlib.metadata import version as _get_version + +import yaml + +from pangeo_forge_orchestrator.api import api + +version = _get_version("pangeo_forge_orchestrator") + # -- Project information ----------------------------------------------------- project = "Pangeo Forge Orchestrator" -copyright = "2021, Pangeo Community" +copyright = "2022, Pangeo Community" author = "Pangeo Community" # -- General configuration --------------------------------------------------- @@ -15,8 +23,11 @@ # "numpydoc", "sphinx_autodoc_typehints", "sphinx_copybutton", + "sphinxcontrib.openapi", ] +myst_enable_extensions = ["substitution"] + extlinks = { "issue": ("https://github.com/pangeo-forge/pangeo-forge-orchestrator/issues/%s", "GH issue "), "pull": ("https://github.com/pangeo-forge/pangeo-forge-orchestrator/pull/%s", "GH PR "), @@ -45,3 +56,10 @@ html_static_path = ["_static"] myst_heading_anchors = 2 + + +# write out the openapi spec to a yaml file +api_spec = api.openapi() +with open("openapi.yaml", mode="w") as fp: + yaml.dump(api_spec, fp) +# this is read in api_spec.md diff --git a/docs/index.md b/docs/index.md index 7f711721..5eb9abdf 100644 --- a/docs/index.md +++ b/docs/index.md @@ -9,5 +9,6 @@ You have found the documentation for for `pangeo-forge-orchestrator`, an unrelea ```{toctree} :maxdepth: 1 +api_spec development_guide ``` diff --git a/docs/requirements.txt b/docs/requirements.txt index 336f7707..1e326cca 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -4,4 +4,6 @@ myst-parser==0.13.6 myst-nb==0.12.3 sphinx-copybutton==0.3.1 sphinx-autodoc-typehints +sphinxcontrib-openapi +uvicorn . diff --git a/setup.cfg b/setup.cfg index a4d84f1b..71b1ee6a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -59,7 +59,7 @@ max-line-length = 100 [isort] known_first_party=pangeo_forge_orchestrator -known_third_party=fastapi,pydantic,pytest,pytest_lazyfixture,requests,setuptools,sqlalchemy,sqlmodel,typer +known_third_party=fastapi,pydantic,pytest,pytest_lazyfixture,requests,setuptools,sqlalchemy,sqlmodel,typer,yaml multi_line_output=3 include_trailing_comma=True force_grid_wrap=0