Skip to content

Commit b0da8dc

Browse files
authored
Merge branch 'master' into fix-integer-index
2 parents d650d2f + c6b43ba commit b0da8dc

5 files changed

Lines changed: 57 additions & 10 deletions

File tree

doc/index.rst

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,36 @@
44
contain the root `toctree` directive.
55
66
Welcome to Flask-RESTX's documentation!
7-
==========================================
7+
=======================================
88

99
Flask-RESTX is an extension for Flask that adds support for quickly building REST APIs.
1010
Flask-RESTX encourages best practices with minimal setup.
1111
If you are familiar with Flask, Flask-RESTX should be easy to pick up.
1212
It provides a coherent collection of decorators and tools to describe your API
1313
and expose its documentation properly (using Swagger).
1414

15+
Flask-RESTX is a community driven fork of `Flask-RESTPlus
16+
<https://github.com/noirbizarre/flask-restplus>`_
17+
18+
19+
Why did we fork?
20+
================
21+
22+
The community has decided to fork the project due to lack of response from the
23+
original author @noirbizarre. We have been discussing this eventuality for
24+
`a long time <https://github.com/noirbizarre/flask-restplus/issues/593>`_.
25+
26+
Things evolved a bit since that discussion and a few of us have been granted
27+
maintainers access to the github project, but only the original author has
28+
access rights on the PyPi project. As such, we been unable to make any actual
29+
releases. To prevent this project from dying out, we have forked it to continue
30+
development and to support our users.
31+
1532

1633
Compatibility
1734
=============
1835

19-
flask-restx requires Python 2.7+.
36+
flask-restx requires Python 2.7+ or 3.4+.
2037

2138

2239
Installation

doc/quickstart.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,29 @@ and that you have already installed both Flask and Flask-RESTX.
1010
If not, then follow the steps in the :ref:`installation` section.
1111

1212

13+
Migrate from Flask-RESTPlus
14+
---------------------------
15+
16+
.. warning:: The *migration* commands provided below are for illustration
17+
purposes.
18+
You may need to adapt them to properly fit your needs.
19+
We also recommend you make a backup of your project prior running them.
20+
21+
At this point, Flask-RESTX remains 100% compatible with Flask-RESTPlus' API.
22+
All you need to do is update your requirements to use Flask-RESTX instead of
23+
Flask-RESTPlus. Then you need to update all your imports.
24+
This can be done using something like:
25+
26+
::
27+
find . -type f -name "*.py" | xargs sed -i "s/flask_restplus/flask_restx/g"
28+
29+
Finally, you will need to update your configuration options (described `here
30+
<quickstart.html#configuration>`_). Example:
31+
32+
::
33+
find . -type f -name "*.py" | xargs sed -i "s/RESTPLUS_/RESTX_/g"
34+
35+
1336
Initialization
1437
--------------
1538

doc/swagger.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,14 +536,13 @@ For ``POST`` and ``PUT`` methods, use the ``body`` keyword argument to specify t
536536

537537
.. code-block:: python
538538
539-
fields = api.model('MyModel', {
539+
my_model = api.model('MyModel', {
540540
'name': fields.String(description='The name', required=True),
541541
'type': fields.String(description='The object type', enum=['A', 'B']),
542542
'age': fields.Integer(min=0),
543543
})
544544
545545
546-
@api.model(fields={'name': fields.String, 'age': fields.Integer})
547546
class Person(fields.Raw):
548547
def format(self, value):
549548
return {'name': value.name, 'age': value.age}
@@ -552,11 +551,11 @@ For ``POST`` and ``PUT`` methods, use the ``body`` keyword argument to specify t
552551
@api.route('/my-resource/<id>', endpoint='my-resource')
553552
@api.doc(params={'id': 'An ID'})
554553
class MyResource(Resource):
555-
@api.doc(model=fields)
554+
@api.doc(model=my_model)
556555
def get(self, id):
557556
return {}
558557
559-
@api.doc(model='MyModel', body=Person)
558+
@api.doc(model=my_model, body=Person)
560559
def post(self, id):
561560
return {}
562561

flask_restx/fields.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def format(self, value):
468468
if value is None:
469469
return self.default
470470
return int(value)
471-
except ValueError as ve:
471+
except (ValueError, TypeError) as ve:
472472
raise MarshallingError(ve)
473473

474474

@@ -482,7 +482,7 @@ class Float(NumberMixin, Raw):
482482
def format(self, value):
483483
try:
484484
return float(value)
485-
except ValueError as ve:
485+
except (ValueError, TypeError) as ve:
486486
raise MarshallingError(ve)
487487

488488

tests/test_fields.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,14 @@ def test_with_default(self):
276276
def test_value(self, value, expected):
277277
self.assert_field(fields.Integer(), value, expected)
278278

279-
def test_decode_error(self):
279+
def test_decode_error_on_invalid_value(self):
280280
field = fields.Integer()
281281
self.assert_field_raises(field, "an int")
282282

283+
def test_decode_error_on_invalid_type(self):
284+
field = fields.Integer()
285+
self.assert_field_raises(field, {"a": "dict"})
286+
283287

284288
class BooleanFieldTest(BaseFieldTestMixin, FieldTestCase):
285289
field_class = fields.Boolean
@@ -330,10 +334,14 @@ def test_value(self, value, expected):
330334
def test_raises(self):
331335
self.assert_field_raises(fields.Float(), "bar")
332336

333-
def test_decode_error(self):
337+
def test_decode_error_on_invalid_value(self):
334338
field = fields.Float()
335339
self.assert_field_raises(field, "not a float")
336340

341+
def test_decode_error_on_invalid_type(self):
342+
field = fields.Float()
343+
self.assert_field_raises(field, {"a": "dict"})
344+
337345

338346
PI_STR = (
339347
"3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117"

0 commit comments

Comments
 (0)