flask_more_smorest.crud.blueprint_operationid
Enhanced Blueprint with automatic operationId generation.
This module provides BlueprintOperationIdMixin that extends Flask-Smorest’s Blueprint to automatically generate OpenAPI operationId values for endpoints.
Functions
|
Strip common boilerplate suffixes from class or function names. |
Classes
|
Blueprint mixin that provides automatic operationId generation. |
- flask_more_smorest.crud.blueprint_operationid.strip_suffixes(name)[source]
Strip common boilerplate suffixes from class or function names.
Strips suffixes in priority order so compound suffixes like
V2Listare handled correctly (V2removed first, thenList).- Parameters:
name (
str) – Class or function name to normalise.- Return type:
- Returns:
Name with recognised suffixes removed.
Example
>>> strip_suffixes("UserListView") 'User' >>> strip_suffixes("AccreditationIndexV2") 'Accreditation' >>> strip_suffixes("FeeEstimationView") 'FeeEstimation'
- class flask_more_smorest.crud.blueprint_operationid.BlueprintOperationIdMixin(*args, **kwargs)[source]
Blueprint mixin that provides automatic operationId generation.
Extends Flask-Smorest’s Blueprint to automatically generate OpenAPI
operationIdvalues for routes based on the route pattern, HTTP method, class name (after suffix stripping) and response schema.Collection detection for GET requests (in priority order):
Manual
@bp.doc(operationId=…)override → used as-is.Explicit
operation_id=kwarg onroute()→ used as-is.Trailing slash in path → collection (
listXxx).many=Trueon response schema → collection (listXxx).Default → individual (
getXxx).
Examples:
bp = BlueprintOperationIdMixin('users', __name__) # Auto-generated: listUsers @bp.route('/users/') class User(MethodView): def get(self): ... # Custom full operationId for a function-based route @bp.route('/special', operation_id='getSpecialUsers') def special_users(): ... # Prefix for all methods on a MethodView (e.g. deprecation) @bp.route('/legacy', operation_id_prefix='_deprecated_') class Item(MethodView): def get(self): ... # → _deprecated_getItem def post(self): ... # → _deprecated_createItem # Suffix for versioning @bp.route('/v2/users/', operation_id_suffix='_v2') class User(MethodView): def get(self): ... # → listUsers_v2 # Combine prefix and suffix @bp.route('/old', operation_id_prefix='legacy_', operation_id_suffix='_v1') class OldEndpoint(MethodView): def get(self): ... # → legacy_getOldEndpoint_v1
- route(rule, *, operation_id=None, operation_id_prefix=None, operation_id_suffix=None, parameters=None, tags=None, **options)[source]
Override route() to capture operationId customisation options.
- Parameters:
rule (
str) – URL rule for the route.operation_id (
str|None) – Explicit full operationId (function-based routes) or override for every method on a MethodView.operation_id_prefix (
str|None) – Prefix prepended to the auto-generated operationId for every method on a MethodView.operation_id_suffix (
str|None) – Suffix appended to the auto-generated operationId for every method on a MethodView.parameters (
list|None) – OpenAPI path-level parameters (passed to parent).**options (
Any) – Additional Flask routing options.
- Return type:
Callable[[type[MethodView] |Callable],type[MethodView] |Callable]- Returns:
Decorator for the view class or function.