Falcon plugin for APICEPEC documentation generation.

falcon-apispec的Python项目详细描述


猎鹰APISpec

Build StatuscodecovPyPILicense: MIT

apispecFalconweb应用程序生成openapi规范(又名swagger)的插件。

安装

pip install falcon-apispec

使用apispec v1.0+

示例应用程序

fromapispecimportAPISpecfromapispec.ext.marshmallowimportMarshmallowPluginimportfalconfromfalcon_apispecimportFalconPluginfrommarshmallowimportSchema,fields# Optional marshmallow supportclassCategorySchema(Schema):id=fields.Int()name=fields.Str(required=True)classPetSchema(Schema):category=fields.Nested(CategorySchema,many=True)name=fields.Str()# Create Falcon web appapp=falcon.API()classRandomPetResource:defon_get(self,req,resp):"""A cute furry animal endpoint.        ---        get:            description: Get a random pet            responses:                200:                    description: A pet to be returned                    schema: PetSchema        """pet=get_random_pet()# returns JSONresp.media=pet# create instance of resourcerandom_pet_resource=RandomPetResource()# pass into `add_route` for Falconapp.add_route("/random",random_pet_resource)# Create an APISpecspec=APISpec(title='Swagger Petstore',version='1.0.0',openapi_version='2.0',plugins=[FalconPlugin(app),MarshmallowPlugin(),],)# Register entities and pathsspec.components.schema('Category',schema=CategorySchema)spec.components.schema('Pet',schema=PetSchema)# pass created resource into `path` for APISpecspec.path(resource=random_pet_resource)

生成的openapi规范

spec.to_dict()# {#   "info": {#     "title": "Swagger Petstore",#     "version": "1.0.0"#   },#   "swagger": "2.0",#   "paths": {#     "/random": {#       "get": {#         "description": "A cute furry animal endpoint.",#         "responses": {#           "200": {#             "schema": {#               "$ref": "#/definitions/Pet"#             },#             "description": "A pet to be returned"#           }#         },#       }#     }#   },#   "definitions": {#     "Pet": {#       "properties": {#         "category": {#           "type": "array",#           "items": {#             "$ref": "#/definitions/Category"#           }#         },#         "name": {#           "type": "string"#         }#       }#     },#     "Category": {#       "required": [#         "name"#       ],#       "properties": {#         "name": {#           "type": "string"#         },#         "id": {#           "type": "integer",#           "format": "int32"#         }#       }#     }#   },# }spec.to_yaml()# definitions:#   Pet:#     enum: [name, photoUrls]#     properties:#       id: {format: int64, type: integer}#       name: {example: doggie, type: string}# info: {description: 'This is a sample Petstore server.  You can find out more ', title: Swagger Petstore, version: 1.0.0}# parameters: {}# paths: {}# security:# - apiKey: []# swagger: '2.0'# tags: []

贡献

为地方发展而设立

  1. Github上的Fork Falcon APISpec
  2. 安装开发需求。强烈建议使用虚拟环境
pip install -r requirements.txt

运行测试

pytest

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

推荐PyPI第三方库


热门话题
java应用程序不是在Eclipse中运行,而是在命令行中运行   swing Java图形组件问题。似乎找不到错误   我需要键盘。close();让代码正常工作?   Springboot中的java HttpSession   抽象语法树我想添加一个语句。我试图解析它,java解析器异常被抛出。如何克服它?   java Hibernate:清理会话   具有不连续子集的java划分问题   java正则表达式查找最后一个冒号后的字符串   java从SpringShell执行OS命令   Java扫描器字符串输入   java字符串索引越界异常(charAt)   java执行器服务终止被卡住   Springockito没有继承java@ContextConfiguration   java如何为一个servlet映射多个url   java安卓获取命令的stderr   java生成类型。表:数据库中的大数字   安卓 Getter Setter返回NothingJava