Skip to content

DatetimeInterval Pydantic Model rendered incorrectly in FastAPI Generate Swagger Docs #113

@ciaransweet

Description

@ciaransweet

The DatetimeInterval Pydantic Model is rendered as an array<[string, string], any> in the generated SwaggerUI docs when using this type in stapi-fastapi

See its usage, pulled in via OrderPayload:

from stapi_pydantic import (
    OpportunityProperties,
    Order,
    OrderPayload,
    OrderStatusCode,
    Queryables,
)

from app.repositories import STAPIRepository
from app.schemas.stapi import OrderParameters as BaseOrderParameters


async def create_order(
    product_router: ProductRouter, payload: OrderPayload, request: Request
) -> ResultE[Order]:

create_order is then used in a Product and added via router.add_product(umbra.product)

On the SwaggerUI docs:

Image

Which alludes to:

"datetime": ["2025-01-01T00:00:00Z", "2025-12-31T23:59:59Z"]

When actually it should be:

"datetime": "2025-01-01T00:00:00Z/2025-12-31T23:59:59Z"

Looks like Swagger is picking up the tuple[AwareDatetime, AwareDatetime], first, which isn't actually the expected input.

My guess is the tests give some false hope here: https://github.com/stapi-spec/pystapi/blob/main/stapi-fastapi/tests/test_order.py#L49-L61

as they're using the model to pass to the endpoint, which will have the serialisation performed.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions