openapi-generators / openapi-generators/openapi-python-client
date-time is not formatted correctly
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2k
- Forks
- 293
- Avg merge
- 34m
- Merged PRs (30d)
- 1
Description
Describe the bug
OpenAPI date-time fields are generated using datetime.datetime.isoformat and don't comply with OpenAPI spec / RFC3339
OpenAPI Spec File
/api/example:
get:
tags:
- "example"
operationId: example-get
summary: "summary removed"
description: ""
parameters:
- in: query
name: "start"
description: "desciption removed"
required: true
schema:
type: string
format: date-time
example: '2020-07-21T17:32:28Z'
- in: query
name: "end"
description: "desciption removed"
required: true
schema:
type: string
format: date-time
example: '2020-07-21T17:32:28Z'
Desktop:
- OS: Windows 11
- Python Version: 3.9.13
- openapi-python-client version 0.15.1
Additional context
Client code generated using openapi-python-client version 0.15.1 parses datetime.datetime objects and uses .isoformat() function to convert these to strings. This produces timestamp strings non-compliant with OpenAPI spec (https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#data-types). According to spec timestamps should look like this:
2023-08-23T13:26:16Z
Instead they look like this:
2023-08-23T12:26:16.979067
I have a server that rejects these as invalid timestamps. I can patch the client manually after generation, but I thought it would be beneficial to submit a bug report.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the generated client request serialization that handles datetime.datetime values and calls isoformat(). Compare its output with the RFC3339/OpenAPI examples in the issue, then run or add coverage for date-time query parameters. Done means generated timestamps are accepted as compliant date-time values by the reported server.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100