Comments (9)
Just leaving this here in case you need a workaround. You can use Annotated[int, Parameter(default=12)]
to get the behavior you expect.
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])
from litestar.
Could you confirm that this is also true in 2.7.0?
from litestar.
Same result with fixed version 2.7.0
dependencies = [
"litestar[standard]==2.7.0"
]
from litestar.
Thanks!
from litestar.
I don't think this is a bug. The specification doesn't have a field to indicate a default value for parameters.
from litestar.
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 schema
which can have a default value.
Us not parsing the default properly is a bug.
from litestar.
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
}
],
...
from litestar.
This issue has been closed in #3280. The change will be included in the upcoming patch release.
from litestar.
A fix for this issue has been released in v2.8.0
from litestar.
Related Issues (20)
- Enhancement: Repository pattern interfaces HOT 1
- Enhancement: Kubernetes application health endpoints HOT 1
- Enhancement: Allow status code categories in route handlers responses
- Enhancement: Provide option to set DTOs for nested fields HOT 7
- Bug: mounted app path interferes with regular paths HOT 5
- Examples not shown when using DTO HOT 2
- Bug: LoggingMiddleware breaks static file serving
- Bug: Redirect is not allowed for a preflight request. HOT 2
- Bug: Enum OAS issues HOT 1
- Enhancement: email service provider integration HOT 3
- Enhancement: Context Managers as Dependencies HOT 1
- Enhancement: feat(monitoring): configurable path parameters cardinality
- Patching of click in rich-click via litestar cli breaks Typer cli apps HOT 4
- Bug: ASGI mounted at base root ("/") intercepts dynamic path params HOT 6
- Enhancement: add an option `logging_module` to `LoggingConfig` HOT 3
- Enhancement: Add class and funcion name to `ImproperlyConfiguredException`s HOT 4
- Docs: little typo in documentation HOT 1
- Bug: normal usage of route handler decorators causes deprecation warnings HOT 1
- Bug(SQLAlchemy Plugin): Generic responses are not getting serialized HOT 2
- Unexpected behavior from `module_to_os_path` HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from litestar.