OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Python] to_json function raise error on date type
Open
Nobody has claimed this yet.
Issue: Bug
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
[BUG] [Python] to_json function raise error on date type: TypeError: Object of type date is
not JSON serializable
openapi-generator version
7.4
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: API
description: API
version: 1.4.0
paths:
/create:
post:
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
responses:
"202":
description: OK
components:
schemas:
Pet:
type: object
properties:
asOfDate:
format: date
type: string
color:
type: string
Generation Details
Steps to reproduce
- generate sdk with the spec and version 7.4
- use the code below to test it
pet_dict = {
"color": "blue",
"asOfDate": "2020-03-03"
}
pet = SDK.Pet.from_json(json.dumps(pet_dict))
print(pet)
// error: Object of type date is
not JSON serializable
pet.to_json()
Related issues/PRs
Suggest a fix
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 with the generated Python SDK model's Pet.from_json and to_json behavior using the OpenAPI declaration and reproduction steps in the issue. Confirm that a Pet with an asOfDate date value can be serialized without the reported TypeError, and verify the resulting JSON output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100