Skip to content

Add CI check that Flask routes and OpenAPI spec stay in sync#3440

Open
hasankhan wants to merge 1 commit into
masterfrom
add-spec-drift-check
Open

Add CI check that Flask routes and OpenAPI spec stay in sync#3440
hasankhan wants to merge 1 commit into
masterfrom
add-spec-drift-check

Conversation

@hasankhan

Copy link
Copy Markdown
Collaborator

Summary

Adds a CI check that fails if main.py and spec.v1.yml disagree on which endpoints exist. This prevents the OpenAPI spec (which powers https://sunnah.stoplight.io/docs/api/) from silently drifting out of sync with the actual API.

How it works

  • scripts/validate_spec.py parses @app.route decorators from main.py and paths from spec.v1.yml, strips the /v1 prefix, normalizes path params positionally (so Flask's <string:name> matches the spec's {collectionName}), and diffs the two sets.
  • .github/workflows/spec-check.yml runs it on every PR and push to master that touches main.py, spec.v1.yml, or the checker itself.

Verified locally

  • Passes on master (14 routes match).
  • Fails cleanly when a route is added to main.py without a spec entry (and vice versa).

Notes

This only validates that path sets match. It does not check request/response schemas or query params - those would require a heavier approach (spec-first codegen or a runtime-generated spec via apispec/flask-smorest). The path-level check catches the most common drift (someone adds a new endpoint and forgets the spec) with minimal ceremony.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

Adds scripts/validate_spec.py which parses @app.route decorators in
main.py and paths in spec.v1.yml, normalizes path params positionally,
and fails if either side has an endpoint the other lacks.

Adds .github/workflows/spec-check.yml which runs the validator on every
PR and push to master that touches main.py or spec.v1.yml.

This makes it impossible to merge a new/changed API endpoint without
updating the spec that Stoplight publishes at
https://sunnah.stoplight.io/docs/api/.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ahadith

ahadith commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

@Suhaibinator cytal pls?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants