简体   繁体   中英

Python-Flask,Swagger, Generate API documents from annotations

I have an existing written application where the APIs are written in following way:

@app.route('/')
def hello():
    return "Hello World":

I want to generate the Swagger documentation from this type of APIs. So far, I've tried few options but most of them generate documents from yml files or yml strings in docstring of a particular method.

I would like to use annotation based approach . There are few libraries which do that but they need to have class for each method which we don't have in code (and changing all of the code is not possible)

Can anybody give me some pointers? What do you use in your projects?

Have you tried flask-sillywalk ? It is not quite what you're asking for, but the closest to the real thing I've seen so far.

Of course I'd also prefer something that would use the contents of the docstring to generate the input for swagger.

Update: There is flasgger . You put the swagger doc in the docstrings of the decorated flask-methods and flasgger will provide a new endpoint for your app with the generated output. Works very well!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM