用于apispec的插件,通过使用修饰函数堆栈帮助重用文档。

apispec-decorated-crawler的Python项目详细描述


APISPEC装饰爬虫

用于apispec的插件,通过使用修饰函数堆栈帮助重用文档。

扩展示例

使用此设置:

fromapispecimportAPISpecfromflaskimportFlaskfrommarshmallowimportSchema,fieldsfrombrunoais.apispec.ext.decorated_crawlerimportdocd_wrapsapp=Flask(__name__)# Create an APISpecspec=APISpec(title='A safe Random swagger Petstore',version='1.0.0',plugins=['apispec.ext.flask','apispec.ext.marshmallow','brunoais.apispec.ext.decorated_crawler',],)defdecorates(func):@docd_wraps(func)defcalling(*args,**kwargs):"""            ---            get:                consumes:                  - application/xml+dec1                security:                    - AlmostBasicAuth: []                      BasicAuth: []                    - ApiKeyAuth: []                tags:                    - down1                    - up1                responses:                    400:                        description: he may fail {f[x-400-suffix]}                        schema: PetSchema            _:                responses:                    400:                        description: Global fail                        schema: PetSchema        """returnfunc(*args,**kwargs)returncallingdefdecorates2(func):@docd_wraps(func)defcalling(*args,**kwargs):"""        ---        get:            tags:                - get2                - up1            security:                - OAuth2: [scope1, scope2]            responses:                402:                    description: mefail                    schema: PetSchema        """returnfunc(*args,**kwargs)returncalling

传递视图函数:

@app.route('/random/<kind>')@decorates@decorates2defrandom_pet(kind):"""    A cute furry animal endpoint.    ---    post:        description: POST a pet    get:        description: Get a pet        security:            - ApiKeyAuth: []        consumes:          - application/json          - application/xml        produces:          - application/json          - application/xml        parameters:            - in: path              name: kind              required: true              type: string              description: Path Parameter description in Markdown.            - in: query              name: offset              type: string              description: Query Parameter description in Markdown.        responses:            200:                description: A pet to be returned                schema: PetSchema            400:                x-400-suffix: yeah yeah....    """pet={"category":[{"id":1,"name":"Named"}],"name":"woof"}returnjsonify(PetSchema().dump(pet).data)# Optional marshmallow supportclassCategorySchema(Schema):id=fields.Int()name=fields.Str(required=True)classPetSchema(Schema):category=fields.Nested(CategorySchema,many=True)name=fields.Str()spec.definition('Category',schema=CategorySchema)spec.definition('Pet',schema=PetSchema)withapp.test_request_context():spec.add_path(view=random_pet)

结果变为

print(spec.to_yaml())
definitions:# ...info:{title:A safe Random swagger Petstore, version:1.0.0}paths:/random/{kind}:post:description:POST a petresponses:400:{description:Global fail, schema:PetSchema}get:consumes:[application/json,application/xml,application/xml+dec1]description:Get a petparameters:-{description:Path Parameter description in Markdown., in:path, name:kind,        required:true, type:string}-{description:Query Parameter description in Markdown., in:query, name:offset,        type:string}produces:[application/json,application/xml]responses:200:description:A pet to be returnedschema:{$ref:'#/definitions/Pet'}400:{description:he may fail yeah yeah...., schema:PetSchema, x-400-suffix:yeahyeah....}402:{description:mefail, schema:PetSchema}security:-ApiKeyAuth:[]-AlmostBasicAuth:[]BasicAuth:[]-OAuth2:[scope1,scope2]tags:[down1,up1,get2]swagger:'2.0'tags:[]

详细信息

这是一个操作助手,允许您传递修饰视图并获取所有修饰函数的组合文档。 它需要传递给add_path的视图。检查视图docstrings及其docd_包装decorator函数并合并所有 将文档转换为单个文档。 如果您使用decorators来管理身份验证,或者即使您有共享的错误页而您没有 希望在所有视图上分别记录常见错误状态(状态400、状态500等)。

所有文档从下到上合并,从view函数开始,到最上面的decorator结束。 decorators可以声明一个名为u(下划线)的“特殊”http方法。在所有方法中最后一个被应用, 也是自下而上,在随后的传球中。

安装

pip install apispec-decorated-crawler

许可证

这是自由软件:你可以自由地修改和重新发布它。 在法律允许的范围内,没有任何保证。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java JavaFX 11可编辑组合框引发IndexOutOfBoundsException   java选择数组中的数组元素   java我从来没有找到创建2D ArrayList的正确方法   java JPA查找orderById的顶部数据,并按字符串过滤Id   使用java在ejabberd中进行xmpp外部身份验证   从ajax调用向java传递点运算符   java如何使用ReadWriteLock   使用Spring控制器和jQueryAjax的java重定向   java使JFrame中的JPanel可滚动   java如何用多个。jar库?   java EditText在RecyclerView中失去了对滚动的关注   java为什么我们必须扩展Servlet或GenericServlet或HttpServlet来创建Servlet应用程序?如果不扩展,我们可以开发Servlet应用程序吗?   使用递归java查找数组中的最大值   具有不同字段数的html表单的java域传输对象   java文本视图扩展;不支持操作异常   java如何使用iText的HTMLWorker类将多语言HTML字符串呈现为PDF