haystack/.github/utils/generate_openapi_specs.py
Sara Zan 96a538b182
Pylint (import related warnings) and REST API improvements (#2326)
* remove duplicate imports

* fix ungrouped-imports

* Fix wrong-import-position

* Fix unused-import

* pyproject.toml

* Working on wrong-import-order

* Solve wrong-import-order

* fix Pool import

* Move open_search_index_to_document_store and elasticsearch_index_to_document_store in elasticsearch.py

* remove Converter from modeling

* Fix mypy issues on adaptive_model.py

* create es_converter.py

* remove converter import

* change import path in tests

* Restructure REST API to not rely on global vars from search.apy and improve tests

* Fix openapi generator

* Move variable initialization

* Change type of FilterRequest.filters

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2022-04-12 16:41:05 +02:00

38 lines
1.2 KiB
Python

import json
from pathlib import Path
import os
import sys
import shutil
sys.path.append(".")
from rest_api.utils import get_openapi_specs, get_app, get_pipelines # pylint: disable=wrong-import-position
from haystack import __version__ # pylint: disable=wrong-import-position
REST_PATH = Path("./rest_api").absolute()
PIPELINE_PATH = str(REST_PATH / "pipeline" / "pipeline_empty.haystack-pipeline.yml")
APP_PATH = str(REST_PATH / "application.py")
DOCS_PATH = Path("./docs") / "_src" / "api" / "openapi"
os.environ["PIPELINE_YAML_PATH"] = PIPELINE_PATH
print(f"Loading OpenAPI specs from {APP_PATH} with pipeline at {PIPELINE_PATH}")
# To initialize the app and the pipelines
get_app()
get_pipelines()
# Generate the openapi specs
specs = get_openapi_specs()
# Dump the specs into a JSON file
with open(DOCS_PATH / "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(DOCS_PATH / "openapi.json", DOCS_PATH / f"openapi-{__version__}.json")