Skip to content

Conversation

@Soroushsrd
Copy link

Description

This PR fixes #1124

Summary

This PR fixes the OpenAPI schema generation for endpoints that return datetime objects. Previously, the application would fail to start with an AttributeError when attempting to generate OpenAPI documentation for endpoints returning datetime.datetime or datetime.date objects.

Changes made:

  • Added special handling for datetime.datetime and datetime.date types in schema generation
  • Added proper OpenAPI schema type ("string") and format ("date-time"/"date") for datetime objects
  • Added unit tests for datetime schema generation

PR Checklist

Please ensure that:

  • The PR contains a descriptive title
  • The PR contains a descriptive summary of the changes
  • You build and test your changes before submitting a PR.
  • You have added relevant documentation
  • You have added relevant tests. We prefer integration tests wherever possible

Pre-Commit Instructions:

- Add special handling for datetime.datetime and datetime.date types
- Add schema generation tests for datetime types
- Fix AttributeError when generating schema for datetime return types

Fixes sparckles#1124
@vercel
Copy link

vercel bot commented Mar 5, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
robyn ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 5, 2025 4:54pm

# should check for Optional type first
if param_type.__module__ == "typing":
properties["anyOf"] = [{"type": self.get_openapi_type(param_type.__args__[0])}, {"type": "null"}]
from typing import Optional, Union
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Soroushsrd , thanks for the PR but we can move the imports to the top of the file, right?

@sansyrox
Copy link
Member

sansyrox commented Mar 6, 2025

Hey @Soroushsrd 👋

One more thing

Lint PR / lint (pull_request)Failing after 1m

Lint PR is failing as well

@Soroushsrd
Copy link
Author

Thank you for the comments. Will fix it ASAP

@tavallaie
Copy link
Contributor

Hi @Soroushsrd, some of the test for python 3.9 and 3.10 failing, can you fix them?

from robyn.types import JSONResponse


@dataclass
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using @DataClass decorator with a TypedDict base class (JSONResponse) is incorrect and will cause runtime issues. TypedDict and dataclass are incompatible - TypedDict is for dictionary-like objects while dataclass is for class instances. Remove the @DataClass decorator and properly define DateResponseModel as a TypedDict class. This will cause serialization errors when the OpenAPI schema tries to process the response.


React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

@recurseml
Copy link

recurseml bot commented May 27, 2025

😱 Found 1 issue. Time to roll up your sleeves! 😱

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error with datetime object as endpoint return

3 participants