haystack/docs/_src/api/openapi/generate_openapi_specs.py
Sara Zan 5c119d973d
Versioning openapi.json (#2228)
* Add versions of the the openapi.json file for versioned documentation

* Update Documentation & Code Style

* Use .suffix for extension check

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2022-02-22 17:35:00 +01:00

32 lines
932 B
Python

import json
from pathlib import Path
import os
import sys
import shutil
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, haystack_version
# Generate the openapi specs
specs = get_openapi_specs()
# Dump the specs into a JSON file
with open("openapi.json", "w") as f:
json.dump(specs, f, indent=4)
# Remove rc versions of the specs from the folder
for specs_file in os.listdir():
if os.path.isfile(specs_file) and "rc" in specs_file and Path(specs_file).suffix == ".json":
os.remove(specs_file)
# Add versioned copy
shutil.copy("openapi.json", f"openapi-{haystack_version}.json")