Skip to content
New issue

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

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

Already on GitHub? # to your account

Publish openAPI yaml in ci/cd #15549

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,22 @@ jobs:
- name: Run pre-commit
run: |
pre-commit run --show-diff-on-failure --color=always --all-files

- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch

- name: Generate OpenAPI YAML and commit
# Generate OpenAPI YAML for the UI
with:
token: ${{ secrets.PREFECT_CONTENTS_PR_RW }}
run: |
uv run --with 'pydantic>=2.9.0' ./scripts/generate_openapi_yml.py
git add src/prefect/_internal/openapi.yml
git commit -m "Update OpenAPI YAML" || echo "No changes to commit"
git push orign HEAD:${{ github.head_ref || github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.PREFECT_CONTENTS_PR_RW }}


34 changes: 34 additions & 0 deletions scripts/generate_openapi_yml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import inspect
import os

import yaml
from fastapi.openapi.utils import get_openapi

from prefect.server.api.server import create_api_app # type: ignore

app = create_api_app()

schema = get_openapi(title=app.title, version=app.version, routes=app.routes)

OPENAPI_YAML_PATH = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
"src",
"prefect",
"_internal",
"openapi.yml",
)

with open(OPENAPI_YAML_PATH, "w+") as file:
file.write(
inspect.cleandoc(
f"""
# ### {app.title}: Version {app.version}
# - This file is auto-generated by scripts/generate_openapi_yml.py
# - Do not edit this file directly.
"""
)
+ "\n"
)
yaml.dump(schema, file, sort_keys=False)

del app