fix(proxy): cleandoc exception docstrings used in OpenAPI ERROR_RESPONSES - #29934
Draft
cursor[bot] wants to merge 1 commit into
Draft
fix(proxy): cleandoc exception docstrings used in OpenAPI ERROR_RESPONSES#29934cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
…NSES The Swagger error descriptions wired up in swagger_utils.ERROR_RESPONSES were taken straight from exception.__doc__, which preserves the leading whitespace from the Python source (4 spaces per body line for any multi-line docstring). openapi-typescript renders that into JSDoc verbatim, so when RateLimitError grew a real multi-line docstring in #27687, every regenerated schema.d.ts now has a different indentation than the file committed by #29885. CI's Check UI API Types Sync flips back and forth between rebases on any PR that doesn't touch schema.d.ts itself. Pass __doc__ through inspect.cleandoc so the description stored in the OpenAPI spec is dedented at the source. The committed schema.d.ts is exactly what gen:api now produces, so no schema regen is needed in this commit; future docstrings on litellm exceptions won't reintroduce the drift either. Inherited docstrings from openai/Exception are still ignored (we keep the existing __doc__-not-getdoc fallback to the class name) so the description of every other 4xx/5xx response stays the class name like 'AuthenticationError'. Co-authored-by: Krrish Dholakia <krrish-berri-2@users.noreply.github.com>
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Relevant issues
CI's
Check UI API Types Syncstarted failing on every PR rebased onto main right after #27687 + #29885 landed together; the autofix automation noticed it on hourly cron.Linear ticket
n/a (CI autofix)
Pre-Submission checklist
make test-unitScreenshots / Proof of Fix
Before the fix, regenerating
schema.d.tsfrom the live spec produced a 12-line diff against the file committed by #29885; runningnpm run gen:apiinui/litellm-dashboardwould surface this every time:After the fix, the same regen is a no-op:
Regression tests in
tests/test_litellm/proxy/common_utils/test_swagger_utils.py:Type
🐛 Bug Fix
Changes
swagger_utils.ERROR_RESPONSESwas wiringexception.__doc__straight into each Swagger response description. Python preserves the source-code indentation in__doc__, so any multi-line docstring shows up in the spec as\n Unified rate-limit error.\n\n Every rate-limit condition....openapi-typescriptthen writes that into JSDoc verbatim, which doubles the indentation inui/litellm-dashboard/src/lib/http/schema.d.ts.Until #27687, none of the litellm exception types in
LITELLM_EXCEPTION_TYPEShad real multi-line docstrings, so this was latent. #27687 added a 7-line docstring onRateLimitError, and #29885 (which runsgen:apiagainst the same docstring) committed aschema.d.tswhose indentation does not round-trip; every subsequent regen drifts and the sync gate fails.This PR routes
__doc__throughinspect.cleandocbefore it lands in the OpenAPI spec, so the description stored inopenapi.jsonis dedented at the source. The fallback toexception.__name__for exceptions without their own docstring is preserved (we keep__doc__, notinspect.getdoc, so we don't pick up the inheritedopenai.APIStatusError/Exceptionstrings that would replace 19 other 4xx/5xx descriptions). With the fix in place the committedschema.d.tsround-trips throughnpm run gen:apiunchanged.Tests:
_exception_descriptiondedents multi-line docstrings forRateLimitError_exception_descriptionfalls back to the class name when a subclass has no own__doc__(no inheritance leak)ERROR_RESPONSES[429]description starts withUnified rate-limit error.and contains no leading-4-space lines