Repository navigation
fix(event_handler): emit the Path alias in the OpenAPI schema when it matches the route template - #8812
Merged
Conversation
… matches the route template
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #8812 +/- ##
========================================
Coverage 97.17% 97.17%
========================================
Files 323 323
Lines 16603 16606 +3
Branches 1503 1504 +1
========================================
+ Hits 16134 16137 +3
Misses 328 328
Partials 141 141 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.



Issue number:
closes #8803
Summary
Changes
Regression from #8630 in 3.39.0. Item 5 there made the OpenAPI path parameter name always the Python argument name, to cover
def f(user_id: Path(alias="userId"))on a/<user_id>route. That broke the opposite case,def f(snake_id: Path(alias="camelId"))on/<camelId>: the schema emittedsnake_id, which does not exist in the template, so the spec was invalid.The schema generator now receives the placeholder names of the route and picks the one that exists in the template: the alias by default, the argument name only when the alias is not a placeholder and the name is. Same order the runtime already uses to resolve the value, so schema and behaviour agree.
Tests cover the alias matching the template, the alias not matching (the #8630 case, unchanged), and the plain parameter, in the schema and through the validation middleware.
A PR with this same fix was opened yesterday and disappeared with its author's account before I could approve it, so this re-lands the approach.
User experience
Before, on 3.39.0 and 3.40.0:
After:
Runtime routing and validation answer the same in both cases; only the generated schema changes.
Verification
tests/functional/event_handlerandtests/unit/event_handler: 1287 passed.ruff,mypyclean. Ran the three scenarios side by side ondevelopand on this branch, schema and runtime: only the alias case changes, and only in the schema. The xenon rank E onget_openapi_schemais pre-existing ondevelopand untouched here. Written with an AI assistant; I ran everything above myself.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.