sanic-org / sanic-openapi

Easily document your Sanic API with a UI

Home Page:https://sanic-openapi.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature Request] Models inheritance

denisovkiv opened this issue · comments

Hello! What do you think about models inheritance? Ex.

from sanic_openapi import doc


class ShortInfo:
    foo = doc.String()


class FullInfo(ShortInfo):
    bar = doc.String()

Expected that FullInfo model would include foo field, but in the UI appears bar field only.

One of possible solutions is to change this line
https://github.com/huge-success/sanic-openapi/blob/fe29d07ccb0e02ec0be6496e971946269b2d7907/sanic_openapi/doc.py#L143
to something like

{key: getattr(self.cls, key) for key in dir(self.cls)}.items(), typing.get_type_hints(self.cls).items()

to get all of class fields include parents, not only current class (SO example)

It would be very nice feature to keep projects DRY

Sounds cool, do you want to submit a PR for it?

Yes, I would be very happy to help :)

Since #166 is merged, close this issue.