Skip to main content

Swagger UI blueprint for Flask

Project description

# flask-swagger-ui

Simple Flask blueprint for adding [Swagger UI](https://github.com/swagger-api/swagger-ui) to your flask application.

Included Swagger UI version: 2.2.5.

## Installation

`pip install flask-swagger-ui`

## Usage

Example application:

```python
from flask import Flask
from flask_swagger_ui import get_swaggerui_blueprint

app = Flask(__name__)


SWAGGER_URL = '/api/docs' # URL for exposing Swagger UI (without trailing '/')
API_URL = 'http://petstore.swagger.io/v2/swagger.json' # Our API url (can of course be a local resource)

# Call factory function to create our blueprint
swaggerui_blueprint = get_swaggerui_blueprint(
SWAGGER_URL, # Swagger UI static files will be mapped to '{SWAGGER_URL}/dist/'
API_URL,
config={ # Swagger UI config overrides
'supportedSubmitMethods': ['get']
}
)

# Register blueprint at URL
# (URL must match the one given to factory function above)
app.register_blueprint(swaggerui_blueprint, url_prefix=SWAGGER_URL)

app.run()

# Now point your browser to localhost:5000/api/docs/

```

## Configuration

The blueprint supports overloading all Swagger UI configuration options that can be JSON serialized.
See https://github.com/swagger-api/swagger-ui#parameters for options.

In addition, some of the OAuth fields are exposed to special variables that will be rendered into the relevant function.

Blueprint defaults are listed below (should match SwaggerUI defaults).

```python
{
# OAuth related
'app_name': 'null',
'client_realm': 'null',
'client_id': 'null',
'client_secret': 'null',

# SwaggerUI base configuration, see https://github.com/swagger-api/swagger-ui#parameters
'docExpansion': "none",
'jsonEditor': False,
'defaultModelRendering': 'schema',
'showRequestHeaders': False,
'supportedSubmitMethods': ['get', 'post', 'put', 'delete', 'patch']
}
```

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-swagger-ui-0.0.2.tar.gz (946.3 kB view details)

Uploaded Source

File details

Details for the file flask-swagger-ui-0.0.2.tar.gz.

File metadata

File hashes

Hashes for flask-swagger-ui-0.0.2.tar.gz
Algorithm Hash digest
SHA256 ed54496b6e627f19c88d5b0c8d5a76e9f639f44a633ad417d5f903062250efeb
MD5 ec1b6ff270080948bfef635ca3422b74
BLAKE2b-256 c9ef75e894575efcab4d0f546a744cfa535ee366d93589b03a68c16e7e5d4f70

See more details on using hashes here.

Supported by

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