Files
floci/src/main/java/io/github/hectorvent
Allen Sanborn c57b8ff5f6 fix(apigateway): report rootResourceId and the API key defaults (#3269)
* fix(apigateway): report rootResourceId and the API key defaults

GetRestApi, CreateRestApi and GetRestApis returned only id, name, description,
createdDate, apiStatus, tags and endpointConfiguration. Three documented response
members were missing. None of them is ever supplied by the caller, so a client has
no way to obtain them other than from the response.

rootResourceId is the most load bearing. The root resource is created with the API
and is already reachable through GetResources, it was just not reported on the API
itself -- which is where a client reads it in order to parent its first resource:

    resource "aws_api_gateway_resource" "hello" {
      rest_api_id = aws_api_gateway_rest_api.api.id
      parent_id   = aws_api_gateway_rest_api.api.root_resource_id   # was empty
      path_part   = "hello"
    }

apiKeySource and disableExecuteApiEndpoint are reported with the AWS defaults,
HEADER and false. Neither is settable on a REST API here: createRestApi ignores
both and updateRestApi patches only /name and /description, so the emulated value
is always the default. Reporting it beats omitting it, because a client that reads
an absent member back as "" or null sees a difference from the configuration it
just sent and never converges.

Reference: the GetRestApi response syntax and elements, including the sample
response carrying "rootResourceId" --
https://docs.aws.amazon.com/apigateway/latest/api/API_GetRestApi.html
apiKeySource is documented there with valid values HEADER | AUTHORIZER.

Tests assert that the reported rootResourceId is the same id GetResources gives the
"/" resource, and that a resource can actually be created against it.

* fix(apigateway): refuse to delete the root resource of a REST API

Reporting rootResourceId on the API only holds up if the resource at "/" is
still there. deleteResource had no guard, so a caller could delete the root and
leave the API with nothing to report and nothing to parent a new resource on,
a state with no way back short of recreating the API.

The root is created with the API and has no pathPart to address it by; it goes
away when the API does, via deleteRestApi, which cascades through the store and
is unaffected by this. putRestApi already skipped "/" when clearing resources.

The botocore model shipped with awscli 2.36.30 (apigateway/2015-07-09) lists
BadRequestException, httpStatusCode 400, among the errors of DeleteResource,
which settles the error type for a delete the service refuses to carry out. It
does not document the root-resource case either way, so the refusal itself is a
deliberate choice for the reason above rather than verified AWS parity, and the
message is descriptive rather than copied from AWS.

* fix(apigateway): let a vanished API cost only its rootResourceId

ListRestApis renders a snapshot of the APIs and resolves each one's root
afterwards, and that lookup read the API's resources, whose first act is to load
the API itself. An API deleted between the snapshot and the render was therefore
already gone by the time its root was looked up, and the NotFoundException it
raised turned the whole listing into a 404 rather than costing the caller one
member of one item.

The lookup moves into ApiGatewayService.findRootResourceId, which returns an
empty Optional for an API that is no longer there. The tolerance is narrow: only
NotFoundException is caught, every other AwsException still propagates, and
GetRestApi on a missing API is still a 404 because it loads the API directly.
2026-09-08 23:51:05 -05:00
..