falcon-apispec

apispec plugin that generates OpenAPI specification (aka Swagger) for Falcon web applications.
Installation
pip install falcon-apispec
Works with apispec v1.0+
.
Example Application
from apispec import APISpec
from apispec.ext.marshmallow import MarshmallowPlugin
import falcon
from falcon_apispec import FalconPlugin
from marshmallow import Schema, fields
class CategorySchema(Schema):
id = fields.Int()
name = fields.Str(required=True)
class PetSchema(Schema):
category = fields.Nested(CategorySchema, many=True)
name = fields.Str()
app = falcon.API()
class RandomPetResource:
def on_get(self, req, resp):
"""A cute furry animal endpoint.
---
description: Get a random pet
responses:
200:
description: A pet to be returned
schema: PetSchema
"""
pet = get_random_pet()
resp.media = pet
random_pet_resource = RandomPetResource()
app.add_route("/random", random_pet_resource)
spec = APISpec(
title='Swagger Petstore',
version='1.0.0',
openapi_version='2.0',
plugins=[
FalconPlugin(app),
MarshmallowPlugin(),
],
)
spec.components.schema('Category', schema=CategorySchema)
spec.components.schema('Pet', schema=PetSchema)
spec.path(resource=random_pet_resource)
Generated OpenAPI Spec
spec.to_dict()
spec.to_yaml()
Contributing
Setting Up for Local Development
- Fork falcon-apispec on Github
- Install development requirements. Virtual environments are highly recommended
pip install -r requirements.txt
Running Tests
pytest