-
-
Notifications
You must be signed in to change notification settings - Fork 313
Fix datetime object handling in OpenAPI schema generation #1134
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
base: main
Are you sure you want to change the base?
Conversation
- 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
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
| # 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 |
There was a problem hiding this comment.
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?
|
Hey @Soroushsrd 👋 One more thing
Lint PR is failing as well |
|
Thank you for the comments. Will fix it ASAP |
|
Hi @Soroushsrd, some of the test for python 3.9 and 3.10 failing, can you fix them? |
| from robyn.types import JSONResponse | ||
|
|
||
|
|
||
| @dataclass |
There was a problem hiding this comment.
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)
|
😱 Found 1 issue. Time to roll up your sleeves! 😱 |
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:
datetime.datetimeanddatetime.datetypes in schema generationPR Checklist
Please ensure that:
Pre-Commit Instructions: