用于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
许可证
这是自由软件:你可以自由地修改和重新发布它。 在法律允许的范围内,没有任何保证。