Plugin for apispec which helps reusing the documentation on a muti-endpoint function/method.
Project description
apispec-clear-unusable
Plugin for apispec which helps reusing the documentation on a muti-endpoint function/method.
Example with flask-restful
from apispec import APISpec from flask import Flask, jsonify from flask_restful import Resource, Api from marshmallow import Schema, fields # Create an APISpec spec = 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 frameworks app = Flask(__name__) api = Api(app) class RandomPet(Resource): def get(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 """ return get_random_pet(species=species, race=race), 200 api.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) with app.test_request_context(): spec.add_path(view=random_pet)
Output becomes
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'
Installation
pip install apispec-clear-unusable
License
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent per‐mitted by law.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for apispec-clear-unusable-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69ac9723b76f9cddc6fb119a290f57280ff12d1f65ce65e1e61ab24b5c135d8d |
|
MD5 | aa7e74f91e1ffba810568c37ff5348bc |
|
BLAKE2-256 | 802665e9b9318483f2c9a7ff08d3a6bf4eb91e3ce4b85b602c056a54af13a485 |
Close
Hashes for apispec_clear_unusable-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e343ae9e70a9e7ce436ca10e2d4e03faf3398240ddf32f664c1c715cda862a61 |
|
MD5 | 21d039c97183b9818465c4f326774d03 |
|
BLAKE2-256 | d93621a0d74ac648a0fa3ad265d8b171b53a4a86b15a0335b9566ef8c9aa2f23 |