用于apispec的插件,有助于重用多端点函数/方法的文档。

apispec-clear-unusable的Python项目详细描述


APISpec清除不可用

用于apispec的插件,有助于重用多端点函数/方法的文档。

示例,带酒瓶

fromapispecimportAPISpecfromflaskimportFlask,jsonifyfromflask_restfulimportResource,ApifrommarshmallowimportSchema,fields# Create an APISpecspec=APISpec(title='Random swagger Petstore',version='1.0.0',plugins=['apispec.ext.flask','apispec.ext.marshmallow','brunoais.apispec.ext.clear_unusable',],)# This example uses flask but it also works with other frameworksapp=Flask(__name__)api=Api(app)classRandomPet(Resource):defget(self,species=None,race=None):"""A cute random furry animal.        ---        description: Get a random pet        parameters:            - in: path              name: species              type: string              description: The species of the animal to be randomly selected        parameters:            - in: path              name: race              type: string              description: The race of the animal to be randomly selected        responses:            200:                description: A pet to be returned                schema: PetSchema        """returnget_random_pet(species=species,race=race),200api.add_resource(RandomPet,'/pets/random',endpoint='randompet')api.add_resource(RandomPet,'/pets/<species>/random',endpoint='randompet_species')api.add_resource(RandomPet,'/pets/<species>/races/<race>/random',endpoint='randompet_species_race')spec.definition('Category',schema=CategorySchema)spec.definition('Pet',schema=PetSchema)withapp.test_request_context():spec.add_path(view=random_pet)

输出变为

definitions:
	#...
parameters: {}
paths:
  /pets/random:
    get:
      description: Get a random pet
      parameters: []
      responses:
        200:
          description: A pet to be returned
          schema: {$ref: '#/definitions/Pet'}
  /pets/{species}/random:
    get:
      description: Get a random pet
      parameters:
      - {description: The species of the animal to be randomly selected, in: path,
        name: species, required: true, type: string}
      responses:
        200:
          description: A pet to be returned
          schema: {$ref: '#/definitions/Pet'}
  /pets/{species}/races/{race}/random:
    get:
      description: Get a random pet
      parameters:
      - {description: The species of the animal to be randomly selected, in: path,
        name: species, required: true, type: string}
      - {description: The race of the animal to be randomly selected, in: path, name: race,
        required: true, type: string}
      responses:
        200:
          description: A pet to be returned
          schema: {$ref: '#/definitions/Pet'}
swagger: '2.0'

安装

pip install apispec-clear-unusable

许可证

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

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

推荐PyPI第三方库


热门话题
java如何通过解决错误“活动无法转换为片段”将片段传递给类构造函数?   Java中清理Code39条码数据的regex帮助   将java转换为C++   java无法在Android Studio中生成签名的apk,出现错误   从数学方程出发   MySQL和Java内存问题   如何强制Java抛出算术异常?   java为什么JDBC将零端口视为空(默认)端口?   java如何在没有“changelog主题”的情况下加入KStream和KTable   排序我尝试合并两个排序的数组,但得到的是java。lang.ArrayIndexOutofBounds异常:5无法找出原因   如何在java中求大长度矩阵的逆?   基于maven构建的java生成类路径字符串   java每20个字符分割一个字符串,然后将每个部分打印到控制台   将字符串数字字转换为字符串数字:Java   在特定区域使用混合类型的java填充字节数组   尽管java类在开关块中实例化,但它只能调用接口方法