|
9 | 9 | import re |
10 | 10 | import six |
11 | 11 | import sys |
| 12 | +import warnings |
12 | 13 |
|
13 | 14 | from collections import OrderedDict |
14 | 15 | from functools import wraps, partial |
@@ -143,10 +144,10 @@ def __init__( |
143 | 144 | self._default_error_handler = None |
144 | 145 | self.tags = tags or [] |
145 | 146 |
|
146 | | - self.error_handlers = { |
| 147 | + self.error_handlers = OrderedDict({ |
147 | 148 | ParseError: mask_parse_error_handler, |
148 | 149 | MaskError: mask_error_handler, |
149 | | - } |
| 150 | + }) |
150 | 151 | self._schema = None |
151 | 152 | self.models = {} |
152 | 153 | self._refresolver = None |
@@ -219,6 +220,7 @@ def init_app(self, app, **kwargs): |
219 | 220 | else: |
220 | 221 | self.blueprint = app |
221 | 222 |
|
| 223 | + |
222 | 224 | def _init_app(self, app): |
223 | 225 | """ |
224 | 226 | Perform initialization actions with the given :class:`flask.Flask` object. |
@@ -250,6 +252,16 @@ def _init_app(self, app): |
250 | 252 | app.config.setdefault("RESTX_MASK_SWAGGER", True) |
251 | 253 | app.config.setdefault("RESTX_INCLUDE_ALL_MODELS", False) |
252 | 254 |
|
| 255 | + # check for deprecated config variable names |
| 256 | + if "ERROR_404_HELP" in app.config: |
| 257 | + app.config['RESTX_ERROR_404_HELP'] = app.config['ERROR_404_HELP'] |
| 258 | + warnings.warn( |
| 259 | + "'ERROR_404_HELP' config setting is deprecated and will be " |
| 260 | + "removed in the future. Use 'RESTX_ERROR_404_HELP' instead.", |
| 261 | + DeprecationWarning |
| 262 | + ) |
| 263 | + |
| 264 | + |
253 | 265 | def __getattr__(self, name): |
254 | 266 | try: |
255 | 267 | return getattr(self.default_namespace, name) |
@@ -503,11 +515,11 @@ def endpoint(self, name): |
503 | 515 | @property |
504 | 516 | def specs_url(self): |
505 | 517 | """ |
506 | | - The Swagger specifications absolute url (ie. `swagger.json`) |
| 518 | + The Swagger specifications relative url (ie. `swagger.json`) |
507 | 519 |
|
508 | 520 | :rtype: str |
509 | 521 | """ |
510 | | - return url_for(self.endpoint("specs"), _external=True) |
| 522 | + return url_for(self.endpoint("specs")) |
511 | 523 |
|
512 | 524 | @property |
513 | 525 | def base_url(self): |
@@ -547,7 +559,7 @@ def __schema__(self): |
547 | 559 |
|
548 | 560 | @property |
549 | 561 | def _own_and_child_error_handlers(self): |
550 | | - rv = {} |
| 562 | + rv = OrderedDict() |
551 | 563 | rv.update(self.error_handlers) |
552 | 564 | for ns in self.namespaces: |
553 | 565 | for exception, handler in six.iteritems(ns.error_handlers): |
@@ -709,7 +721,7 @@ def handle_error(self, e): |
709 | 721 |
|
710 | 722 | elif ( |
711 | 723 | code == HTTPStatus.NOT_FOUND |
712 | | - and current_app.config.get("ERROR_404_HELP", True) |
| 724 | + and current_app.config.get("RESTX_ERROR_404_HELP", True) |
713 | 725 | and include_message_in_response |
714 | 726 | ): |
715 | 727 | data["message"] = self._help_on_404(data.get("message", None)) |
|
0 commit comments