PWZER / swagger-ui-py

Swagger UI for Python web framework, such Tornado, Flask and Sanic. https://pwzer.github.io/swagger-ui-py/
https://pypi.org/project/swagger-ui-py
Apache License 2.0
69 stars 31 forks source link
openapi swagger

tests Version PyPi Version PyPi Downloads

Project Page

swagger-ui-py

Swagger UI for Python web framework, such Tornado, Flask, Quart, aiohttp, Sanic and Falcon.

Only support Python3.

Supported

You can print supported list use command

python3 -c "from swagger_ui import supported_list; print(supported_list)"

If you want to add supported frameworks, you can refer to Flask Support or Falcon Support, Implement the corresponding handler and match function.

Usage

SwaggerUI Configuration

You can configure Swagger parameters using the dictionary, Both key and value are of type str, if value is JavaScript string, you need to wrap the quotes around it. Such as "layout": "\"StandaloneLayout\"".

  parameters = {
      "deepLinking": "true",
      "displayRequestDuration": "true",
      "layout": "\"StandaloneLayout\"",
      "plugins": "[SwaggerUIBundle.plugins.DownloadUrl]",
      "presets": "[SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset]",
  }
  api_doc(app, config_path='./config/test.yaml', parameters=parameters)

For details about parameters configuration, see the official documentation Parameters Configuration.

OAuth2 Configuration

The format is similar to parameters.

  oauth2_config = {
      "clientId": "\"your-client-id\"",
      "clientSecret": "\"your-client-secret-if-required\"",
      "realm": "\"your-realms\"",
      "appName": "\"your-app-name\"",
      "scopeSeparator": "\" \"",
      "scopes": "\"openid profile\"",
      "additionalQueryStringParams": "{test: \"hello\"}",
      "usePkceWithAuthorizationCodeGrant": True,
  }
  api_doc(app, config_path='./config/test.yaml', oauth2_config=oauth2_config)

For details about OAuth2 configuration, see the official documentation OAuth2 Configuration.

Swagger UI

Swagger UI version is v5.7.2. see https://github.com/swagger-api/swagger-ui.

Swagger Editor

Swagger Editor version is v4.11.1. see https://github.com/swagger-api/swagger-editor.

Update

You can update swagger ui and swagger editor version with

python3 tools/update.py --ui --editor