Skip to content
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

Add basic support for type hinting-based docs #129

Merged
merged 11 commits into from
Sep 2, 2019

Conversation

viniciusd
Copy link
Contributor

@viniciusd viniciusd commented Aug 8, 2019

Incrementally addresses #128

A working example that fully works after these changes:

from sanic import Sanic
from sanic_openapi import doc, swagger_blueprint

app = Sanic()
app.blueprint(swagger_blueprint)

class Car:
    make: str
    model: str
    year: int

@app.get("/car/<id:int>")
@doc.summary("Gets a car")
@doc.produces(Car)
async def get_car(request, car_id):
    return json({
                 "make": "Nissan",
                 "model": "370Z",
    })

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8000)

@viniciusd
Copy link
Contributor Author

viniciusd commented Aug 8, 2019

I acknowledge there aren't tests related to this kind of feature throughout the current codebase. In a future PR, I can work on adding tests to the object serialization.

@chenjr0719
Copy link
Member

@viniciusd Sorry for the delay. About the conflict, please solve it. Maybe you can put the example at here. And, I think it is better to add test in this PR or the code coverage might decrease after merge this PR.

@codecov-io
Copy link

codecov-io commented Aug 20, 2019

Codecov Report

Merging #129 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #129      +/-   ##
==========================================
+ Coverage   95.54%   95.56%   +0.01%     
==========================================
  Files           4        4              
  Lines         449      451       +2     
  Branches       95       95              
==========================================
+ Hits          429      431       +2     
  Misses          6        6              
  Partials       14       14
Impacted Files Coverage Δ
sanic_openapi/doc.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a6df84d...dbaf5b0. Read the comment docs.

@viniciusd
Copy link
Contributor Author

Thanks for the feedback!
Conflict is now solved 👍

Gonna add the example to the docs

@viniciusd
Copy link
Contributor Author

Sorry for the delay, got pushed back by a few other tasks.

Added docs to the fields.md file :)

Copy link
Member

@chenjr0719 chenjr0719 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants