flask_more_smorest.perms.api

Extended Flask-Smorest API with authentication and permission support.

This module provides an Api class that extends Flask-Smorest’s Api with JWT authentication, permission checking, custom schema name resolution, and health check endpoint.

Functions

custom_schema_name_resolver(schema, **kwargs)

Custom schema name resolver for OpenAPI spec.

Classes

Api([app, spec_kwargs])

Extended Api with JWT authentication and permission checking.

class flask_more_smorest.perms.api.Api(app=None, *, spec_kwargs=None)[source]

Extended Api with JWT authentication and permission checking.

This class extends Flask-Smorest’s Api to automatically: - Configure JWT authentication in OpenAPI spec - Enforce authentication on non-public endpoints - Check admin permissions on admin-only endpoints - Customize schema naming for OpenAPI

Example

>>> from flask import Flask
>>> from flask_more_smorest.perms import Api
>>>
>>> app = Flask(__name__)
>>> api = Api(app)
__init__(app=None, *, spec_kwargs=None)[source]

Initialize the API with custom Marshmallow plugin.

Parameters:
  • app (Flask | None) – Optional Flask application

  • spec_kwargs (dict | None) – Optional keyword arguments for APISpec

init_app(app, *pargs, **kwargs)[source]

Initialize the API with a Flask application.

Sets up OpenAPI security schemes and before_request handler for authentication and authorization.

Parameters:
  • app (Flask) – Flask application to initialize

  • *pargs (Any) – Additional positional arguments

  • **kwargs (Any) – Additional keyword arguments

Return type:

None

flask_more_smorest.perms.api.custom_schema_name_resolver(schema, **kwargs)[source]

Custom schema name resolver for OpenAPI spec.

Filters out partial, only, and exclude schemas to keep the OpenAPI spec clean and avoid duplicate schema definitions.

Parameters:
  • schema (type[Schema]) – Marshmallow schema class to resolve name for

  • **kwargs (str | bool) – Additional keyword arguments

Return type:

str

Returns:

Empty string for partial/filtered schemas, default name otherwise