-
-
Notifications
You must be signed in to change notification settings - Fork 374
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
Bug: default not generated for query parameter in openapi spec. #3278
Comments
Could you confirm that this is also true in 2.7.0? |
Same result with fixed version 2.7.0 dependencies = [
"litestar[standard]==2.7.0"
] |
Thanks! |
I don't think this is a bug. The specification doesn't have a field to indicate a default value for parameters. |
Sorry about that. I was completely wrong. While it's correct that the parameter object as per the spec doesn't allow for defaults, it does allow for a Us not parsing the default properly is a bug. |
Just leaving this here in case you need a workaround. You can use from typing_extensions import Annotated
from litestar import Litestar, get
from litestar.params import Parameter
@get(path="query_default")
async def query_default(foo: Annotated[int, Parameter(default=12)]) -> None:
return
app = Litestar(route_handlers=[query_default]) |
Thanks for the workaround. I added the working schema snippet for completeness ...
"paths": {
"/query_default": {
"get": {
"summary": "QueryDefault",
"operationId": "QueryDefaultQueryDefault",
"parameters": [
{
"name": "foo",
"in": "query",
"schema": {
"type": "integer",
"default": 12
},
"required": false,
"deprecated": false,
"allowEmptyValue": false,
"allowReserved": false
}
],
... |
This issue has been closed in #3280. The change will be included in the upcoming patch release. |
A fix for this issue has been released in v2.8.0 |
Description
Hi,
The default of a query parameter is not properly generated when creating the openapi specification. See MVCE down below.
The generated specification looks like this:
where the default is missing in the schema property.
URL to code causing the issue
No response
MCVE
Steps to reproduce
No response
Screenshots
No response
Logs
No response
Litestar Version
Version 2.7.1
Platform
Note
While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.
Check out all issues funded or available for funding on our Polar.sh dashboard
The text was updated successfully, but these errors were encountered: