Skip to content

Generated Models Don't Inherit Parent Properties #110

Closed
@bowenwr

Description

@bowenwr

Is your feature request related to a problem? Please describe.

Given OpenAPI YAML like (assume it's converted to JSON for generation):

components:
  schemas:
    Schema:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        fieldDefinitions:
          type: array
          items:
            $ref: '#/components/schemas/SchemaField'
        type:
          type: string
        prefix:
          type: string
        registryId:
          type: string
    SchemaField:
      type: object
      properties:
        isRequired:
          type: boolean
        name:
          type: string
    BoxSchema:
      allOf:
        - $ref: '#/components/schemas/Schema'
        - type: object
          properties:
            height:
              type: number
            width:
              type: number
            containerSchema:
              type: object
              properties:
                id:
                  type: string
                name:
                  type: string

The Schema class gets generated correctly like:

@dataclass
class Schema:
    """  """
    id: Optional[str] = None
    name: Optional[str] = None
    field_definitions: Optional[List[SchemaField]] = None
    type: Optional[str] = None
    prefix: Optional[str] = None
    registry_id: Optional[str] = None

...

The BoxSchema class is completely empty, with neither its own properties nor that of Schema:

@dataclass
class BoxSchema:
    """  """

    def to_dict(self) -> Dict[str, Any]:

        return {}

    @staticmethod
    def from_dict(d: Dict[str, Any]) -> BoxSchema:
        return BoxSchema()

Describe the solution you'd like

Components that inherit from other components should generate a set of properties combining parent and individual properties. Other spec viewer projects appear to properly create the expected result:

Screen Shot 2020-07-30 at 3 52 49 PM

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions