We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
JSON validation crash on missing array minItems property
```
  File "/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/pyramid/viewderivers.py", line 147, in _requestonly_view
    response = view(request)
  File "/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/cornice/service.py", line 491, in wrapper
    response = view_()
  File "/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/kinto/core/resource/__init__.py", line 460, in put
    new_record = self.process_record(post_record, old=existing)
  File "/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/kinto/views/records.py", line 66, in process_record
    jsonschema.validate(stripped, schema)
  File "/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/jsonschema/validators.py", line 540, in validate
    cls.check_schema(schema)
  File "/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/jsonschema/validators.py", line 83, in check_schema
    raise SchemaError.create_from(error)
jsonschema.exceptions.SchemaError: [] is too short

Failed validating 'minItems' in schema['properties']['required']:
    {'items': {'type': 'string'},
     'minItems': 1,
     'type': 'array',
     'uniqueItems': True}

On instance['required']:
    []
```
JSON validation crash on missing array minItems property
```
  File "/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/pyramid/viewderivers.py", line 147, in _requestonly_view
    response = view(request)
  File "/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/cornice/service.py", line 491, in wrapper
    response = view_()
  File "/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/kinto/core/resource/__init__.py", line 460, in put
    new_record = self.process_record(post_record, old=existing)
  File "/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/kinto/views/records.py", line 66, in process_record
    jsonschema.validate(stripped, schema)
  File "/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/jsonschema/validators.py", line 540, in validate
    cls.check_schema(schema)
  File "/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/jsonschema/validators.py", line 83, in check_schema
    raise SchemaError.create_from(error)
jsonschema.exceptions.SchemaError: [] is too short

Failed validating 'minItems' in schema['properties']['required']:
    {'items': {'type': 'string'},
     'minItems': 1,
     'type': 'array',
     'uniqueItems': True}

On instance['required']:
    []
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `kinto/views/records.py`
Content:
```
1 import copy
2 
3 import jsonschema
4 from kinto.core import resource, utils
5 from kinto.core.errors import raise_invalid
6 from jsonschema import exceptions as jsonschema_exceptions
7 from pyramid.security import Authenticated
8 from pyramid.settings import asbool
9 
10 from kinto.views import object_exists_or_404
11 
12 
13 _parent_path = '/buckets/{{bucket_id}}/collections/{{collection_id}}'
14 
15 
16 @resource.register(name='record',
17                    collection_path=_parent_path + '/records',
18                    record_path=_parent_path + '/records/{{id}}')
19 class Record(resource.ShareableResource):
20 
21     schema_field = 'schema'
22 
23     def __init__(self, request, **kwargs):
24         # Before all, first check that the parent collection exists.
25         # Check if already fetched before (in batch).
26         collections = request.bound_data.setdefault('collections', {})
27         collection_uri = self.get_parent_id(request)
28         if collection_uri not in collections:
29             # Unknown yet, fetch from storage.
30             collection_parent_id = utils.instance_uri(request, 'bucket',
31                                                       id=self.bucket_id)
32             collection = object_exists_or_404(request,
33                                               collection_id='collection',
34                                               parent_id=collection_parent_id,
35                                               object_id=self.collection_id)
36             collections[collection_uri] = collection
37 
38         super().__init__(request, **kwargs)
39         self._collection = collections[collection_uri]
40 
41     def get_parent_id(self, request):
42         self.bucket_id = request.matchdict['bucket_id']
43         self.collection_id = request.matchdict['collection_id']
44         return utils.instance_uri(request, 'collection',
45                                   bucket_id=self.bucket_id,
46                                   id=self.collection_id)
47 
48     def process_record(self, new, old=None):
49         """Validate records against collection schema, if any."""
50         new = super().process_record(new, old)
51 
52         schema = self._collection.get('schema')
53         settings = self.request.registry.settings
54         schema_validation = 'experimental_collection_schema_validation'
55         if not schema or not asbool(settings.get(schema_validation)):
56             return new
57 
58         collection_timestamp = self._collection[self.model.modified_field]
59 
60         try:
61             stripped = copy.deepcopy(new)
62             stripped.pop(self.model.id_field, None)
63             stripped.pop(self.model.modified_field, None)
64             stripped.pop(self.model.permissions_field, None)
65             stripped.pop(self.schema_field, None)
66             jsonschema.validate(stripped, schema)
67         except jsonschema_exceptions.ValidationError as e:
68             try:
69                 field = e.path.pop() if e.path else e.validator_value.pop()
70             except AttributeError:
71                 field = None
72             raise_invalid(self.request, name=field, description=e.message)
73 
74         new[self.schema_field] = collection_timestamp
75         return new
76 
77     def collection_get(self):
78         result = super().collection_get()
79         self._handle_cache_expires(self.request.response)
80         return result
81 
82     def get(self):
83         result = super().get()
84         self._handle_cache_expires(self.request.response)
85         return result
86 
87     def _handle_cache_expires(self, response):
88         """If the parent collection defines a ``cache_expires`` attribute,
89         then cache-control response headers are sent.
90 
91         .. note::
92 
93             Those headers are also sent if the
94             ``kinto.record_cache_expires_seconds`` setting is defined.
95         """
96         is_anonymous = Authenticated not in self.request.effective_principals
97         if not is_anonymous:
98             return
99 
100         cache_expires = self._collection.get('cache_expires')
101         if cache_expires is None:
102             by_bucket = '{}_record_cache_expires_seconds'.format(self.bucket_id)
103             by_collection = '{}_{}_record_cache_expires_seconds'.format(
104                 self.bucket_id, self.collection_id)
105             settings = self.request.registry.settings
106             cache_expires = settings.get(by_collection,
107                                          settings.get(by_bucket))
108 
109         if cache_expires is not None:
110             response.cache_expires(seconds=int(cache_expires))
111
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/kinto/views/records.py b/kinto/views/records.py
--- a/kinto/views/records.py
+++ b/kinto/views/records.py
@@ -65,10 +65,10 @@
             stripped.pop(self.schema_field, None)
             jsonschema.validate(stripped, schema)
         except jsonschema_exceptions.ValidationError as e:
-            try:
-                field = e.path.pop() if e.path else e.validator_value.pop()
-            except AttributeError:
-                field = None
+            if e.validator_value:
+                field = e.validator_value[-1]
+            else:
+                field = e.schema_path[-1]
             raise_invalid(self.request, name=field, description=e.message)
 
         new[self.schema_field] = collection_timestamp

{"golden_diff": "diff --git a/kinto/views/records.py b/kinto/views/records.py\n--- a/kinto/views/records.py\n+++ b/kinto/views/records.py\n@@ -65,10 +65,10 @@\n             stripped.pop(self.schema_field, None)\n             jsonschema.validate(stripped, schema)\n         except jsonschema_exceptions.ValidationError as e:\n-            try:\n-                field = e.path.pop() if e.path else e.validator_value.pop()\n-            except AttributeError:\n-                field = None\n+            if e.validator_value:\n+                field = e.validator_value[-1]\n+            else:\n+                field = e.schema_path[-1]\n             raise_invalid(self.request, name=field, description=e.message)\n \n         new[self.schema_field] = collection_timestamp\n", "issue": "JSON validation crash on missing array minItems property\n```\r\n  File \"/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/pyramid/viewderivers.py\", line 147, in _requestonly_view\r\n    response = view(request)\r\n  File \"/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/cornice/service.py\", line 491, in wrapper\r\n    response = view_()\r\n  File \"/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/kinto/core/resource/__init__.py\", line 460, in put\r\n    new_record = self.process_record(post_record, old=existing)\r\n  File \"/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/kinto/views/records.py\", line 66, in process_record\r\n    jsonschema.validate(stripped, schema)\r\n  File \"/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/jsonschema/validators.py\", line 540, in validate\r\n    cls.check_schema(schema)\r\n  File \"/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/jsonschema/validators.py\", line 83, in check_schema\r\n    raise SchemaError.create_from(error)\r\njsonschema.exceptions.SchemaError: [] is too short\r\n\r\nFailed validating 'minItems' in schema['properties']['required']:\r\n    {'items': {'type': 'string'},\r\n     'minItems': 1,\r\n     'type': 'array',\r\n     'uniqueItems': True}\r\n\r\nOn instance['required']:\r\n    []\r\n```\nJSON validation crash on missing array minItems property\n```\r\n  File \"/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/pyramid/viewderivers.py\", line 147, in _requestonly_view\r\n    response = view(request)\r\n  File \"/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/cornice/service.py\", line 491, in wrapper\r\n    response = view_()\r\n  File \"/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/kinto/core/resource/__init__.py\", line 460, in put\r\n    new_record = self.process_record(post_record, old=existing)\r\n  File \"/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/kinto/views/records.py\", line 66, in process_record\r\n    jsonschema.validate(stripped, schema)\r\n  File \"/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/jsonschema/validators.py\", line 540, in validate\r\n    cls.check_schema(schema)\r\n  File \"/home/ubuntu/venvs/kinto/local/lib/python3.5/site-packages/jsonschema/validators.py\", line 83, in check_schema\r\n    raise SchemaError.create_from(error)\r\njsonschema.exceptions.SchemaError: [] is too short\r\n\r\nFailed validating 'minItems' in schema['properties']['required']:\r\n    {'items': {'type': 'string'},\r\n     'minItems': 1,\r\n     'type': 'array',\r\n     'uniqueItems': True}\r\n\r\nOn instance['required']:\r\n    []\r\n```\n", "before_files": [{"content": "import copy\n\nimport jsonschema\nfrom kinto.core import resource, utils\nfrom kinto.core.errors import raise_invalid\nfrom jsonschema import exceptions as jsonschema_exceptions\nfrom pyramid.security import Authenticated\nfrom pyramid.settings import asbool\n\nfrom kinto.views import object_exists_or_404\n\n\n_parent_path = '/buckets/{{bucket_id}}/collections/{{collection_id}}'\n\n\n@resource.register(name='record',\n                   collection_path=_parent_path + '/records',\n                   record_path=_parent_path + '/records/{{id}}')\nclass Record(resource.ShareableResource):\n\n    schema_field = 'schema'\n\n    def __init__(self, request, **kwargs):\n        # Before all, first check that the parent collection exists.\n        # Check if already fetched before (in batch).\n        collections = request.bound_data.setdefault('collections', {})\n        collection_uri = self.get_parent_id(request)\n        if collection_uri not in collections:\n            # Unknown yet, fetch from storage.\n            collection_parent_id = utils.instance_uri(request, 'bucket',\n                                                      id=self.bucket_id)\n            collection = object_exists_or_404(request,\n                                              collection_id='collection',\n                                              parent_id=collection_parent_id,\n                                              object_id=self.collection_id)\n            collections[collection_uri] = collection\n\n        super().__init__(request, **kwargs)\n        self._collection = collections[collection_uri]\n\n    def get_parent_id(self, request):\n        self.bucket_id = request.matchdict['bucket_id']\n        self.collection_id = request.matchdict['collection_id']\n        return utils.instance_uri(request, 'collection',\n                                  bucket_id=self.bucket_id,\n                                  id=self.collection_id)\n\n    def process_record(self, new, old=None):\n        \"\"\"Validate records against collection schema, if any.\"\"\"\n        new = super().process_record(new, old)\n\n        schema = self._collection.get('schema')\n        settings = self.request.registry.settings\n        schema_validation = 'experimental_collection_schema_validation'\n        if not schema or not asbool(settings.get(schema_validation)):\n            return new\n\n        collection_timestamp = self._collection[self.model.modified_field]\n\n        try:\n            stripped = copy.deepcopy(new)\n            stripped.pop(self.model.id_field, None)\n            stripped.pop(self.model.modified_field, None)\n            stripped.pop(self.model.permissions_field, None)\n            stripped.pop(self.schema_field, None)\n            jsonschema.validate(stripped, schema)\n        except jsonschema_exceptions.ValidationError as e:\n            try:\n                field = e.path.pop() if e.path else e.validator_value.pop()\n            except AttributeError:\n                field = None\n            raise_invalid(self.request, name=field, description=e.message)\n\n        new[self.schema_field] = collection_timestamp\n        return new\n\n    def collection_get(self):\n        result = super().collection_get()\n        self._handle_cache_expires(self.request.response)\n        return result\n\n    def get(self):\n        result = super().get()\n        self._handle_cache_expires(self.request.response)\n        return result\n\n    def _handle_cache_expires(self, response):\n        \"\"\"If the parent collection defines a ``cache_expires`` attribute,\n        then cache-control response headers are sent.\n\n        .. note::\n\n            Those headers are also sent if the\n            ``kinto.record_cache_expires_seconds`` setting is defined.\n        \"\"\"\n        is_anonymous = Authenticated not in self.request.effective_principals\n        if not is_anonymous:\n            return\n\n        cache_expires = self._collection.get('cache_expires')\n        if cache_expires is None:\n            by_bucket = '{}_record_cache_expires_seconds'.format(self.bucket_id)\n            by_collection = '{}_{}_record_cache_expires_seconds'.format(\n                self.bucket_id, self.collection_id)\n            settings = self.request.registry.settings\n            cache_expires = settings.get(by_collection,\n                                         settings.get(by_bucket))\n\n        if cache_expires is not None:\n            response.cache_expires(seconds=int(cache_expires))\n", "path": "kinto/views/records.py"}], "after_files": [{"content": "import copy\n\nimport jsonschema\nfrom kinto.core import resource, utils\nfrom kinto.core.errors import raise_invalid\nfrom jsonschema import exceptions as jsonschema_exceptions\nfrom pyramid.security import Authenticated\nfrom pyramid.settings import asbool\n\nfrom kinto.views import object_exists_or_404\n\n\n_parent_path = '/buckets/{{bucket_id}}/collections/{{collection_id}}'\n\n\n@resource.register(name='record',\n                   collection_path=_parent_path + '/records',\n                   record_path=_parent_path + '/records/{{id}}')\nclass Record(resource.ShareableResource):\n\n    schema_field = 'schema'\n\n    def __init__(self, request, **kwargs):\n        # Before all, first check that the parent collection exists.\n        # Check if already fetched before (in batch).\n        collections = request.bound_data.setdefault('collections', {})\n        collection_uri = self.get_parent_id(request)\n        if collection_uri not in collections:\n            # Unknown yet, fetch from storage.\n            collection_parent_id = utils.instance_uri(request, 'bucket',\n                                                      id=self.bucket_id)\n            collection = object_exists_or_404(request,\n                                              collection_id='collection',\n                                              parent_id=collection_parent_id,\n                                              object_id=self.collection_id)\n            collections[collection_uri] = collection\n\n        super().__init__(request, **kwargs)\n        self._collection = collections[collection_uri]\n\n    def get_parent_id(self, request):\n        self.bucket_id = request.matchdict['bucket_id']\n        self.collection_id = request.matchdict['collection_id']\n        return utils.instance_uri(request, 'collection',\n                                  bucket_id=self.bucket_id,\n                                  id=self.collection_id)\n\n    def process_record(self, new, old=None):\n        \"\"\"Validate records against collection schema, if any.\"\"\"\n        new = super().process_record(new, old)\n\n        schema = self._collection.get('schema')\n        settings = self.request.registry.settings\n        schema_validation = 'experimental_collection_schema_validation'\n        if not schema or not asbool(settings.get(schema_validation)):\n            return new\n\n        collection_timestamp = self._collection[self.model.modified_field]\n\n        try:\n            stripped = copy.deepcopy(new)\n            stripped.pop(self.model.id_field, None)\n            stripped.pop(self.model.modified_field, None)\n            stripped.pop(self.model.permissions_field, None)\n            stripped.pop(self.schema_field, None)\n            jsonschema.validate(stripped, schema)\n        except jsonschema_exceptions.ValidationError as e:\n            if e.validator_value:\n                field = e.validator_value[-1]\n            else:\n                field = e.schema_path[-1]\n            raise_invalid(self.request, name=field, description=e.message)\n\n        new[self.schema_field] = collection_timestamp\n        return new\n\n    def collection_get(self):\n        result = super().collection_get()\n        self._handle_cache_expires(self.request.response)\n        return result\n\n    def get(self):\n        result = super().get()\n        self._handle_cache_expires(self.request.response)\n        return result\n\n    def _handle_cache_expires(self, response):\n        \"\"\"If the parent collection defines a ``cache_expires`` attribute,\n        then cache-control response headers are sent.\n\n        .. note::\n\n            Those headers are also sent if the\n            ``kinto.record_cache_expires_seconds`` setting is defined.\n        \"\"\"\n        is_anonymous = Authenticated not in self.request.effective_principals\n        if not is_anonymous:\n            return\n\n        cache_expires = self._collection.get('cache_expires')\n        if cache_expires is None:\n            by_bucket = '{}_record_cache_expires_seconds'.format(self.bucket_id)\n            by_collection = '{}_{}_record_cache_expires_seconds'.format(\n                self.bucket_id, self.collection_id)\n            settings = self.request.registry.settings\n            cache_expires = settings.get(by_collection,\n                                         settings.get(by_bucket))\n\n        if cache_expires is not None:\n            response.cache_expires(seconds=int(cache_expires))\n", "path": "kinto/views/records.py"}]}