FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: add GH workflow to generate openapi schema by Faraz32123 · Pull Request #39025 · openedx/openedx-platform · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .yml  (1) All 2 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
101 changes: 101 additions & 0 deletions .github/workflows/generate_openapi_schemas.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# generate_openapi_schemas.yml
#
# Purpose: Generate OpenAPI schemas for the LMS and CMS using drf-spectacular,
# then open a pull request if either schema changed. The generated schema files
# are consumed by the openedx-platform-sdk repo's regen_sdk.sh script to keep
# the SDK in sync with the platform's tagged API views.

name: Generate OpenAPI Schemas

permissions:
contents: write
pull-requests: write

on:
workflow_dispatch:

schedule:
# Regenerate and commit the full OpenAPI schemas every Monday at 09:00 UTC.
- cron: "0 9 * * 1"

jobs:
generate-schemas:
runs-on: ubuntu-latest

steps:
- name: Check out repository
Comment thread
feanil marked this conversation as resolved.
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

- name: Install uv
uses: astral-sh/setup-uv@bec219d24cd3e171d82865faccec33120bb574f4 # v10.1.0
with:
enable-cache: true

# `default-groups = []` in pyproject.toml means a bare `uv sync` installs
# no groups at all, which leaves out ora2 and makes both schema steps fail
# with ModuleNotFoundError. `docs` includes `bundled`, which carries the
# bundled XBlocks — the same set .readthedocs.yaml and the other workflows
# install.
- name: Install dependencies
run: uv sync --no-default-groups --group docs --frozen

# `docs.docs_settings` is what `make swagger` uses: it applies the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This comment describes #39108, not master. Without it SPECTACULAR_SETTINGS is the default at lms/envs/common.py:2156 and lms_api_filter keeps only /api/enrollment/v\d+/, so this step overwrites the published LMS reference with the enrollment-only subset.

Note the dependency in the description and land #39108 first. On top of it the step is correct: 481 paths against the 293 committed.

# unfiltered /api-docs configuration instead of the narrow, SDK-facing
# schema that SPECTACULAR_SETTINGS carries by default. Without it this
# step would overwrite the published LMS reference with the
# enrollment-only subset.
#
# NOTE: docs_settings only carries that unfiltered configuration as of
# https://github.com/openedx/openedx-platform/pull/39108, which must merge
# before this workflow runs.
- name: Generate LMS OpenAPI schema
run: |
DJANGO_SETTINGS_MODULE=docs.docs_settings \
uv run python manage.py lms spectacular --file docs/lms-openapi.yaml

# Studio has no docs_settings equivalent. `manage.py cms` defaults to
# cms.envs.devstack, which imports production.py and so requires a
# CMS_CFG file that does not exist in CI — settings raise
# ImproperlyConfigured before the command is even registered.
# cms.envs.development needs no such file. Its schema is the Authoring
# API's contentstore-scoped surface, the same one Studio publishes at
# /authoring-api/schema/.
- name: Generate CMS OpenAPI schema
run: |
DJANGO_SETTINGS_MODULE=cms.envs.development \
uv run python manage.py cms spectacular --file docs/cms-openapi.yaml

Comment thread
feanil marked this conversation as resolved.
- name: Open pull request if schemas changed
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8
with:
branch: chore/update-openapi-schemas
# Without a suffix, a run that happens while the previous PR is
# still open pushes onto that same branch. Matches
# compile-python-requirements.yml and upgrade-one-python-dependency.yml.
branch-suffix: short-commit-hash
commit-message: |
chore: regenerate OpenAPI schemas

Commit generated by workflow `${{ github.workflow_ref }}`
title: 'chore: update OpenAPI schemas for SDK generation'
team-reviewers: wg-maintenance-openedx-platform-oncall
body: |
## Auto-generated OpenAPI schema update

PR generated by workflow `${{ github.workflow_ref }}`.
It contains regenerated `docs/lms-openapi.yaml` and/or `docs/cms-openapi.yaml`
files reflecting the latest state of the platform's API views.

`docs/lms-openapi.yaml` is the full LMS API surface — the same schema
`make swagger` produces, which the docs build publishes.
`docs/cms-openapi.yaml` is Studio's tagged schema.

Both are consumed by the
[openedx-platform-sdk](https://github.com/edly-io/openedx-platform-sdk)
repository's `regen_sdk.sh`, which filters them down to the tagged
operations it generates a client for.

**Do not edit these files by hand** — they will be overwritten on the next run.
add-paths: |
docs/lms-openapi.yaml
docs/cms-openapi.yaml
14 changes: 14 additions & 0 deletions cms/envs/common.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,20 @@ def _should_send_xblock_events(settings):
# This affects the Authoring API swagger docs but not the legacy swagger docs under /api-docs/.
REST_FRAMEWORK['DEFAULT_SCHEMA_CLASS'] = 'drf_spectacular.openapi.AutoSchema' # noqa: F405

# Identity of the generated Authoring API schema. The full configuration —
# endpoint filtering, path prefixes and SERVERS — lives in devstack.py and
# production.py, because SERVERS depends on CMS_BASE and AUTHORING_API_URL,
# which are only populated there. These three fields do not, so they are
# defined here to give any settings module that does not define its own
# SPECTACULAR_SETTINGS (notably cms.envs.development, used to generate the
# committed schema in CI) a titled, versioned document rather than
# drf-spectacular's empty-title, 0.0.0 default.
SPECTACULAR_SETTINGS = {
'TITLE': 'Authoring API',
'DESCRIPTION': 'Experimental API to edit xblocks and course content.',
'VERSION': '0.1.0',
}

################### Studio Search (beta), using Meilisearch ###################

# Enable Studio search features (powered by Meilisearch) (beta, off by default)
Expand Down
Loading

Back | FazBrowse Home | New Git URL