简体   繁体   English

Python-Flask,Swagger,从注释生成API文档

[英]Python-Flask,Swagger, Generate API documents from annotations

I have an existing written application where the APIs are written in following way: 我有一个现有的书面应用程序,其中API以下列方式编写:

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

I want to generate the Swagger documentation from this type of APIs. 我想从这种类型的API生成Swagger文档。 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. 到目前为止,我尝试了很少的选项,但是大多数选项都是从yml文件或特定方法的docstring中的yml字符串生成文档。

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. 当然我也更喜欢使用docstring的内容生成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. 您将swagger doc放在装饰瓶的文档字符串中 - 方法和flasgger将为您的应用程序提供生成的输出的新端点。 Works very well! 效果很好!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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