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 Server Object.
Not supported Security Requirement Object.
Not supported Tag Object.
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 Security Scheme Object.
Not supported OAuth Flows Object.
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
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
Hashes for Flask_First-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4989757712f5904751d9eaa6a8a2b30ce5deac1007b3abb393d2927f0058670 |
|
MD5 | 288948e48c0dc8aae2a80c3f5d8eac10 |
|
BLAKE2b-256 | 99fb3fd1494e271727e4230e293fc00ffe6787dcd34228beed33dc36dc98de44 |