Coder Social home page Coder Social logo

Comments (10)

provinzkraut avatar provinzkraut commented on June 19, 2024 1

@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.

JacobCoffee avatar JacobCoffee commented on June 19, 2024

I think your MCVE got cut off :) and is missing some imports

from litestar.

robswc avatar robswc commented on June 19, 2024

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.

provinzkraut avatar provinzkraut commented on June 19, 2024

@robswc Can you describe what output you're expecting and what you're actually getting?

from litestar.

robswc avatar robswc commented on June 19, 2024

@robswc Can you describe what output you're expecting and what you're actually getting?

Will do!

image

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.

robswc avatar robswc commented on June 19, 2024

Also, for a bit more context, it looks like arguments passed to Body show on swagger.

image

Body(title="test", description="this comes through", ...

from litestar.

guacs avatar guacs commented on June 19, 2024

The reason for this is twofold.

  1. 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.
  2. 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.

robswc avatar robswc commented on June 19, 2024

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.

guacs avatar guacs commented on June 19, 2024

Unfortunately, I don't think it's possible at the moment.

from litestar.

robswc avatar robswc commented on June 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.