add NO_OPENAPI env var to disable /openapi.json endpoint - #25547
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
| @@ -493,6 +493,7 @@ | |||
| ProxyUpdateSpend, | |||
| _cache_user_row, | |||
| _get_docs_url, | |||
| _get_openapi_url, | |||
26198f0 to
c4b53cd
Compare
Greptile SummaryAdds a Confidence Score: 5/5Safe to merge — straightforward, isolated feature following established patterns with no correctness issues. All four changed files are clean: the utility function mirrors No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/proxy/utils.py | Adds _get_openapi_url() following the exact same pattern as _get_docs_url and _get_redoc_url; no issues. |
| litellm/proxy/proxy_server.py | Imports and wires _get_openapi_url() into the FastAPI constructor alongside the existing docs_url and redoc_url hooks; correct module-level placement. |
| tests/test_litellm/proxy/test_utils.py | New test file using monkeypatch correctly; covers default and disabled cases. |
| docs/my-website/docs/proxy/config_settings.md | Adds NO_OPENAPI entry in the environment variable table in alphabetical order; accurate description. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[FastAPI app init] --> B["_get_openapi_url()"]
B --> C{NO_OPENAPI env var set\nand truthy?}
C -- Yes --> D["return None\n→ /openapi.json returns 404"]
C -- No --> E["return '/openapi.json'\n→ schema served normally"]
D --> F["FastAPI: openapi_url=None"]
E --> G["FastAPI: openapi_url='/openapi.json'"]
Reviews (2): Last reviewed commit: "add NO_OPENAPI env var to disable /opena..." | Re-trigger Greptile
| def test_get_openapi_url(env_vars, expected_url): | ||
| # Clear relevant environment variables | ||
| os.environ.pop("NO_OPENAPI", None) | ||
|
|
||
| # Set test environment variables | ||
| for key, value in env_vars.items(): | ||
| os.environ[key] = value | ||
|
|
||
| result = _get_openapi_url() | ||
| assert result == expected_url |
There was a problem hiding this comment.
Missing env var teardown causes test pollution
The test sets NO_OPENAPI=True in os.environ but never cleans it up after the parametrized case completes. Any subsequent test in the same pytest process that reads NO_OPENAPI will see the stale value. Use monkeypatch (pytest's built-in fixture) so the env var is automatically restored after each test.
| def test_get_openapi_url(env_vars, expected_url): | |
| # Clear relevant environment variables | |
| os.environ.pop("NO_OPENAPI", None) | |
| # Set test environment variables | |
| for key, value in env_vars.items(): | |
| os.environ[key] = value | |
| result = _get_openapi_url() | |
| assert result == expected_url | |
| def test_get_openapi_url(monkeypatch, env_vars, expected_url): | |
| # Clear relevant environment variables | |
| monkeypatch.delenv("NO_OPENAPI", raising=False) | |
| # Set test environment variables | |
| for key, value in env_vars.items(): | |
| monkeypatch.setenv(key, value) | |
| result = _get_openapi_url() | |
| assert result == expected_url |
| def _get_openapi_url() -> Optional[str]: | ||
| """ | ||
| Get the OpenAPI schema URL from the environment variables. | ||
|
|
||
| - If NO_OPENAPI is True, return None. | ||
| - Otherwise, default to "/openapi.json". | ||
| """ | ||
| if str_to_bool(os.getenv("NO_OPENAPI")) is True: | ||
| return None | ||
|
|
||
| return "/openapi.json" |
There was a problem hiding this comment.
No custom URL support unlike sibling functions
_get_docs_url and _get_redoc_url both accept a DOCS_URL / REDOC_URL env var that lets operators relocate the endpoint rather than only suppressing it. _get_openapi_url only supports suppression (NO_OPENAPI); there is no way to change the schema URL to a non-default path. This may be intentional, but for consistency consider adding an OPENAPI_URL env var check (same pattern as the existing helpers).
c4b53cd to
fae3a46
Compare
6723e7d
into
BerriAI:litellm_oss_staging_04_13_2026_p1
Relevant issues
Fixes 25538
Pre-Submission checklist
Note: I was a bit confused about where to put the tests. The checklist says tests belong in
tests/test_litellm, but all test coverage for similar features is intests/proxy_unit_tests/test_proxy_utils.py.tests/test_litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewCI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Type
🆕 New Feature
Changes
Adds a NO_OPENAPI environment variable (or similar) that sets openapi_url=None on the FastAPI app constructor, disabling the /openapi.json endpoint.