Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Description not set for UUID based path parameters in OpenAPI #3118

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion litestar/_openapi/schema_generation/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
Sequence: Schema(type=OpenAPIType.ARRAY),
Set: Schema(type=OpenAPIType.ARRAY),
Tuple: Schema(type=OpenAPIType.ARRAY),
UUID: Schema(type=OpenAPIType.STRING, format=OpenAPIFormat.UUID, description="Any UUID string"),
UUID: Schema(type=OpenAPIType.STRING, format=OpenAPIFormat.UUID),
bool: Schema(type=OpenAPIType.BOOLEAN),
bytearray: Schema(type=OpenAPIType.STRING),
bytes: Schema(type=OpenAPIType.STRING),
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_schema_generation() -> None:
"components": {
"schemas": {
"IdModel": {
"properties": {"id": {"type": "string", "format": "uuid", "description": "Any UUID string"}},
"properties": {"id": {"type": "string", "format": "uuid"}},
"type": "object",
"required": ["id"],
"title": "IdContainer",
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/test_openapi/test_parameters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import TYPE_CHECKING, List, Optional, Type, cast
from uuid import UUID
provinzkraut marked this conversation as resolved.
Show resolved Hide resolved

import pytest
from typing_extensions import Annotated
Expand Down Expand Up @@ -324,3 +325,21 @@ async def index(
assert response.json()["paths"]["/"]["get"]["parameters"][0]["examples"] == {
"text-example-1": {"summary": "example summary", "value": "example value"}
}


def test_uuid_path_description_generation() -> None:
cofin marked this conversation as resolved.
Show resolved Hide resolved
# https://github.com/litestar-org/litestar/issues/2967
@get("str/{id:str}")
async def str_path(id: Annotated[str, Parameter(description="String ID")]) -> str:
return id

@get("uuid/{id:uuid}")
async def uuid_path(id: Annotated[UUID, Parameter(description="UUID ID")]) -> UUID:
return id

with create_test_client(
[str_path, uuid_path], openapi_config=OpenAPIConfig(title="Test API", version="1.0.0")
) as client:
response = client.get("/schema/openapi.json")
assert response.json()["paths"]["/str/{id}"]["get"]["parameters"][0]["description"] == "String ID"
assert response.json()["paths"]["/uuid/{id}"]["get"]["parameters"][0]["description"] == "UUID ID"
Loading