sanic-org / sanic-openapi

Easily document your Sanic API with a UI
https://sanic-openapi.readthedocs.io/
MIT License
505 stars 107 forks source link

[Bug] Inheritance does not work #177

Closed TechPriest001 closed 4 years ago

TechPriest001 commented 4 years ago

Describe the bug According to the documentation, inheritance is supported. However, using the example code provided in the documentation, the expected structure containing members from both the base class and the subclass does not occur. Instead, only the members from the subclass are shown.

Screenshots image

To Reproduce Use example code that is provided in the documentation:

from sanic import Sanic
from sanic.response import json

from sanic_openapi import doc, swagger_blueprint

app = Sanic()
app.blueprint(swagger_blueprint)

class User:
    username = doc.String("The name of your user account.")
    password = doc.String("The password of your user account.")

class UserInfo(User):
    first_name = doc.String("The first name of user.")
    last_name = doc.String("The last name of user.")

@app.get("/test")
@doc.produces(UserInfo)
async def test(request):
    return json({})

app.run(host="0.0.0.0", debug=True)

Expected behavior UserInfo on the UI page should contain "username" and "password" members in addition to "first_name" and "last_name".

Environment (please complete the following information):

Package versions:

sanic==20.3.0
sanic-openapi==0.6.0

Additional context Add any other context about the problem here. This might be how to fix this bug or some hint to fix it.

chenjr0719 commented 4 years ago

Hi @TechPriest001 , thanks for your report. The model inheritance is new feature and we haven't released the latest version include this feature to PyPI yet. 😅

To use this new feature, please install our master branch instead of using PyPI:

pip install git+https://github.com/huge-success/sanic-openapi.git

We also have the plan(in #176 ) to release 0.6.2 version to PyPI in recent days. If you do not hurry maybe you can wait for this release.

I also change the default document version to stable to avoid this happen again. Sorry for misleading you. I will close this issue first and if you still have any issue, please fell free to reopen this issue, thanks.

Best, Jacob