Skip to main content

Flask extension for using “specification first” principle.

Project description

Flask extension for using “specification first” principle.

Features:

  • Decorator for mapping routes from OpenAPI specification on Python’s view functions via Flask.

  • Validating path parameters from url.

  • Validating arguments from url.

  • Validating JSON from request.

  • Validating response.


Limitations

  • All specification in one file.

  • Not supported request headers.

  • Not supported xml.

  • Not supported External Documentation Object.

  • Not supported allOf, oneOf, anyOf.

  • Not supported Encoding Object.

  • Not supported Callback Object.

  • Not supported Example Object.

  • Not supported Link Object.

  • Not supported Discriminator Object.

  • Not supported XML Object.

  • Not supported Specification Extensions.

  • Not supported OAuthFlowsObject.


Installing

Install and update using pip:

$ pip install flask_first

Simple example

OpenAPI 3 specification file openapi.yaml:

openapi: 3.0.3
info:
  title: Simple API for Flask-First
  version: 1.0.0
paths:
  /{name}:
    parameters:
      - name: name
        in: path
        required: true
        schema:
          type: string
    get:
      operationId: index
      summary: Returns a list of items
      responses:
        '200':
          description: OK

File with application initialization main.py:

import os

from flask import Flask
from flask_first import First

basedir = os.path.abspath(os.path.dirname(__file__))
path_to_spec = os.path.join(basedir, 'openapi.yaml')

app = Flask(__name__)
app.config['FIRST_RESPONSE_VALIDATION'] = True
First(app, path_to_spec=path_to_spec)


@app.specification
def index(name):
    return f'Hello, {name}!'

if __name__ == '__main__':
    app.run()

Run application:

$ python main.py

Check url in browser http://127.0.0.1:5000/username.

Settings

FIRST_RESPONSE_VALIDATION

Default: False.

Enabling response body validation. Useful when developing. May be disabled in a production environment.

Additional documentation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Flask-First-0.2.0.tar.gz (12.9 kB view hashes)

Uploaded Source

Built Distribution

Flask_First-0.2.0-py3-none-any.whl (9.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page