2022-01-27 13:06:01 +01:00
|
|
|
import json
|
|
|
|
from pathlib import Path
|
|
|
|
import os
|
|
|
|
import sys
|
2022-02-22 17:35:00 +01:00
|
|
|
import shutil
|
2022-02-03 13:43:18 +01:00
|
|
|
|
2022-01-27 13:06:01 +01:00
|
|
|
sys.path.append("../../../../")
|
|
|
|
|
|
|
|
rest_path = Path("../../../../rest_api").absolute()
|
2022-02-03 13:43:18 +01:00
|
|
|
pipeline_path = str(rest_path / "pipeline" / "pipeline_empty.yaml")
|
|
|
|
app_path = str(rest_path / "application.py")
|
2022-01-27 13:06:01 +01:00
|
|
|
print(f"Loading OpenAPI specs from {app_path} with pipeline at {pipeline_path}")
|
|
|
|
|
|
|
|
os.environ["PIPELINE_YAML_PATH"] = pipeline_path
|
|
|
|
|
2022-02-22 17:35:00 +01:00
|
|
|
from rest_api.application import get_openapi_specs, haystack_version
|
2022-01-27 13:06:01 +01:00
|
|
|
|
|
|
|
# Generate the openapi specs
|
|
|
|
specs = get_openapi_specs()
|
|
|
|
|
|
|
|
# Dump the specs into a JSON file
|
2022-02-22 17:35:00 +01:00
|
|
|
with open("openapi.json", "w") as f:
|
2022-02-10 16:25:00 +01:00
|
|
|
json.dump(specs, f, indent=4)
|
2022-02-22 17:35:00 +01:00
|
|
|
|
|
|
|
# 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")
|