No project description provided
Project description
flask-redoc
A Flask extension for displaying OpenAPI/Swagger documentation using Redocs.
Installation
Under your virtualenv do:
pip install flask-redoc
or (dev version)
pip install https://github.com/mzaglia/flask-redoc
Getting Started
Using YAML file
Save your petstore.yml
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
responses:
'200':
description: A paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
items:
$ref: "#/components/schemas/Pet"
Error:
type: object
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
Load in your app:
from flask import Flask
from flask_redoc import Redoc
redoc = Redoc(app,'petstore.yml')
@app.route('/pets', methods=['GET', 'POST'])
def pets():
...
You can also use docstrings as specification and Marshmallow models for schemas (this will updated any existing specs loaded with YAML files).
app.config['REDOC'] = {'title':'Petstore', 'marshmallow_schemas':[PetSchema]}
class PetSchema(Schema):
name = fields.Str()
@app.route('/random')
def random():
"""A cute furry animal endpoint.
---
get:
description: Get a random pet
responses:
200:
description: Return a pet
content:
application/json:
schema: PetSchema
"""
return PetSchema().dump(dict(name="Bird"))
Configuration
Default configuration
DEFAULT_CONFIG = {
'endpoint': 'docs',
'spec_route': '/docs',
'static_url_path': '/redoc_static',
'title': 'ReDoc',
'version': '1.0.0',
'openapi_version': '3.0.2',
'info': dict(),
'marshmallow_schemas': list()
}
Changing configuration
You can change any default configuration as follows
app.config['REDOC'] = {'spec_route': '/my_docs', 'title': 'My Docs'}
redoc = Redoc(app)
Further reading
For more information about creating your spec using docstring, please visit: https://apispec.readthedocs.io/en/latest/
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flask_redoc-0.2.1.tar.gz.
File metadata
- Download URL: flask_redoc-0.2.1.tar.gz
- Upload date:
- Size: 281.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c9f986abde3493135544ec5cce28d04fda80517582e59411fe4833d3e0a4f71
|
|
| MD5 |
7b8ff79885d72d09430ce79263235697
|
|
| BLAKE2b-256 |
c7a2fa89ca1a15dcdc7c132e66269f591995d4a847be271f67c4439774053fdb
|
File details
Details for the file flask_redoc-0.2.1-py3-none-any.whl.
File metadata
- Download URL: flask_redoc-0.2.1-py3-none-any.whl
- Upload date:
- Size: 277.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07fac353155c9d9139805ca48877cf3f2a576493c9aa8b269fd49b520880999d
|
|
| MD5 |
9e1096e77764ef9150a02691bfef1162
|
|
| BLAKE2b-256 |
6b71a80787f848a8f5459db4b78cbdb4c8af305cfbcc57f76cedabdeb36cb687
|