Closed foxpluto closed 1 year ago
Hi @foxpluto Thank You for reporting this issue, it is definitely a bug. It's happening because:
datetime
(unlike JSON parsing standard)json.dumps
method to serialize, which is in my opinion silly, throwing exception for common data types like UUID
and datetime
and other built-in types like dataclass
, etc.Good news: I even created in another library a method to avoid this kind of scenario, so to fix the error I would only need to replace the built-in json.dumps
with essentials.json.dumps
.
It uses a more user-friendly JSONEncoder class that handles those types.
Wonderful !!! I'll wait the fix to test it.
Thanks, S.
no ETA for this fix?
Sorry to bother...
Hi @foxpluto Sorry for taking longer than I promised at first, in the last weeks I was focused again on my web framework.
I fixed the bug and published a new version of the library where the bug happens 1.0.6. You can upgrade the essentials-openapi
dependency and the error has been resolved.
However, while writing tests and the fix, I also realized that maintaining the exact format of the datetime as in the examples is not obvious because datetimes are parsed automatically by YAML, then serialized using a certain format for JSON (the built-in json.dumps
throws exception probably exactly for this reason, that the desired serialization format for dates and times is not obvious).
To maintain the exact format you set for your examples, like 2022-08-17T18:00:00Z
, you have two options:
- description: Start time stamp of the returned data interval
- example: 2022-08-17T18:00:00Z
+ example: '2022-08-17T18:00:00Z'
in: query
name: fromInstant
required: false
schema:
format: date-time
type: string
OPENAPI_DATETIME_FORMAT="{YOUR_DESIRED_FORMAT_FOR_DATETIME_strftime}"
. This is something I added to 1.0.6
.Wonderful !!!
At least I have my API documentation in order on my site. I have used your second option with:
OPENAPI_DATETIME_FORMAT="%Y%m%dT%H%M%S.%fZ"
And works perfectly.
Thanks
You're welcome 😄 I leave this issue open to recall about documenting this feature, when I get the time. Now I'm still dedicating time to my web framework.
I have a quite long openapi file with a lot of date-time like this one:
but I have this error:
Is this a bug?
Regards, S.