Skip to main content

Add openapi docs to flask app using Flask-Pydantic

Project description

Flask-Pydantic-Docs

Installation

python3 -m pip install Flask-Pydantic-Docs

Usage

Example

# necessary imports

app = Flask(__name___)
openapi = OpenAPI()

access_denied = APIError(code=403, msg="Access Denied")

@app.route("/post", methods=["POST"])
@openapi_docs(response=ResponseModel, tags=["demo"], exceptions=[access_denied])
@validate()
def post(body: BodyModel, query: QueryModel):
    return ResponseModel(
        id=id_,
        age=query.age,
        name=body.name,
        nickname=body.nickname,
    )
...

openapi.register(app)

NOTE:

  • Since the openapi_docs decorator is to register the schemas based on the models used by the view function, so the models have to be put in the view function arguments with annotations as shown in the above example. Otherwise, the schemas cannot be captured.

  • The statement openapi.register needs to be run after all view functions or register_blueprint.

Add Auth Security Schemes

# necessary imports, app and model definition

openapi = OpenAPI(
    extra_props={
        "components": {
            "securitySchemes": {
                "bearerAuth": {
                    "type": "http",
                    "scheme": "bearer",
                    "bearerFormat": "JWT",
                }
            }
        },
        "security": [{"bearerAuth": []}]
    },
)

...

openapi.register(app)

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-Pydantic-Docs-0.0.16.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Flask_Pydantic_Docs-0.0.16-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file Flask-Pydantic-Docs-0.0.16.tar.gz.

File metadata

  • Download URL: Flask-Pydantic-Docs-0.0.16.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.11

File hashes

Hashes for Flask-Pydantic-Docs-0.0.16.tar.gz
Algorithm Hash digest
SHA256 29e1fe8d5f75e5e2e700303f28c91b1f3b1092b3db42bbbbd57cd5093773e84b
MD5 6fb2e5b6bb333ce17f23387ce6804174
BLAKE2b-256 d5d452aa58c68ed143dd0c22df3d0b34373dacf6efe18a41dcce3243db3ebe52

See more details on using hashes here.

File details

Details for the file Flask_Pydantic_Docs-0.0.16-py3-none-any.whl.

File metadata

  • Download URL: Flask_Pydantic_Docs-0.0.16-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.11

File hashes

Hashes for Flask_Pydantic_Docs-0.0.16-py3-none-any.whl
Algorithm Hash digest
SHA256 78f151f9a7ff891324295024c2281d11c79c0b7c68ab45cf0e98b5f02ebcf566
MD5 632a8fa3c6f9079d4041bcfca09e30b9
BLAKE2b-256 1a396190cb9c69b0006a87299a61ef090afd221dfb72c4d7e1f163e9d94c61ed

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