This is an automated email from the ASF dual-hosted git repository.

kamilbregula pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/master by this push:
     new 880b65a  Use strict API  schemas (#9365)
880b65a is described below

commit 880b65ac29d42a12b385cad490c956e69edeb44e
Author: Kamil BreguĊ‚a <[email protected]>
AuthorDate: Thu Jun 18 14:14:44 2020 +0200

    Use strict API  schemas (#9365)
---
 airflow/api_connexion/schemas/connection_schema.py    |  6 +++---
 airflow/api_connexion/schemas/error_schema.py         |  4 ++--
 airflow/api_connexion/schemas/event_log_schema.py     |  4 ++--
 airflow/api_connexion/schemas/pool_schema.py          |  4 ++--
 airflow/www/extensions/init_views.py                  |  2 +-
 tests/api_connexion/schemas/test_connection_schema.py | 18 ++++++++++++++++--
 6 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/airflow/api_connexion/schemas/connection_schema.py 
b/airflow/api_connexion/schemas/connection_schema.py
index 387dd70..3b603e2 100644
--- a/airflow/api_connexion/schemas/connection_schema.py
+++ b/airflow/api_connexion/schemas/connection_schema.py
@@ -61,6 +61,6 @@ class ConnectionCollectionSchema(Schema):
     total_entries = fields.Int()
 
 
-connection_schema = ConnectionSchema()
-connection_collection_item_schema = ConnectionCollectionItemSchema()
-connection_collection_schema = ConnectionCollectionSchema()
+connection_schema = ConnectionSchema(strict=True)
+connection_collection_item_schema = ConnectionCollectionItemSchema(strict=True)
+connection_collection_schema = ConnectionCollectionSchema(strict=True)
diff --git a/airflow/api_connexion/schemas/error_schema.py 
b/airflow/api_connexion/schemas/error_schema.py
index 172af62..d9fb310 100644
--- a/airflow/api_connexion/schemas/error_schema.py
+++ b/airflow/api_connexion/schemas/error_schema.py
@@ -52,5 +52,5 @@ class ImportErrorCollectionSchema(Schema):
     total_entries = fields.Int()
 
 
-import_error_schema = ImportErrorSchema()
-import_error_collection_schema = ImportErrorCollectionSchema()
+import_error_schema = ImportErrorSchema(strict=True)
+import_error_collection_schema = ImportErrorCollectionSchema(strict=True)
diff --git a/airflow/api_connexion/schemas/event_log_schema.py 
b/airflow/api_connexion/schemas/event_log_schema.py
index b718809..480325e 100644
--- a/airflow/api_connexion/schemas/event_log_schema.py
+++ b/airflow/api_connexion/schemas/event_log_schema.py
@@ -53,5 +53,5 @@ class EventLogCollectionSchema(Schema):
     total_entries = fields.Int()
 
 
-event_log_schema = EventLogSchema()
-event_log_collection_schema = EventLogCollectionSchema()
+event_log_schema = EventLogSchema(strict=True)
+event_log_collection_schema = EventLogCollectionSchema(strict=True)
diff --git a/airflow/api_connexion/schemas/pool_schema.py 
b/airflow/api_connexion/schemas/pool_schema.py
index 6b0722c..a2e1fb0 100644
--- a/airflow/api_connexion/schemas/pool_schema.py
+++ b/airflow/api_connexion/schemas/pool_schema.py
@@ -83,5 +83,5 @@ class PoolCollectionSchema(Schema):
     total_entries = fields.Int()
 
 
-pool_collection_schema = PoolCollectionSchema()
-pool_schema = PoolSchema()
+pool_collection_schema = PoolCollectionSchema(strict=True)
+pool_schema = PoolSchema(strict=True)
diff --git a/airflow/www/extensions/init_views.py 
b/airflow/www/extensions/init_views.py
index 2e5614e..aced827 100644
--- a/airflow/www/extensions/init_views.py
+++ b/airflow/www/extensions/init_views.py
@@ -98,7 +98,7 @@ def init_api_connexion(app: Flask) -> None:
     connexion_app = connexion.App(__name__, specification_dir=spec_dir, 
skip_error_handlers=True)
     connexion_app.app = app
     api_bp = connexion_app.add_api(
-        specification='v1.yaml', base_path='/api/v1', validate_responses=True, 
strict_validation=False
+        specification='v1.yaml', base_path='/api/v1', validate_responses=True, 
strict_validation=True
     ).blueprint
     app.register_error_handler(ProblemException, 
connexion_app.common_error_handler)
     app.extensions['csrf'].exempt(api_bp)
diff --git a/tests/api_connexion/schemas/test_connection_schema.py 
b/tests/api_connexion/schemas/test_connection_schema.py
index a192bb2..5afe1d0 100644
--- a/tests/api_connexion/schemas/test_connection_schema.py
+++ b/tests/api_connexion/schemas/test_connection_schema.py
@@ -14,9 +14,11 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-
+import re
 import unittest
 
+import marshmallow
+
 from airflow.api_connexion.schemas.connection_schema import (
     ConnectionCollection, connection_collection_item_schema, 
connection_collection_schema, connection_schema,
 )
@@ -70,7 +72,8 @@ class TestConnectionCollectionItemSchema(unittest.TestCase):
             'port': 80
         }
         connection_dump_2 = {
-            'connection_id': "mysql_default_2"
+            'connection_id': "mysql_default_2",
+            'conn_type': "postgres",
         }
         result_1 = connection_collection_item_schema.load(connection_dump_1)
         result_2 = connection_collection_item_schema.load(connection_dump_2)
@@ -90,9 +93,20 @@ class TestConnectionCollectionItemSchema(unittest.TestCase):
             result_2[0],
             {
                 'conn_id': "mysql_default_2",
+                'conn_type': "postgres",
             }
         )
 
+    def test_deserialize_required_fields(self):
+        connection_dump_1 = {
+            'connection_id': "mysql_default_2",
+        }
+        with self.assertRaisesRegex(
+            marshmallow.exceptions.ValidationError,
+            re.escape("{'conn_type': ['Missing data for required field.']}")
+        ):
+            connection_collection_item_schema.load(connection_dump_1)
+
 
 class TestConnectionCollectionSchema(unittest.TestCase):
 

Reply via email to