Comments (10)
@robswc If you want to create a PR go for it, and if you need feedback/assistance let us know here or on discord!
from litestar.
I think your MCVE got cut off :) and is missing some imports
from litestar.
That's fair! Here is a app.py I created, I'll also edit the original post.
"""Minimal Litestar application."""
from __future__ import annotations
from asyncio import sleep
from dataclasses import dataclass
from typing import Annotated
from litestar import Litestar, post
__all__ = ("async_hello_world")
from litestar.openapi.spec import Example
from litestar.params import Body
@dataclass
class User:
"""User dataclass."""
name: str
age: int
@post("/async")
async def async_hello_world(
data: Annotated[User, Body(title="test", examples=[Example(value={
"test": "test"})])]
) -> User: # noqa:
# UP006
"""Route Handler that outputs hello world."""
await sleep(0.1)
return data
app = Litestar(route_handlers=[async_hello_world])
from litestar.
@robswc Can you describe what output you're expecting and what you're actually getting?
from litestar.
@robswc Can you describe what output you're expecting and what you're actually getting?
Will do!
The image is what I'm getting.
What I'm trying to get is {"test": "test"}
to show as an example in swagger. With pydantic/FastAPI I'm able to set json_schema_extra
and examples
to get those to pull through.
The Body
seems to take an examples
argument but I'm not sure if I'm using that correctly.
from litestar.
Also, for a bit more context, it looks like arguments passed to Body
show on swagger.
Body(title="test", description="this comes through", ...
from litestar.
The reason for this is twofold.
- We aren't checking if examples are provided for any of the supported complex types i.e. dataclasses, structs or typeddicts. We are also not creating any examples if they have not been provided, but the user has asked to generate them.
- The examples need to be stored as part of the
content-type
for them to show for request bodies and not just in the schema as seen here. If providing examples in the schema is enough, then I'm not sure how the schema should be changed (it would be better to check how other frameworks like FastAPI is generating the schema).
from litestar.
Thanks for the detailed reply!
Are there any examples that you're aware of that show how to include examples in the request? Or is that not possible at the moment? I'm still getting familiar with the framework but enjoying it so far!
from litestar.
Unfortunately, I don't think it's possible at the moment.
from litestar.
Do you think it would be worth attempting a PR to add this in? Or would it be better handled by those with more domain knowledge?
from litestar.
Related Issues (20)
- Documentation Style Overhaul HOT 4
- Bug: Logger memory leak through threads HOT 3
- Bug: Exception handler leaks internal exceptions HOT 2
- Bug: declaring a RedisStore in the app triggers a 500 error in the 2nd set of parameters of a parametrized test HOT 13
- Request to Package litestar for Conda Distribution HOT 4
- Enhancement: Support "+json" suffixed media types per RFC 6839 HOT 4
- Bug: session middleware cookies always include segment number HOT 2
- Docs: Minor inconsistencies in description and example for "Applications" chapter HOT 3
- Enhancement: Session Middleware should create session id right away HOT 6
- Docs: Translate Them HOT 6
- Bug: CacheControlHeader not applying on create_static_files_router HOT 3
- Enhancement: Have OpenAPI Schema generation respect route handler ordering HOT 8
- Enhancement: Support Websockets on the async tests client
- Bug: Duplicate Response Schema name when using ManyToOne relationships HOT 1
- Bug: Certain `TypedDict` classes are not usable as `data` kwarg HOT 7
- Question: Using handler decorators on methods HOT 4
- Enhancement: Support all kwargs for `model_dump` in PydanticPlugin HOT 1
- Bug: OpenAPI schema error when using `pydantic.SecretStr` with a `pydantic.Field` HOT 5
- Bug: pydantic PrivateAttr fields are inspected for type hints HOT 10
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.