Skip to content

Generated Models Don't Inherit Parent Properties #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bowenwr opened this issue Jul 30, 2020 · 2 comments
Closed

Generated Models Don't Inherit Parent Properties #110

bowenwr opened this issue Jul 30, 2020 · 2 comments
Labels
✨ enhancement New feature or improvement

Comments

@bowenwr
Copy link
Contributor

bowenwr commented Jul 30, 2020

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 bowenwr added the ✨ enhancement New feature or improvement label Jul 30, 2020
@dbanty
Copy link
Collaborator

dbanty commented Jul 31, 2020

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

@dbanty
Copy link
Collaborator

dbanty commented Jul 8, 2023

I think this is long-since completed 😅

@dbanty dbanty closed this as completed Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or improvement
Projects
None yet
Development

No branches or pull requests

2 participants