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

Define BaseClass for each data object

Open adaamz opened this issue 3 years ago • 0 comments

Is your feature request related to a problem? Please describe. My problem is that for first level data structures I would like to define additional properties defined in base class (not in schema definition as it is kinda internal), while for internal structures of that first level structure should be child of standard pydantic.BaseModel.

Describe the solution you'd like If it would be somehow deducted by generator it would be nice.

Describe alternatives you've considered If I have to define it by myself in schema definitions it's probably acceptable as well.

paths:
  asdf:
    parameters:
      $ref: "#/components/schemas/Asdf"

components:
  schemas:
    Asdf:
      type: object
      required: [abc]
      properties:
        abc:
          $ref: "#/components/schemas/InternalDataStructureAbc"

    InternalDataStructureAbc:
      type: object
      required: [a]
      properties:
        a:
          type: integer

should be generated to

from pydantic import BaseModel
from my_project import MyBaseClass

class Asdf(MyBaseClass):
  abc: InternalDataStructureAbc

class InternalDataStructureAbc(BaseModel):
  a: int

adaamz avatar Nov 19 '21 10:11 adaamz