Skip to content

Commit

Permalink
add rootResourceId to RestAPI responses
Browse files Browse the repository at this point in the history
  • Loading branch information
mattheidelbaugh committed Sep 12, 2024
1 parent d1b97ff commit da751c5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions moto/apigateway/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,7 @@ class RestAPI(CloudFormationModel):
PROP_POLICY = "policy"
PROP_DISABLE_EXECUTE_API_ENDPOINT = "disableExecuteApiEndpoint"
PROP_MINIMUM_COMPRESSION_SIZE = "minimumCompressionSize"
PROP_ROOT_RESOURCE_ID = "rootResourceId"

# operations
OPERATION_ADD = "add"
Expand Down Expand Up @@ -1065,6 +1066,7 @@ def __init__(
self.models: Dict[str, Model] = {}
self.request_validators: Dict[str, RequestValidator] = {}
self.default = self.add_child("/") # Add default child
self.root_resource_id = self.default.id

def __repr__(self) -> str:
return str(self.id)
Expand All @@ -1083,6 +1085,7 @@ def to_dict(self) -> Dict[str, Any]:
self.PROP_POLICY: self.policy,
self.PROP_DISABLE_EXECUTE_API_ENDPOINT: self.disableExecuteApiEndpoint,
self.PROP_MINIMUM_COMPRESSION_SIZE: self.minimum_compression_size,
self.PROP_ROOT_RESOURCE_ID: self.root_resource_id,
}

def apply_patch_operations(self, patch_operations: List[Dict[str, Any]]) -> None:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_apigateway/test_apigateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def test_create_and_get_rest_api():
name="my_api", description="this is my api", disableExecuteApiEndpoint=True
)
api_id = response["id"]
root_resource_id = response["rootResourceId"]

response = client.get_rest_api(restApiId=api_id)

Expand All @@ -34,6 +35,7 @@ def test_create_and_get_rest_api():
"endpointConfiguration": {"types": ["EDGE"]},
"tags": {},
"disableExecuteApiEndpoint": True,
"rootResourceId": root_resource_id,
}


Expand All @@ -42,6 +44,7 @@ def test_update_rest_api():
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"]
root_resource_id = response["rootResourceId"]
patchOperations = [
{"op": "replace", "path": "/name", "value": "new-name"},
{"op": "replace", "path": "/description", "value": "new-description"},
Expand Down Expand Up @@ -71,6 +74,7 @@ def test_update_rest_api():
"endpointConfiguration": {"types": ["EDGE"]},
"tags": {},
"disableExecuteApiEndpoint": True,
"rootResourceId": root_resource_id,
}
# should fail with wrong apikeysoruce
patchOperations = [
Expand Down

0 comments on commit da751c5

Please sign in to comment.