openapi-python-client icon indicating copy to clipboard operation
openapi-python-client copied to clipboard

Generated Models Don't Inherit Parent Properties

Open bowenwr opened this issue 5 years ago • 1 comments

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

bowenwr avatar Jul 30 '20 23:07 bowenwr

I believe this overlaps with #98 (supporting allOf feature. Great detail here though so definitely keeping this open until it's done.

dbanty avatar Jul 31 '20 13:07 dbanty

I think this is long-since completed 😅

dbanty avatar Jul 08 '23 17:07 dbanty