Repository navigation
fix: generate valid code when a path parameter with a default precedes one without - #1495
Open
saadkhantareen wants to merge 1 commit into
Open
saadkhantareen wants to merge 1 commit into
saadkhantareen wants to merge 1 commit into
Conversation
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
Generating a client for an endpoint whose path declares a parameter with a default before a parameter without one (for example
/test/{has_default}/{no_default}, wherehas_defaulthas a schema default) produced invalid Python:Python rejects this with
SyntaxError: Parameter without a default cannot follow a parameter with a default, so generation failed entirely.Changes
Endpoint.sort_parametersnow stable-sorts path parameters after ordering them by their position in the path, moving parameters that declare a default after those that do not. Path order is preserved within each group, so endpoints that already generated valid code are unchanged, and all internal calls pass path parameters by keyword.Tests
pytest tests/test_parser/test_openapi.py end_to_end_tests/functional_tests/generated_code_execution/test_path_parameters.py— 33 passed.pytest tests --basetemp=tests/tmp— 322 passed, 4 skipped.pytest end_to_end_tests/test_end_to_end.py end_to_end_tests/functional_tests --basetemp=tests/tmp— 136 passed; the 9 snapshot failures intest_end_to_end.pyoccur identically on unmodifiedmainand are unaffected by this change.no_default: int, has_default: str = "default_value".ruff checkandruff format --checkpass on the changed files;mypy openapi_python_client/parser/openapi.pyreports no issues.Fixes #1281