fix(openapi): skip non-numeric response keys in generate_return_doc#6175
Open
garyzava wants to merge 1 commit into
Open
fix(openapi): skip non-numeric response keys in generate_return_doc#6175garyzava wants to merge 1 commit into
garyzava wants to merge 1 commit into
Conversation
PydocHelper.generate_return_doc sorted the responses with
int(item[0]), which raises ValueError: invalid literal for int() with
base 10 on valid OpenAPI response keys that are not numeric status
codes, such as 'default' and range patterns like '2XX'/'4XX'.
Skip non-numeric keys in the sort. The next statement already keeps
only keys starting with '2' that have content, so dropping non-numeric
keys changes no valid behavior and just avoids the crash. This mirrors
operation_parser, which filters startswith('2') before using the keys.
Adds regression tests for a 'default' key, a range key, and a
responses dict with only non-numeric keys (returns '').
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
PydocHelper.generate_return_docsorts the OpenAPI responses withint(item[0]), which crashes withValueError: invalid literal for int() with base 10on valid non-numeric response keys likedefaultor range patterns(
2XX,4XX). This skips non-numeric keys in the sort so a tool can begenerated from such specs.
Fixes #6174
What changed
src/google/adk/tools/openapi_tool/common/common.py- exclude non-numerickeys from the sort in
generate_return_doc.tests/unittests/tools/openapi_tool/common/test_common.py- add regressiontests for a
defaultkey, a range key, and a responses dict with onlynon-numeric keys.
Why
The line after the sort already keeps only responses whose key starts with
2and that have content, so non-numeric keys (
default,1XX-5XX) are neverused anyway. Dropping them from the sort removes the crash without changing any
valid behavior. This matches
operation_parser, which filtersstartswith('2')before using the keys.
How I tested
The three new tests fail before the fix with
ValueError: invalid literal for int() with base 10: 'default'(and'4XX')and pass after.
pyinkandisortreport no changes on both files.Backward compatibility
No API change. Specs with only numeric response keys behave exactly as before;
specs with
default/range keys now work instead of crashing.