Skip to content
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(OpenAPI): Schema generation doesn't resolve signature types for "nested" objects #3650

Open
4 tasks
floxay opened this issue Aug 2, 2024 · 0 comments
Open
4 tasks
Labels
Bug 🐛 This is something that is not working as expected OpenAPI This is related to our OpenAPI schema

Comments

@floxay
Copy link
Contributor

floxay commented Aug 2, 2024

Description

OpenAPI schema generation fails if it encounters a "nested" object with a type which is not available at runtime but could be resolved using signature types/namespaces.

URL to code causing the issue

No response

MCVE

main.py

from litestar import Litestar, get

from external_module import Item
from schemas import ItemContainer

@get(sync_to_thread=False, signature_namespace={"Item": Item})
def handler() -> ItemContainer:
    return ItemContainer(items=[])

app = Litestar(
    route_handlers=[handler],
    signature_types=(Item,),
    debug=True,
)

schemas.py

from __future__ import annotations

from dataclasses import dataclass

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from external_module import Item

@dataclass
class ItemContainer:
    items: list[Item]

external_module.py

from dataclasses import dataclass

@dataclass
class Item:
    foo: str = "bar"

Steps to reproduce

1. Run the above code
2. See error at `http://127.0.0.1:8000/schema` (`name 'Item' is not defined`)
3. `http://127.0.0.1:8000` still works.

Screenshots

No response

Logs

No response

Litestar Version

2.10.0

Platform

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)

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

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
  • This, along with engagement in the community, helps us know which features are a priority to our users.
Fund with Polar
@floxay floxay added the Bug 🐛 This is something that is not working as expected label Aug 2, 2024
@JacobCoffee JacobCoffee added the OpenAPI This is related to our OpenAPI schema label Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 This is something that is not working as expected OpenAPI This is related to our OpenAPI schema
Projects
None yet
Development

No branches or pull requests

2 participants