Skip to content

datamodel-codegen produces class with missing body parts #1901

@degenaro

Description

@degenaro

Describe the bug

Within the OSCAL schema is:

"EmailAddressDatatype" : 
   { "description" : "An email address string formatted according to RFC 6531.",
    "allOf" : 
    [ 
     { "$ref" : "#/definitions/StringDatatype" },
     
     { "type" : "string",
      "format" : "email",
      "pattern" : "^.+@.+$" } ] },

An empty body is produced by datamodel-codegen:

class EmailAddressDatatype(OscalBaseModel):
    """
    An email address string formatted according to RFC 6531.
    """

To Reproduce

  1. download OSCAL schemas from here https://github.com/usnistgov/OSCAL/releases/tag/v1.1.2
  2. run datamodel-codegen (shown below)

Example schema (snippet):

"EmailAddressDatatype" : 
   { "description" : "An email address string formatted according to RFC 6531.",
    "allOf" : 
    [ 
     { "$ref" : "#/definitions/StringDatatype" },
     
     { "type" : "string",
      "format" : "email",
      "pattern" : "^.+@.+$" } ] },

Follow link above for full schema.

Used commandline:

datamodel-codegen --disable-timestamp --disable-appending-item-suffix --use-schema-description --input-file-type jsonschema --input release-1.1.2-schemas/oscal_assessment-plan_schema.json --base-class trestle.core.base_model.OscalBaseModel --output trestle/oscal/tmp/assessment_plan.py

Expected behavior
The generated code body should not be empty, but rather contain that which is found in the json schema.

Version:

  • OS: Red Hat Enterprise Linux release 8.9 (Ootpa)
  • Python version: 3.9.9
  • datamodel-code-generator version: 0.25.5

Additional context
NA

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions