fix(cloudformation): drop undeclared OpenAPI authorizer schemes (#6632)

This commit is contained in:
Andre Kurait authored and GitHub committed 2026-10-26 08:06:31 -04:00
1 parent 7453011c43
commit f32db4fe49
4 files changed
+103 -11

No files matched your search

@@ -107,6 +107,22 @@ final class SamRestApiAuth {
}
}
}
if (!swagger) {
removeUndeclaredCustomSchemes(document, definitions);
}
}
private void removeUndeclaredCustomSchemes(ObjectNode document, ObjectNode definitions) {
// SAM builds securityDefinitions first, then replaces OpenAPI securitySchemes with it.
// Inline OpenAPI authorizers absent from that generated map do not reach the importer.
Iterator<Map.Entry<String, JsonNode>> schemes = definitions.fields();
while (schemes.hasNext()) {
Map.Entry<String, JsonNode> scheme = schemes.next();
if (scheme.getValue().has("x-amazon-apigateway-authorizer")
&& !document.path("securityDefinitions").has(scheme.getKey())) {
schemes.remove();
}
}
}
private void applyDefaults(ObjectNode operation, ObjectNode definitions, boolean iam, boolean keyRequired) {