Add CI check that Flask routes and OpenAPI spec stay in sync#3440
Open
hasankhan wants to merge 1 commit into
Open
Add CI check that Flask routes and OpenAPI spec stay in sync#3440hasankhan wants to merge 1 commit into
hasankhan wants to merge 1 commit into
Conversation
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>
Contributor
|
@Suhaibinator cytal pls? |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a CI check that fails if
main.pyandspec.v1.ymldisagree 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.pyparses@app.routedecorators frommain.pyandpathsfromspec.v1.yml, strips the/v1prefix, normalizes path params positionally (so Flask's<string:name>matches the spec's{collectionName}), and diffs the two sets..github/workflows/spec-check.ymlruns it on every PR and push tomasterthat touchesmain.py,spec.v1.yml, or the checker itself.Verified locally
master(14 routes match).main.pywithout 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