Repository: getmoto/moto

Issue:
API Gateway missing default for apiKeyRequired when creating resource method
By default when creating a new resource method in API Gateway the apiKeyRequired parameter has a default value of false added by AWS which is missing from moto.

For instance:

```
$ aws apigateway create-rest-api --name jrbeilke-test
{
    "id": "w1wumry1zj",
    "name": "jrbeilke-test",
    "createdDate": 1580323604,
    "apiKeySource": "HEADER",
    "endpointConfiguration": {
        "types": [
            "EDGE"
        ]
    }
}
```

```
$ aws apigateway get-resources --rest-api-id w1wumry1zj
{
    "items": [
        {
            "id": "i0tl35kn71",
            "path": "/"
        }
    ]
}
```

```
$ aws apigateway put-method --rest-api-id w1wumry1zj --resource-id i0tl35kn71 --http-method GET --authorization-type NONE
{
    "httpMethod": "GET",
    "authorizationType": "NONE",
    "apiKeyRequired": false
}
```


Discussion:

Resolving patch:
diff --git a/moto/apigateway/models.py b/moto/apigateway/models.py
--- a/moto/apigateway/models.py
+++ b/moto/apigateway/models.py
@@ -83,14 +83,14 @@ def __init__(self, status_code):
 
 
 class Method(BaseModel, dict):
-    def __init__(self, method_type, authorization_type):
+    def __init__(self, method_type, authorization_type, **kwargs):
         super(Method, self).__init__()
         self.update(
             dict(
                 httpMethod=method_type,
                 authorizationType=authorization_type,
                 authorizerId=None,
-                apiKeyRequired=None,
+                apiKeyRequired=kwargs.get("api_key_required") or False,
                 requestParameters=None,
                 requestModels=None,
                 methodIntegration=None,
@@ -158,8 +158,12 @@ def get_response(self, request):
             )
         return response.status_code, response.text
 
-    def add_method(self, method_type, authorization_type):
-        method = Method(method_type=method_type, authorization_type=authorization_type)
+    def add_method(self, method_type, authorization_type, api_key_required):
+        method = Method(
+            method_type=method_type,
+            authorization_type=authorization_type,
+            api_key_required=api_key_required,
+        )
         self.resource_methods[method_type] = method
         return method
 
@@ -594,9 +598,18 @@ def get_method(self, function_id, resource_id, method_type):
         resource = self.get_resource(function_id, resource_id)
         return resource.get_method(method_type)
 
-    def create_method(self, function_id, resource_id, method_type, authorization_type):
+    def create_method(
+        self,
+        function_id,
+        resource_id,
+        method_type,
+        authorization_type,
+        api_key_required=None,
+    ):
         resource = self.get_resource(function_id, resource_id)
-        method = resource.add_method(method_type, authorization_type)
+        method = resource.add_method(
+            method_type, authorization_type, api_key_required=api_key_required
+        )
         return method
 
     def get_stage(self, function_id, stage_name):
diff --git a/moto/apigateway/responses.py b/moto/apigateway/responses.py
--- a/moto/apigateway/responses.py
+++ b/moto/apigateway/responses.py
@@ -145,8 +145,13 @@ def resource_methods(self, request, full_url, headers):
             return 200, {}, json.dumps(method)
         elif self.method == "PUT":
             authorization_type = self._get_param("authorizationType")
+            api_key_required = self._get_param("apiKeyRequired")
             method = self.backend.create_method(
-                function_id, resource_id, method_type, authorization_type
+                function_id,
+                resource_id,
+                method_type,
+                authorization_type,
+                api_key_required,
             )
             return 200, {}, json.dumps(method)
 


Test patch:
diff --git a/tests/test_apigateway/test_apigateway.py b/tests/test_apigateway/test_apigateway.py
--- a/tests/test_apigateway/test_apigateway.py
+++ b/tests/test_apigateway/test_apigateway.py
@@ -286,6 +286,41 @@ def test_create_method():
         {
             "httpMethod": "GET",
             "authorizationType": "none",
+            "apiKeyRequired": False,
+            "ResponseMetadata": {"HTTPStatusCode": 200},
+        }
+    )
+
+
+@mock_apigateway
+def test_create_method_apikeyrequired():
+    client = boto3.client("apigateway", region_name="us-west-2")
+    response = client.create_rest_api(name="my_api", description="this is my api")
+    api_id = response["id"]
+
+    resources = client.get_resources(restApiId=api_id)
+    root_id = [resource for resource in resources["items"] if resource["path"] == "/"][
+        0
+    ]["id"]
+
+    client.put_method(
+        restApiId=api_id,
+        resourceId=root_id,
+        httpMethod="GET",
+        authorizationType="none",
+        apiKeyRequired=True,
+    )
+
+    response = client.get_method(restApiId=api_id, resourceId=root_id, httpMethod="GET")
+
+    # this is hard to match against, so remove it
+    response["ResponseMetadata"].pop("HTTPHeaders", None)
+    response["ResponseMetadata"].pop("RetryAttempts", None)
+    response.should.equal(
+        {
+            "httpMethod": "GET",
+            "authorizationType": "none",
+            "apiKeyRequired": True,
             "ResponseMetadata": {"HTTPStatusCode": 200},
         }
     )