Skip to content

A Swagger (OpenAPI) implementation using the Falcon Framework. With SQLAlchemy and Redis support

License

Notifications You must be signed in to change notification settings

dutradda/falcon-swagger

Repository files navigation

DISCONTINUED PROJECT! Please see the Swagger it framework.

Build Status Coverage Status

falcon-swagger

A Falcon Framework (http://falconframework.org) Extension.

Features:

  • Supports Swagger Schema 2.0 (OpenAPI 2.0);
  • Provides SQLAlchemy models base classes (with Redis integration, if you want);
  • Provides Redis models base classes (without SQLAlchemy).

Usage Example:

from falconswagger import SwaggerAPI, ModelHttpMeta

class HelloModelMeta(ModelHttpMeta):
   __schema__ = {
      '/hello/you/{name}': {
         'get': {
            'parameters': [{
                'name': 'name',
                'in': 'path',
                'required': True,
                'type': 'string'
            }],
            'operationId': 'get_hello_you',
            'responses': {'200': {'description': 'Got you'}}
        }
      },
      '/hello/world': {
         'get': {
            'operationId': 'get_hello_world',
            'responses': {'200': {'description': 'Got hello'}}
        }
      }
   }

   def get_hello_you(cls, req, resp):
      you = req.context['parameters']['path']['name']
      resp.body = 'Hello {}!\n'.format(you)
                  
   def get_hello_world(cls, req, resp):
      resp.body = 'Hello World!\n'

class HelloModel(metaclass=HelloModelMeta):
   pass

api = SwaggerAPI([HelloModel], title='Hello API')
gunicorn hello_word_api:api
curl -i localhost:8000/hello/world
HTTP/1.1 200 OK
Server: gunicorn/19.6.0
Connection: close
content-length: 13
content-type: application/json; charset=UTF-8

Hello World!
curl -i localhost:8000/hello/you/Diogo
HTTP/1.1 200 OK
Server: gunicorn/19.6.0
Connection: close
content-length: 13
content-type: application/json; charset=UTF-8

Hello Diogo!
curl -i localhost:8000/swagger.json
HTTP/1.1 200 OK
Server: gunicorn/19.6.0
Connection: close
content-length: 672
content-type: application/json; charset=UTF-8

{
  "swagger": "2.0",
  "paths": {
    "/hello/world": {
      "get": {
        "operationId": "HelloModel.get_hello_world",
        "responses": {
          "200": {
            "description": "Got hello"
          }
        }
      }
    },
    "/hello/you/{name}": {
      "get": {
        "operationId": "HelloModel.get_hello_you",
        "responses": {
          "200": {
            "description": "Got you"
          }
        },
        "parameters": [
          {
            "in": "path",
            "type": "string",
            "required": true,
            "name": "name"
          }
        ]
      }
    }
  },
  "info": {
    "title": "Hello API",
    "version": "1.0.0"
  }
}

About

A Swagger (OpenAPI) implementation using the Falcon Framework. With SQLAlchemy and Redis support

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages