Skip to content

Dataclass generation does not include specified string format like uuid #1784

@maddin1991

Description

@maddin1991

Describe the bug
When i generate my models as dataclass the generater does not consider string formats like uuid, date ... The output is just of type string which is different when i generate pydantic models.

To Reproduce

Example schema:

{
  "openapi": "3.0.3",
  "components": {
    "schemas": {
      "Input": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id"],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          }
        }
      }
    }
  }
}

The generated result:

from __future__ import annotations
from dataclasses import dataclass


@dataclass
class Input:
    id: str

Used commandline:

$ datamodel-codegen --input ../api/openapi.json --output test.py --output-model-type dataclasses.dataclass

Expected behavior
I would expect that the id type is of type UUID like when i generate as pydantic:

from __future__ import annotations
from uuid import UUID
from pydantic import BaseModel, ConfigDict


class Input(BaseModel):
    model_config = ConfigDict(
        extra='forbid',
    )
    id: UUID

Version:

  • OS: win10
  • Python version: 3.11.2
  • datamodel-code-generator version: 0.25.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions