Skip to content
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

[DOC] Auto-generate openapi.json #782

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 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
39 changes: 39 additions & 0 deletions .github/workflows/generate_api_docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: "Generate openapi.json"

env:
DEFAULT_PYTHON_VERSION: "3.10"
pavithraes marked this conversation as resolved.
Show resolved Hide resolved

on:
release:
types: [published]
push: # temporary, only for testing
branches:
- "gen-openapi-json"
pavithraes marked this conversation as resolved.
Show resolved Hide resolved
workflow_dispatch:

jobs:
update-openapi-json:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -el {0}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v3
with:
environment-file: conda-store-server/environment-dev.yaml

- name: Install conda-store-server
run: python -m pip install conda-store-server/.

- name: Run openapi.json generation script
run: python docusaurus-docs/scripts/generate_openapi_json.py

- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
commit-message: "[AUTO] Update openapi.json"
title: "[AUTO] Update openapi.json"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ conda-store-server/conda_store_server/server/static/conda-store-ui/
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# conda-store
conda-store.sqlite
32 changes: 32 additions & 0 deletions docusaurus-docs/scripts/generate_openapi_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import json
from pathlib import Path

from conda_store_server.server import app as server_app
from fastapi.openapi.utils import get_openapi


def gen_openapi_json():
cs_server = server_app.CondaStoreServer()
cs_server.initialize()
app = cs_server.init_fastapi_app()
filepath = Path(__file__).parent / "../static/openapi.json"

with open(filepath, "w") as f:
json.dump(
get_openapi(
title=app.title,
version=app.version,
openapi_version=app.openapi_version,
description=app.description,
routes=app.routes,
),
f,
)


def main():
gen_openapi_json()
pavithraes marked this conversation as resolved.
Show resolved Hide resolved


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions docusaurus-docs/static/openapi.json

Large diffs are not rendered by default.

Loading