Skip to content

Commit

Permalink
Merge 4231847 into 3da9017
Browse files Browse the repository at this point in the history
  • Loading branch information
SteadBytes authored Jan 13, 2020
2 parents 3da9017 + 4231847 commit 4dea45c
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 22 deletions.
4 changes: 2 additions & 2 deletions doc/mask.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Flask-RESTX support partial object fetching (aka. fields mask)
by supplying a custom header in the request.

By default the header is ``X-Fields``
but it can be changed with the ``RESTPLUS_MASK_HEADER`` parameter.
but it can be changed with the ``RESTX_MASK_HEADER`` parameter.

Syntax
------
Expand Down Expand Up @@ -65,7 +65,7 @@ The header will be exposed as a Swagger parameter each time you use the

As Swagger does not permit exposing a global header once
it can make your Swagger specifications a lot more verbose.
You can disable this behavior by setting ``RESTPLUS_MASK_SWAGGER`` to ``False``.
You can disable this behavior by setting ``RESTX_MASK_SWAGGER`` to ``False``.

You can also specify a default mask that will be applied if no header mask is found.

Expand Down
4 changes: 2 additions & 2 deletions doc/swagger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ The ``@api.expect()`` decorator
The ``@api.expect()`` decorator allows you to specify the expected input fields.
It accepts an optional boolean parameter ``validate`` indicating whether the payload should be validated.
The validation behavior can be customized globally either
by setting the ``RESTPLUS_VALIDATE`` configuration to ``True``
by setting the ``RESTX_VALIDATE`` configuration to ``True``
or passing ``validate=True`` to the API constructor.

The following examples are equivalent:
Expand Down Expand Up @@ -215,7 +215,7 @@ An example of application-wide validation by config:

.. code-block:: python
app.config['RESTPLUS_VALIDATE'] = True
app.config['RESTX_VALIDATE'] = True
api = Api(app)
Expand Down
6 changes: 3 additions & 3 deletions flask_restx/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ def _init_app(self, app):
self._configure_namespace_logger(app, ns)

self._register_apidoc(app)
self._validate = self._validate if self._validate is not None else app.config.get('RESTPLUS_VALIDATE', False)
app.config.setdefault('RESTPLUS_MASK_HEADER', 'X-Fields')
app.config.setdefault('RESTPLUS_MASK_SWAGGER', True)
self._validate = self._validate if self._validate is not None else app.config.get('RESTX_VALIDATE', False)
app.config.setdefault('RESTX_MASK_HEADER', 'X-Fields')
app.config.setdefault('RESTX_MASK_SWAGGER', True)

def __getattr__(self, name):
try:
Expand Down
2 changes: 1 addition & 1 deletion flask_restx/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def wrapper(*args, **kwargs):
resp = f(*args, **kwargs)
mask = self.mask
if has_app_context():
mask_header = current_app.config['RESTPLUS_MASK_HEADER']
mask_header = current_app.config['RESTX_MASK_HEADER']
mask = request.headers.get(mask_header) or mask
if isinstance(resp, tuple):
data, code, headers = unpack(resp)
Expand Down
2 changes: 1 addition & 1 deletion flask_restx/representations.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def output_json(data, code, headers=None):
'''Makes a Flask response with a JSON encoded body'''

settings = current_app.config.get('RESTPLUS_JSON', {})
settings = current_app.config.get('RESTX_JSON', {})

# If we're in debug mode, and the indent is not set, we set it to a
# reasonable value here. Note that this won't override any existing value
Expand Down
2 changes: 1 addition & 1 deletion flask_restx/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class Resource(MethodView):
'''
Represents an abstract RESTPlus resource.
Represents an abstract RESTX resource.
Concrete resources should extend from this class
and expose methods for each supported HTTP method.
Expand Down
4 changes: 2 additions & 2 deletions flask_restx/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,9 @@ def parameters_for(self, doc):

# Handle fields mask
mask = doc.get('__mask__')
if (mask and current_app.config['RESTPLUS_MASK_SWAGGER']):
if (mask and current_app.config['RESTX_MASK_SWAGGER']):
param = {
'name': current_app.config['RESTPLUS_MASK_HEADER'],
'name': current_app.config['RESTX_MASK_HEADER'],
'in': 'header',
'type': 'string',
'format': 'mask',
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def post_json(self, url, data, status=200, **kwargs):
return json.loads(response.data.decode('utf8'))

def get_specs(self, prefix='', status=200, **kwargs):
'''Get a Swagger specification for a RestPlus API'''
'''Get a Swagger specification for a RESTX API'''
return self.get_json('{0}/swagger.json'.format(prefix), status=status, **kwargs)


Expand Down
10 changes: 6 additions & 4 deletions tests/legacy/test_api_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,11 @@ def test_exception_header_forwarding_doesnt_duplicate_headers(self, api):

def test_read_json_settings_from_config(self, app, client):
class TestConfig(object):
RESTPLUS_JSON = {'indent': 2,
'sort_keys': True,
'separators': (', ', ': ')}
RESTX_JSON = {
'indent': 2,
'sort_keys': True,
'separators': (', ', ': ')
}

app.config.from_object(TestConfig)
api = restx.Api(app)
Expand All @@ -343,7 +345,7 @@ def default(self, obj):
return 'cabbage'

class TestConfig(object):
RESTPLUS_JSON = {'cls': CabageEncoder}
RESTX_JSON = {'cls': CabageEncoder}

app.config.from_object(TestConfig)
api = restx.Api(app)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_fields_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ def get(self):
'boolean': True
}

app.config['RESTPLUS_MASK_HEADER'] = 'X-Mask'
app.config['RESTX_MASK_HEADER'] = 'X-Mask'
data = client.get_json('/test/', headers={'X-Mask': '{name,age}'})

assert data == {'name': 'John Doe', 'age': 42}
Expand Down Expand Up @@ -963,7 +963,7 @@ def get(self):
'boolean': True
}

app.config['RESTPLUS_MASK_HEADER'] = 'X-Mask'
app.config['RESTX_MASK_HEADER'] = 'X-Mask'
specs = client.get_specs()

op = specs['paths']['/test/']['get']
Expand Down Expand Up @@ -992,7 +992,7 @@ def get(self):
'boolean': True
}

app.config['RESTPLUS_MASK_SWAGGER'] = False
app.config['RESTX_MASK_SWAGGER'] = False
specs = client.get_specs()

op = specs['paths']['/test/']['get']
Expand Down
4 changes: 2 additions & 2 deletions tests/test_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_format_checker_object_on_constructor(self, app, client):
assert 'ipv4' in out['errors']['ip']

def test_validation_false_in_config(self, app, client):
app.config['RESTPLUS_VALIDATE'] = False
app.config['RESTX_VALIDATE'] = False
api = restx.Api(app)

fields = api.model('Person', {
Expand All @@ -132,7 +132,7 @@ def post(self):
assert out == {}

def test_validation_in_config(self, app, client):
app.config['RESTPLUS_VALIDATE'] = True
app.config['RESTX_VALIDATE'] = True
api = restx.Api(app)

fields = api.model('Person', {
Expand Down

0 comments on commit 4dea45c

Please sign in to comment.