haystack/docs/_src/api/openapi/generate_openapi_specs.py
Sara Zan 713771095b
Autogenerate OpenAPI specs file (#2047)
* Add docstrings to the REST API endpoint to have them included in the OpenAPI specs

* Attempt at make GitHub CI generate the OpenAPI specs

* Missing __init__.py was breaking rest_api import

* Add comment on dummy pipeline

* Create separate workflow file for the OpenAPI specs generation

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Markus Paff <markuspaff.mp@gmail.com>
2022-01-27 13:06:01 +01:00

22 lines
588 B
Python

import json
from pathlib import Path
import os
import sys
sys.path.append("../../../../")
rest_path = Path("../../../../rest_api").absolute()
pipeline_path = str(rest_path/"pipeline"/"pipeline_empty.yaml")
app_path = str(rest_path/"application.py")
print(f"Loading OpenAPI specs from {app_path} with pipeline at {pipeline_path}")
os.environ["PIPELINE_YAML_PATH"] = pipeline_path
from rest_api.application import get_openapi_specs
# Generate the openapi specs
specs = get_openapi_specs()
# Dump the specs into a JSON file
with open(f"openapi.json", "w") as f:
json.dump(specs, f)