fix(apigateway): return the full integration configuration on read-back (#3432)

GetIntegration returned only type, httpMethod, uri and passthroughBehavior,
and GetIntegrationResponse only statusCode and selectionPattern. The mapping
configuration Floci stores and honours at invoke time - requestParameters,
requestTemplates, integrationResponses, responseParameters and
responseTemplates - was never returned, so infrastructure-as-code tools that
diff against these reads saw it as absent and reported drift that never
converged.

Three further corrections in the same area:

- UpdateStage stored method settings under the JSON-Pointer-escaped resource
  path ("~1pets/GET"), so the escaped spelling AWS sends produced a key that
  nothing could look up. Both spellings now normalise onto "pets/GET", which
  is what AWS reports.
- An integration.response.header.X-Foo mapping was resolved case-sensitively,
  so it silently yielded null whenever the backend used different casing.
  Header names are case-insensitive per RFC 9110.
- An integration with no "type" - which an OpenAPI import can produce - threw
  a NullPointerException inside the dispatch switch instead of reporting the
  misconfiguration.
This commit is contained in:
Abhigya authored and GitHub committed 2026-09-11 16:42:22 -04:00
1 parent 9c9aa670e4
commit a91d7becd1
4 files changed
+200 -3

No files matched your search

@@ -1984,6 +1984,19 @@ public class ApiGatewayController {
node.put("httpMethod", i.getHttpMethod());
node.put("uri", i.getUri());
node.put("passthroughBehavior", i.getPassthroughBehavior());
if (!i.getRequestParameters().isEmpty()) {
ObjectNode params = node.putObject("requestParameters");
i.getRequestParameters().forEach(params::put);
}
if (!i.getRequestTemplates().isEmpty()) {
ObjectNode templates = node.putObject("requestTemplates");
i.getRequestTemplates().forEach(templates::put);
}
if (!i.getIntegrationResponses().isEmpty()) {
ObjectNode responses = node.putObject("integrationResponses");
i.getIntegrationResponses().forEach((status, ir) ->
responses.set(status, toIntegrationResponseNode(ir)));
}
return node;
}
@@ -1991,6 +2004,14 @@ public class ApiGatewayController {
ObjectNode node = objectMapper.createObjectNode();
node.put("statusCode", r.statusCode());
node.put("selectionPattern", r.selectionPattern());
if (r.responseParameters() != null && !r.responseParameters().isEmpty()) {
ObjectNode params = node.putObject("responseParameters");
r.responseParameters().forEach(params::put);
}
if (r.responseTemplates() != null && !r.responseTemplates().isEmpty()) {
ObjectNode templates = node.putObject("responseTemplates");
r.responseTemplates().forEach(templates::put);
}
return node;
}
@@ -53,6 +53,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
@@ -391,7 +392,16 @@ public class ApiGatewayExecuteController {
LOG.debugv("execute-api: {0} {1}/{2}{3} → {4}", httpMethod, apiId, stageName, path,
integration.getType());
return switch (integration.getType().toUpperCase()) {
// An OpenAPI import whose x-amazon-apigateway-integration omits "type" leaves this null;
// report it rather than failing with an NPE inside the switch.
String integrationType = integration.getType();
if (integrationType == null || integrationType.isBlank()) {
return Response.status(500)
.entity(jsonMessage("No integration type configured"))
.type(MediaType.APPLICATION_JSON).build();
}
return switch (integrationType.toUpperCase(Locale.ROOT)) {
case "AWS_PROXY" -> invokeProxy(region, apiId, httpMethod, path, proxy, stageName,
matched, stage, integration, headers, uriInfo, body, authorizerResult, resolvedApiKey,
iamIdentity);
@@ -1268,7 +1278,9 @@ public class ApiGatewayExecuteController {
// Apply response parameter mapping (header mapping from responseParameters config).
if (matchedResponse != null && matchedResponse.responseParameters() != null) {
Map<String, String> serviceResponseHeaders = new HashMap<>();
// Case-insensitive: an integration.response.header.X-Foo mapping must resolve
// regardless of the casing the backend or client library used for the header name.
Map<String, String> serviceResponseHeaders = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
if (serviceResponse != null) {
for (Map.Entry<String, List<String>> e : serviceResponse.getStringHeaders().entrySet()) {
if (!e.getValue().isEmpty()) serviceResponseHeaders.put(e.getKey(), e.getValue().get(0));
@@ -738,7 +738,11 @@ public class ApiGatewayService {
String prefix = path.substring(1, path.length() - suffix.length());
int lastSlash = prefix.lastIndexOf('/');
if (lastSlash < 0) return;
String resourcePath = prefix.substring(0, lastSlash);
// AWS escapes the resource path's slashes as ~1 in the patch path ("/~1pets/GET/...")
// but reports the setting keyed by the plain path ("pets/GET"), so normalise both the
// escaped and unescaped spellings onto that one key.
String resourcePath = prefix.substring(0, lastSlash).replace("~1", "/");
if (resourcePath.startsWith("/")) resourcePath = resourcePath.substring(1);
String httpMethod = prefix.substring(lastSlash + 1);
String methodKey = resourcePath + "/" + httpMethod;