@@ -280,13 +280,19 @@ def generate_spec_json(self):
280280 }
281281 }
282282
283- def register_api (self , api : APIBlueprint ) -> None :
283+ def register_api (self , api : APIBlueprint , ** options : Any ) -> None :
284284 """
285285 Register an APIBlueprint.
286286
287287 Args:
288288 api: The APIBlueprint instance to register.
289289
290+ options: Additional keyword arguments are passed to :class:`~flask.blueprints.BlueprintSetupState`.
291+ They can be accessed in :meth:`~flask.Blueprint.record` callbacks.
292+ url_prefix, Blueprint routes will be prefixed with this.
293+ subdomain, Blueprint routes will match on this subdomain.
294+ url_defaults, Blueprint routes will use these default values for view arguments.
295+
290296 """
291297 for tag in api .tags :
292298 if tag .name not in self .tag_names :
@@ -297,20 +303,31 @@ def register_api(self, api: APIBlueprint) -> None:
297303 self .tag_names .append (tag .name )
298304
299305 # Update paths with the APIBlueprint's paths
306+ url_prefix = options .get ("url_prefix" )
307+ if url_prefix and api .url_prefix and url_prefix != api .url_prefix :
308+ api .paths = {url_prefix + k .removeprefix (api .url_prefix ): v for k , v in api .paths .items ()}
309+ elif url_prefix and not api .url_prefix :
310+ api .paths = {url_prefix .rstrip ("/" ) + "/" + k .lstrip ("/" ): v for k , v in api .paths .items ()}
300311 self .paths .update (** api .paths )
301312
302313 # Update component schemas with the APIBlueprint's component schemas
303314 self .components_schemas .update (** api .components_schemas )
304315
305316 # Register the APIBlueprint with the current instance
306- self .register_blueprint (api )
317+ self .register_blueprint (api , ** options )
307318
308- def register_api_view (self , api_view : APIView , view_kwargs : Optional [Dict [Any , Any ]] = None ) -> None :
319+ def register_api_view (
320+ self ,
321+ api_view : APIView ,
322+ url_prefix : Optional [str ] = None ,
323+ view_kwargs : Optional [Dict [Any , Any ]] = None
324+ ) -> None :
309325 """
310326 Register APIView
311327
312328 Args:
313329 api_view: The APIView instance to register.
330+ url_prefix: A path to prepend to all the APIView's urls
314331 view_kwargs: Additional keyword arguments to pass to the API views.
315332 """
316333 if view_kwargs is None :
@@ -326,13 +343,17 @@ def register_api_view(self, api_view: APIView, view_kwargs: Optional[Dict[Any, A
326343 self .tag_names .append (tag .name )
327344
328345 # Update paths with the APIView's paths
346+ if url_prefix and api_view .url_prefix and url_prefix != api_view .url_prefix :
347+ api_view .paths = {url_prefix + k .removeprefix (api_view .url_prefix ): v for k , v in api_view .paths .items ()}
348+ elif url_prefix and not api_view .url_prefix :
349+ api_view .paths = {url_prefix .rstrip ("/" ) + "/" + k .lstrip ("/" ): v for k , v in api_view .paths .items ()}
329350 self .paths .update (** api_view .paths )
330351
331352 # Update component schemas with the APIView's component schemas
332353 self .components_schemas .update (** api_view .components_schemas )
333354
334355 # Register the APIView with the current instance
335- api_view .register (self , view_kwargs = view_kwargs )
356+ api_view .register (self , url_prefix = url_prefix , view_kwargs = view_kwargs )
336357
337358 def _add_url_rule (
338359 self ,
0 commit comments