OpenAPITools / OpenAPITools/openapi-generator

[BUG][PYTHON] JSON serialization fails for UUID fields in generated Python

Open
#22,063 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.