datamodel-code-generator icon indicating copy to clipboard operation
datamodel-code-generator copied to clipboard

datamodel-codegen produces class with missing body parts

Open degenaro opened this issue 1 year ago • 0 comments

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

degenaro avatar Apr 03 '24 18:04 degenaro