A pluggable API documentation generator. Currently supports the Swagger 2.0 specification.
Project description
A pluggable API documentation generator. Currently supports the OpenAPI specification (f.k.a. Swagger 2.0).
Features
Supports OpenAPI 2.0 specification (f.k.a. Swagger)
Framework-agnostic
Includes plugins marshmallow, Flask, and Tornado
Utilities for parsing docstrings
Example Application
from apispec import APISpec
from flask import Flask, jsonify
from marshmallow import Schema, fields
# Create an APISpec
spec = APISpec(
title='Swagger Petstore',
version='1.0.0',
plugins=[
'apispec.ext.flask',
'apispec.ext.marshmallow',
],
)
# Optional marshmallow support
class CategorySchema(Schema):
id = fields.Int()
name = fields.Str(required=True)
class PetSchema(Schema):
category = fields.Nested(CategorySchema, many=True)
name = fields.Str()
# Optional Flask support
app = Flask(__name__)
@app.route('/random')
def random_pet():
"""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()
return jsonify(PetSchema().dump(pet).data)
ctx = app.test_request_context()
ctx.push()
# Register entities and paths
spec.definition('Category', schema=CategorySchema)
spec.definition('Pet', schema=PetSchema)
spec.add_path(view=random_pet)
Generated Swagger Spec
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"
# }
# }
# }
# },
# }
Documentation
Documentation is available at http://apispec.readthedocs.org/ .
License
MIT licensed. See the bundled LICENSE file for more details.
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
apispec-0.10.1.tar.gz
(30.7 kB
view details)
Built Distribution
File details
Details for the file apispec-0.10.1.tar.gz
.
File metadata
- Download URL: apispec-0.10.1.tar.gz
- Upload date:
- Size: 30.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1106ad6e34335537594375076111cbf8b9366aab4b09af9f866320606fe21b62 |
|
MD5 | 4e5d88992f4b51d6a134344ed4f96b83 |
|
BLAKE2b-256 | be02bcef096364b94b3b2afb27c2b8bd4842fdeac320f0d77a57a88c81da5d47 |
Provenance
File details
Details for the file apispec-0.10.1-py2.py3-none-any.whl
.
File metadata
- Download URL: apispec-0.10.1-py2.py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b668bea8751c5422116f98fd88b77113942f3f834bcbcf56f6d19bcd56848c0c |
|
MD5 | 6d52e942d5251655ce72a6eb322e9a60 |
|
BLAKE2b-256 | cf463dba877265ceae1dc3335c6a43d89e6428db120804dd0b213171f9feddae |