Repository: Qiskit/qiskit

Issue:
Inability to set many=True during schema binding
### Information
`@bind_schema` decorator does not allow passing extra parameters with the schema like `many=True` which results in inability to deserialize a collection of objects.

- **Qiskit Terra version**: 0.8.2
- **Python version**: 3.7.3
- **Operating system**: Darwin Kernel Version 18.7.0

### What is the current behavior?
Any payload with collections gets rejected by model validation.


### Steps to reproduce the problem
Let's define a simple schema and a corresponding model:
```
from qiskit.validation import BaseSchema, BaseModel, bind_schema
from qiskit.validation.fields import String

class TestSchema(BaseSchema):
    test = String(required=True)

@bind_schema(TestSchema)
class TestModel(BaseModel):

    def __init__(self, test, **kwargs):
        self.test = test
```

Then try to deserialize a payload with a collection:
```
from qiskit.validation import ModelValidationError
from test.ibmqtestcase import IBMQTestCase

class Test(IBMQTestCase):

    def test_schema(self):
        payload = [{'test': 'abc'}]
        try:
            result = TestModel.from_dict(payload)
        except ModelValidationError:
            self.fail('Could not deserialize the payload')
        self.assertTrue(isinstance(result, list))
```

### What is the expected behavior?
Ability to pass `many = True` during schema binding, and the payload to be deserialized successfully into a list of `TestModel` objects.


### Suggested solutions
Add `**kwargs` parameters to `@bind_schema` and parse them accordingly.





Discussion:

Resolving patch:
diff --git a/qiskit/validation/base.py b/qiskit/validation/base.py
--- a/qiskit/validation/base.py
+++ b/qiskit/validation/base.py
@@ -166,9 +166,10 @@ def make_model(self, data, **_):
 class _SchemaBinder:
     """Helper class for the parametrized decorator ``bind_schema``."""
 
-    def __init__(self, schema_cls):
+    def __init__(self, schema_cls, **kwargs):
         """Get the schema for the decorated model."""
         self._schema_cls = schema_cls
+        self._kwargs = kwargs
 
     def __call__(self, model_cls):
         """Augment the model class with the validation API.
@@ -184,7 +185,7 @@ def __call__(self, model_cls):
 
         # Set a reference to the Model in the Schema, and vice versa.
         self._schema_cls.model_cls = model_cls
-        model_cls.schema = self._schema_cls()
+        model_cls.schema = self._schema_cls(**self._kwargs)
 
         # Append the methods to the Model class.
         model_cls.__init__ = self._validate_after_init(model_cls.__init__)
@@ -195,7 +196,7 @@ def __call__(self, model_cls):
         return model_cls
 
     @staticmethod
-    def _create_validation_schema(schema_cls):
+    def _create_validation_schema(schema_cls, **kwargs):
         """Create a patched Schema for validating models.
 
         Model validation is not part of Marshmallow. Schemas have a ``validate``
@@ -211,7 +212,7 @@ def _create_validation_schema(schema_cls):
             BaseSchema: a copy of the original Schema, overriding the
                 ``_deserialize()`` call of its fields.
         """
-        validation_schema = schema_cls()
+        validation_schema = schema_cls(**kwargs)
         for _, field in validation_schema.fields.items():
             if isinstance(field, ModelTypeValidator):
                 validate_function = field.__class__.check_type
@@ -246,7 +247,7 @@ def _decorated(self, **kwargs):
         return _decorated
 
 
-def bind_schema(schema):
+def bind_schema(schema, **kwargs):
     """Class decorator for adding schema validation to its instances.
 
     The decorator acts on the model class by adding:
@@ -277,13 +278,18 @@ class AnotherModel(BaseModel):
         instantiation. If ``validate=False`` is passed to the constructor, this
         validation will not be performed.
 
+    Args:
+        schema (class): the schema class used for validation.
+        **kwargs: Additional attributes for the ``marshmallow.Schema``
+            initializer.
+
     Raises:
         ValueError: when trying to bind the same schema more than once.
 
     Return:
         type: the same class with validation capabilities.
     """
-    return _SchemaBinder(schema)
+    return _SchemaBinder(schema, **kwargs)
 
 
 def _base_model_from_kwargs(cls, kwargs):


Test patch:
diff --git a/test/python/validation/test_schemas.py b/test/python/validation/test_schemas.py
--- a/test/python/validation/test_schemas.py
+++ b/test/python/validation/test_schemas.py
@@ -53,3 +53,18 @@ class _AnotherModel(BaseModel):
                 pass
         except ValueError:
             self.fail('`bind_schema` raised while binding.')
+
+    def test_binding_params(self):
+        """Test using parameters in schema binding."""
+        class _DummySchema(BaseSchema):
+            pass
+
+        # Set `many=True` as an example of a marshmallow parameter.
+        @bind_schema(_DummySchema, many=True)
+        class _DummyModel(BaseModel):
+            pass
+
+        # By using `many=True`, the serialization outputs a list.
+        dummy_models = _DummyModel.from_dict([{}])
+        self.assertIsInstance(dummy_models, list)
+        self.assertTrue(all([isinstance(obj, _DummyModel) for obj in dummy_models]))