From d24bbda77f8e462a636b5a4d31b7da9d80b7cfc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lafr=C3=A9choux?= Date: Tue, 7 Jan 2025 12:39:39 +0100 Subject: [PATCH 1/3] Require Marshmallow 3.24 --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3330ef6..b9b9b35 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,7 @@ requires-python = ">=3.9" dependencies = [ "werkzeug>=3.0.1,<4", "flask>=3.0.2,<4", - "marshmallow>=3.18.0,<4", + "marshmallow>=3.24.1,<4", "webargs>=8.0.0,<9", "apispec[marshmallow]>=6.0.0,<7", ] @@ -50,7 +50,7 @@ tests = [ "coverage==7.6.10", "werkzeug==3.1.3", "flask==3.1.0", - "marshmallow==3.23.2", + "marshmallow==3.24.1", "webargs==8.6.0", "apispec==6.8.0", "PyYAML==6.0.2", From 76bd676d39bbdef57d8bfe54df2283018ccc3ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lafr=C3=A9choux?= Date: Tue, 7 Jan 2025 12:40:34 +0100 Subject: [PATCH 2/3] Don't use ordered Meta, schemas are always ordered --- docs/openapi.rst | 18 ++---------------- src/flask_smorest/pagination.py | 4 ---- tests/conftest.py | 1 - 3 files changed, 2 insertions(+), 21 deletions(-) diff --git a/docs/openapi.rst b/docs/openapi.rst index 54213a8..6f752cc 100644 --- a/docs/openapi.rst +++ b/docs/openapi.rst @@ -242,23 +242,9 @@ schema `properties`. Although objects are not ordered in JSON, OpenAPI graphical interfaces tend to respect the order in which the `properties` are defined in the ``properties`` object in the specification file. -When using an ordererd ``Schema``, the fields definition order is preserved -when generating the specification file and the `properties` are displayed in -that order. +``Schema`` classes keep fields in declaration order, and this order is preserved when +generating the specification file: the `properties` are displayed in that order. -This is typically done in a base class: - -.. code-block:: python - :emphasize-lines: 2,3 - - class MyBaseSchema(ma.Schema): - class Meta: - ordered = True - - - class User(MyBaseSchema): - name = ma.fields.String() - surname = ma.fields.String() Serve the OpenAPI Documentation ------------------------------- diff --git a/src/flask_smorest/pagination.py b/src/flask_smorest/pagination.py index f0cbd45..5230a9a 100644 --- a/src/flask_smorest/pagination.py +++ b/src/flask_smorest/pagination.py @@ -59,7 +59,6 @@ class PaginationParametersSchema(ma.Schema): """Deserializes pagination params into PaginationParameters""" class Meta: - ordered = True unknown = ma.EXCLUDE page = ma.fields.Integer( @@ -127,9 +126,6 @@ class PaginationMetadataSchema(ma.Schema): previous_page = ma.fields.Int() next_page = ma.fields.Int() - class Meta: - ordered = True - PAGINATION_HEADER = { "description": "Pagination metadata", diff --git a/tests/conftest.py b/tests/conftest.py index b92c44e..6845129 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -69,7 +69,6 @@ class DocSchema(CounterSchema): class QueryArgsSchema(ma.Schema): class Meta: - ordered = True unknown = ma.EXCLUDE arg1 = ma.fields.String() From ede7234ba5db3cc27f3c289acd222074d10d2aeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lafr=C3=A9choux?= Date: Tue, 7 Jan 2025 12:42:27 +0100 Subject: [PATCH 3/3] Use Raw, not Field --- tests/test_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_api.py b/tests/test_api.py index 2e9fbb6..0ee3e27 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -546,7 +546,7 @@ def dumps(self, obj, **kwargs): return json.dumps(obj, **kwargs, cls=CustomJSONEncoder) class CustomSchema(ma.Schema): - custom_field = ma.fields.Field(load_default=CustomType()) + custom_field = ma.fields.Raw(load_default=CustomType()) app.config["OPENAPI_VERSION"] = openapi_version app.json = CustomJsonProvider(app)