Skip to content

♻️Storage API specs are now autogenerated 🚨 #4413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,992 changes: 1,077 additions & 915 deletions api/specs/storage/openapi.yaml

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions api/specs/storage/scripts/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

.PHONY: _check_venv_active
_check_venv_active:
# Checking whether virtual environment was activated
@python3 -c "import sys; assert sys.base_prefix!=sys.prefix"


.PHONY: install
install: _check_venv_active
@cd ./../../../../services/storage && make install-dev && cd -
pip install -r requirements.txt


.PHONY: all
all: _check_venv_active
@for file in *.py; do \
python $$file; \
done
38 changes: 38 additions & 0 deletions api/specs/storage/scripts/_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
""" Common utils for OAS script generators
"""

import sys
from pathlib import Path

import yaml
from fastapi import FastAPI
from servicelib.fastapi.openapi import override_fastapi_openapi_method

CURRENT_DIR = Path(sys.argv[0] if __name__ == "__main__" else __file__).resolve().parent


def create_openapi_specs(
app: FastAPI, file_path: Path, *, drop_fastapi_default_422: bool = True
):
override_fastapi_openapi_method(app)
openapi = app.openapi()

schemas = openapi["components"]["schemas"]
for section in ("HTTPValidationError", "ValidationError"):
schemas.pop(section)

# Removes default response 422
if drop_fastapi_default_422:
for _, method_item in openapi.get("paths", {}).items():
for _, param in method_item.items():
# NOTE: If description is like this,
# it assumes it is the default HTTPValidationError from fastapi
if (e422 := param.get("responses", {}).get("422", None)) and e422.get(
"description"
) == "Validation Error":
param.get("responses", {}).pop("422", None)

with file_path.open("wt") as fh:
yaml.safe_dump(openapi, fh, indent=1, sort_keys=False)

print("Saved OAS to", file_path)
4 changes: 4 additions & 0 deletions api/specs/storage/scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Extra reqs, besides webserver's

fastapi
jsonref
Loading