OpenAPITools / OpenAPITools/openapi-generator
[BUG][PYTHON] JSON serialization fails for UUID fields in generated Python
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
I am using the maven plugin openapi-generator-maven-plugin (python generator), to generate Python code that includes UUID fields. Since 7.15 version of this plugin, the to_json method of the generated python object containing an UUID field leads to this error: Object of type UUID is not JSON serializable error
There is an example to reproduce the issue
components:
schemas:
MyObject:
type: object
properties:
id:
type: string
format: uuid
from my_api.model.my_object import MyObject
import uuid
obj = MyObject(id=uuid.uuid4())
json_str = obj.to_json()
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 reproducing the issue with the provided OpenAPI schema through the openapi-generator-maven-plugin and inspect the generated Python model's to_json method. Trace how UUID values are passed to JSON serialization, then add coverage for the generated MyObject case and confirm that obj.to_json() succeeds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100