Skip to content

Commit 1cf8479

Browse files
author
Aabid Mohamed
authored
Merge branch 'main' into docs/split-responses-section
2 parents f5e0d2e + 4a43322 commit 1cf8479

6 files changed

Lines changed: 51 additions & 12 deletions

File tree

.github/workflows/ci.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
python-version: "3.11"
4444

4545
- name: Install uv
46-
uses: astral-sh/setup-uv@v8.3.0
46+
uses: astral-sh/setup-uv@v8.3.1
4747
with:
4848
enable-cache: true
4949

@@ -60,7 +60,7 @@ jobs:
6060
python-version: "3.11"
6161

6262
- name: Install uv
63-
uses: astral-sh/setup-uv@v8.3.0
63+
uses: astral-sh/setup-uv@v8.3.1
6464
with:
6565
enable-cache: true
6666

@@ -77,7 +77,7 @@ jobs:
7777
python-version: "3.11"
7878

7979
- name: Install uv
80-
uses: astral-sh/setup-uv@v8.3.0
80+
uses: astral-sh/setup-uv@v8.3.1
8181
with:
8282
enable-cache: true
8383

@@ -125,7 +125,7 @@ jobs:
125125
python-version: 3.14
126126

127127
- name: Install uv
128-
uses: astral-sh/setup-uv@v8.3.0
128+
uses: astral-sh/setup-uv@v8.3.1
129129
with:
130130
version: "0.6.12"
131131
enable-cache: true
@@ -161,7 +161,7 @@ jobs:
161161
python-version: 3.11
162162

163163
- name: Install uv
164-
uses: astral-sh/setup-uv@v8.3.0
164+
uses: astral-sh/setup-uv@v8.3.1
165165
with:
166166
enable-cache: true
167167

@@ -210,7 +210,7 @@ jobs:
210210
allow-prereleases: true
211211

212212
- name: Install uv
213-
uses: astral-sh/setup-uv@v8.3.0
213+
uses: astral-sh/setup-uv@v8.3.1
214214
with:
215215
enable-cache: true
216216

@@ -250,7 +250,7 @@ jobs:
250250
python-version: "3.12"
251251

252252
- name: Install uv
253-
uses: astral-sh/setup-uv@v8.3.0
253+
uses: astral-sh/setup-uv@v8.3.1
254254
with:
255255
enable-cache: true
256256

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
python-version: "3.12"
3737

3838
- name: Install uv
39-
uses: astral-sh/setup-uv@v8.3.0
39+
uses: astral-sh/setup-uv@v8.3.1
4040
with:
4141
version: "0.5.4"
4242
enable-cache: true

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
python-version: "3.12"
2323

2424
- name: Install uv
25-
uses: astral-sh/setup-uv@v8.3.0
25+
uses: astral-sh/setup-uv@v8.3.1
2626
with:
2727
version: "0.5.4"
2828
enable-cache: true

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
if: startsWith(inputs.os, 'windows')
5555

5656
- name: Install uv
57-
uses: astral-sh/setup-uv@v8.3.0
57+
uses: astral-sh/setup-uv@v8.3.1
5858
with:
5959
version: "0.8.8"
6060
enable-cache: true

litestar/_openapi/responses.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,19 @@
4242

4343
__all__ = ("create_responses_for_handler",)
4444

45-
CAPITAL_LETTERS_PATTERN = re.compile(r"(?=[A-Z])")
45+
WORD_BOUNDARY_PATTERN = re.compile(
46+
r"""
47+
(?<=[a-z0-9])(?=[A-Z]) # a lowercase letter or digit, followed by an uppercase letter
48+
|
49+
(?<=[A-Z])(?=[A-Z][a-z]) # an uppercase run, followed by a new capitalized word
50+
""",
51+
re.VERBOSE,
52+
)
4653

4754

4855
def pascal_case_to_text(string: str) -> str:
4956
"""Given a 'PascalCased' string, return its split form- 'Pascal Cased'."""
50-
return " ".join(re.split(CAPITAL_LETTERS_PATTERN, string)).strip()
57+
return " ".join(re.split(WORD_BOUNDARY_PATTERN, string)).strip()
5158

5259

5360
def create_cookie_schema(cookie: Cookie) -> Schema:

tests/unit/test_openapi/test_responses.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from litestar._openapi.responses import (
1616
ResponseFactory,
1717
create_error_responses,
18+
pascal_case_to_text,
1819
)
1920
from litestar._openapi.schema_generation.plugins import openapi_schema_plugins
2021
from litestar.datastructures import Cookie, ResponseHeader
@@ -151,6 +152,37 @@ class AlternativePetException(HTTPException):
151152
assert schema.type
152153

153154

155+
@pytest.mark.parametrize(
156+
("string", "expected"),
157+
[
158+
("PetException", "Pet Exception"),
159+
("InvalidAPIKeyError", "Invalid API Key Error"),
160+
("HTTPException", "HTTP Exception"),
161+
("ValidationException", "Validation Exception"),
162+
("API", "API"),
163+
("Error", "Error"),
164+
("error", "error"),
165+
("HTTP404Error", "HTTP404 Error"),
166+
("Base64Decoder", "Base64 Decoder"),
167+
("", ""),
168+
],
169+
)
170+
def test_pascal_case_to_text(string: str, expected: str) -> None:
171+
assert pascal_case_to_text(string) == expected
172+
173+
174+
def test_create_error_responses_preserves_acronyms_in_description() -> None:
175+
class InvalidAPIKeyError(HTTPException):
176+
status_code = 401
177+
178+
_, response = next(create_error_responses(exceptions=[InvalidAPIKeyError]))
179+
180+
assert response.content
181+
schema = response.content[MediaType.JSON].schema
182+
assert isinstance(schema, Schema)
183+
assert schema.description == "Invalid API Key Error"
184+
185+
154186
def test_create_error_responses_with_non_http_status_code() -> None:
155187
class HouseNotFoundError(HTTPException):
156188
status_code: int = 420

0 commit comments

Comments
 (0)