Comments (8)
@tuukkamustonen thanks for the writeup!
-
I agree that the generation of the examples for the errors should be affected by the value of
create_examples
, however making that change currently may be considered a breaking change. We could create another flag to control the example generation of error responses, but I'm reluctant to add yet another flag. We should definitely fix this for v3 though. -
If the examples are being created for the response models schemas by default, then it's definitely a bug.
-
Tuning the example generation for the
Parameter
sounds good to me since we already have it forResponseSpec
and it'll maintain that consistency that way. -
The generation of examples in both OpenAPI and JSON schema is something that needs to be fixed as well. There seems to be some issues in what we generate due to which the examples are not being rendered correctly in some cases as in #3076. This isn't the first time issues regarding rendering of the examples is happening, so I think we have to properly look at how the examples are supposed to be generated as per the OpenAPI 3.0 spec and make the changes accordingly. I think #3128 might fix some of it.
-
For the defining of examples in pydantic models themselves, I agree that the plugin should be checking the config dictionary. Though, I'm not sure about
msgspec
,dataclasses
andTypedDict
since, as far as I know, there's no official way to that. For those cases, I think users will have to rely on usingExample
instead.
Let me know what you think about all this and I think we could create different issues for each of them so we can track them separately.
from litestar.
@guacs I think you're right. Examples are not generated for the responses as I argued. My bad. I'll write it off the list.
from litestar.
making that change currently may be considered a breaking change
could we use experimental features to backport?
from litestar.
making that change currently may be considered a breaking change
could we use experimental features to backport?
We could, but I'm not sure if the feature brings enough of a benefit to have to use a feature flag (and the associated complexity) for it.
from litestar.
Examples are generated for response models
@tuukkamustonen I wasn't able to reproduce this with the following:
from __future__ import annotations
from dataclasses import dataclass
from litestar import get
from litestar.app import Litestar
@dataclass
class Foo:
foo: int
@get("/")
async def get_foo() -> Foo:
...
@get("/favicon.ico")
async def you_cant_have_it() -> None:
return
app = Litestar([get_foo, you_cant_have_it], debug=True)
from litestar.
- For the defining of examples in pydantic models themselves, I agree that the plugin should be checking the config dictionary. Though, I'm not sure about
msgspec
,dataclasses
andTypedDict
since, as far as I know, there's no official way to that. For those cases, I think users will have to rely on usingExample
instead.
That's fair. I'm using Pydantic so for me supporting only Pydantic would suffice 😄 Though, I think in general it's a good feature to be able to define the examples within in the models (less clutter for the handler declarations). Yeah, maybe not for TypedDicts or dataclasses, but looks like at least Msgspec supports generating JSON schema so maybe for that, too.
I assume there's a technical blocker for that, but couldn't you just use the JSON schema that those libraries generate, when such support is available? And retain custom support for just those that don't, ie. TypedDicts and dataclasses(?)
I wasn't able to reproduce this with the following:
Okay, I'll check (slowly, we just moved to a new address and apartment is full of boxes...)
from litestar.
I assume there's a technical blocker for that, but couldn't you just use the JSON schema that those libraries generate, when such support is available? And retain custom support for just those that don't, ie. TypedDicts and dataclasses(?)
One reason to not use them is consistency. Being able to swap from e.g. a dataclass to a Pydantic model to a msgspec Struct without the OpenAPI schema changing is a valuable feature to have, especially if you're not only using the schema for documentation but e.g. to generate clients or downstream typing from.
Another reason would be richness of the generated schema. Because Litetar has more context information, e.g. examples, we can generate richer schemas.
And a last reason is that we often generate more specific schemas than the ones provided by the libraries themselves.
from litestar.
Another reason would be richness of the generated schema. Because Litetar has more context information, e.g. examples, we can generate richer schemas.
Anything else than examples
?
more specific schemas
And an example of this...?
from litestar.
Related Issues (20)
- DTO backend does not transferring mappings with nested models HOT 9
- Bug: SerializationException when running modeling-and-features demo from docs HOT 3
- Bug: Can't convert sqlalchemy model to pydantic model which is inherited from BaseModel HOT 1
- Enhancement: Add Pydantic's error dictionary to ValidationException's extra dict
- Enhancement: make `SessionMiddleware` return custom types HOT 3
- Bug: OpenAPI docs fail to generate with certain validators and pydantic v1 HOT 3
- Bug: Multi-body response incompatible with LoggingMiddleware HOT 2
- Bug: test failures
- Bug: `return_dto` is silently ignored if return data type does not match DTO definition HOT 1
- Bug: Test error
- Enhancement: add `default_json_serializer` to `__all__` in `litestar.logging.config`
- Docs: Migrating to Litestar from Django HOT 1
- Decoupled, transactional communication of domain events and commands
- Docs: Support for domain driven designs
- 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 4
- Examples not shown when using DTO HOT 1
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.