Datamodel-code-generator: TypeError when Enum is subclassed in generated code

Created on 9 Nov 2020  路  3Comments  路  Source: koxudaxi/datamodel-code-generator

Describe the bug
The generated code tries to subclass an Enum, which makes python raise TypeError. Seems to be related to the "AllOf" keyword. When the enclosing "AllOf" is removed, the generated code is without Enum-subclassing and it works as expected.

To Reproduce

Example schema:

{
  "openapi": "3.0.2",
  "components": {
    "schemas": {
      "ProcessingStatus": {
        "title": "ProcessingStatus",
        "enum": [
          "COMPLETED",
          "PENDING",
          "FAILED"
        ],
        "type": "string",
        "description": "The processing status"
      },
      "ProcessingTask": {
        "title": "ProcessingTask",
        "type": "object",
        "properties": {
          "processing_status": {
            "title": "Status of the task",
            "allOf": [
              {
                "$ref": "#/components/schemas/ProcessingStatus"
              }
            ],
            "default": "COMPLETED"
          }
        }
      }
    }
  }
}

Used commandline:

$ datamodel-codegen --input openapi_test.json --output models_test.py

Version:

  • OS: Win 10
  • Python version: 3.8.5
  • datamodel-code-generator version: 0.6.2
released

Most helpful comment

@koxudaxi
Thank you, much appreciated.

All 3 comments

@agrav
Thank you for creating this issue.
OK, I will fix it.

@agrav
I have released a new version as 0.6.4
This version ignores allOf when it has only an enum object.

@koxudaxi
Thank you, much appreciated.

Was this page helpful?
0 / 5 - 0 ratings