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: set model response to NOT prefer alias #2150

Merged
merged 1 commit into from
Aug 12, 2023
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/path_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def create_path_item(
operation_ids: list[str] = []

request_schema_creator = SchemaCreator(create_examples, plugins, schemas, prefer_alias=True)
response_schema_creator = SchemaCreator(create_examples, plugins, schemas, prefer_alias=True)
response_schema_creator = SchemaCreator(create_examples, plugins, schemas, prefer_alias=False)
for http_method, handler_tuple in route.route_handler_map.items():
route_handler, _ = handler_tuple

Expand Down
15 changes: 11 additions & 4 deletions tests/unit/test_openapi/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from litestar.exceptions import ImproperlyConfiguredException
from litestar.openapi.config import OpenAPIConfig
from litestar.openapi.spec import Components, Example, OpenAPIHeader, OpenAPIType, Schema
from litestar.testing import TestClient

if TYPE_CHECKING:
from litestar.handlers.http_handlers import HTTPRouteHandler
Expand Down Expand Up @@ -62,19 +63,25 @@ def handler(data: RequestWithAlias) -> ResponseWithAlias:

assert app.openapi_schema
schemas = app.openapi_schema.to_schema()["components"]["schemas"]
request_key = "second"
assert schemas["RequestWithAlias"] == {
"properties": {"second": {"type": "string"}},
"properties": {request_key: {"type": "string"}},
"type": "object",
"required": ["second"],
"required": [request_key],
"title": "RequestWithAlias",
}
response_key = "first"
assert schemas["ResponseWithAlias"] == {
"properties": {"second": {"type": "string"}},
"properties": {response_key: {"type": "string"}},
"type": "object",
"required": ["second"],
"required": [response_key],
"title": "ResponseWithAlias",
}

with TestClient(app) as client:
response = client.post("/", json={request_key: "foo"})
assert response.json() == {response_key: "foo"}


def test_allows_customization_of_operation_id_creator() -> None:
def operation_id_creator(handler: "HTTPRouteHandler", _: Any, __: Any) -> str:
Expand Down