From 41b00b16dbb8a3661f5d9cbbb85fbf453db885a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Ziel?= <159726064+danielvanza@users.noreply.github.com> Date: Mon, 30 Nov 2026 03:26:15 +0100 Subject: [PATCH] fix(cloudformation): provision ApiGateway Model and RequestValidator, and honor them on Method (#9790) --- docs/services/cloudformation.md | 2 +- .../apigateway/ApiGatewayService.java | 36 ++- .../ApiGatewayRestApiCfnProvisioner.java | 208 +++++++++++++- .../provisioners/CfnRollback.java | 9 + .../create-only-properties.json | 9 + ...ayCfnRequestValidationIntegrationTest.java | 91 +++++++ .../ApiGatewayRestApiCfnProvisionerTest.java | 254 +++++++++++++++++- .../cloudformation/schema-surface.tsv | 2 + .../supported-resource-types.tsv | 2 + .../cloudformation/writable-property-gaps.tsv | 2 - tools/docs/cfn_resource_types.yaml | 2 +- 11 files changed, 603 insertions(+), 14 deletions(-) create mode 100644 src/test/java/io/floci/aws/services/cloudformation/ApiGatewayCfnRequestValidationIntegrationTest.java diff --git a/docs/services/cloudformation.md b/docs/services/cloudformation.md index 1ecdc58bac..dba6bb0505 100644 --- a/docs/services/cloudformation.md +++ b/docs/services/cloudformation.md @@ -244,7 +244,7 @@ cross-resource references. | Application Auto Scaling | `ScalableTarget` (`ScheduledActions` are accepted and not run; Floci has no scheduled scaling), `ScalingPolicy` | | Route 53 | `HostedZone`, `RecordSet`, `RecordSetGroup` (written in one change batch, so a record set that cannot be written leaves the zone unchanged; every record set must be in the group's hosted zone), `HealthCheck` | | Cloud Map | `HttpNamespace`, `PrivateDnsNamespace`, `PublicDnsNamespace`, `Service` | -| API Gateway (v1) | `RestApi`, `Resource`, `Authorizer` (created with `Name`, `Type`, `AuthorizerUri`, `IdentitySource`, `AuthorizerResultTtlInSeconds` and `ProviderARNs`; updated in place for those, keeping the id; a template that drops `AuthorizerResultTtlInSeconds`, `IdentitySource` or `ProviderARNs` restores the TTL of 300 and clears the identity source and the pools, a dropped `AuthorizerUri` keeps the current one, and dropping `IdentitySource` from a `TOKEN` or `COGNITO_USER_POOLS` authorizer fails the resource, as AWS requires it there; a change to `RestApiId` replaces the authorizer, as the registry marks it create-only, and deletes the old one once the update commits; `AuthorizerCredentials`, `AuthType` and `IdentityValidationExpression` are not stored), `Method`, `Deployment`, `Stage` (created with `RestApiId`, `StageName`, `DeploymentId` and `Description`; updated in place for `DeploymentId` and `Description`, keeping the stage variables and method settings set outside the stack; a template that drops `Description` clears it, and a dropped `DeploymentId` keeps the current one; a change to `RestApiId` or `StageName` replaces the stage, as the registry marks them create-only, and deletes the old one once the update commits unless `UpdateReplacePolicy: Retain` keeps it, a name already taken on the API fails the update; `AccessLogSetting`, `CacheClusterEnabled`, `CacheClusterSize`, `CanarySetting`, `ClientCertificateId`, `DocumentationVersion`, `MethodSettings`, `Tags`, `TracingEnabled` and `Variables` are accepted and not stored), `Account`, `DomainName`, `BasePathMapping`, `GatewayResponse`, `ApiKey`, `UsagePlan`, `UsagePlanKey` | +| API Gateway (v1) | `RestApi`, `Resource`, `Authorizer` (created with `Name`, `Type`, `AuthorizerUri`, `IdentitySource`, `AuthorizerResultTtlInSeconds` and `ProviderARNs`; updated in place for those, keeping the id; a template that drops `AuthorizerResultTtlInSeconds`, `IdentitySource` or `ProviderARNs` restores the TTL of 300 and clears the identity source and the pools, a dropped `AuthorizerUri` keeps the current one, and dropping `IdentitySource` from a `TOKEN` or `COGNITO_USER_POOLS` authorizer fails the resource, as AWS requires it there; a change to `RestApiId` replaces the authorizer, as the registry marks it create-only, and deletes the old one once the update commits; `AuthorizerCredentials`, `AuthType` and `IdentityValidationExpression` are not stored), `Method`, `Model`, `RequestValidator`, `Deployment`, `Stage` (created with `RestApiId`, `StageName`, `DeploymentId` and `Description`; updated in place for `DeploymentId` and `Description`, keeping the stage variables and method settings set outside the stack; a template that drops `Description` clears it, and a dropped `DeploymentId` keeps the current one; a change to `RestApiId` or `StageName` replaces the stage, as the registry marks them create-only, and deletes the old one once the update commits unless `UpdateReplacePolicy: Retain` keeps it, a name already taken on the API fails the update; `AccessLogSetting`, `CacheClusterEnabled`, `CacheClusterSize`, `CanarySetting`, `ClientCertificateId`, `DocumentationVersion`, `MethodSettings`, `Tags`, `TracingEnabled` and `Variables` are accepted and not stored), `Account`, `DomainName`, `BasePathMapping`, `GatewayResponse`, `ApiKey`, `UsagePlan`, `UsagePlanKey` | | API Gateway v2 | `Api`, `Authorizer`, `Route`, `Integration`, `Stage`, `Deployment`, `DomainName`, `ApiMapping`, `VpcLink` | | AppSync | `GraphQLApi`, `GraphQLSchema`, `DataSource`, `FunctionConfiguration`, `Resolver`, `ApiKey`. `Ref` on `GraphQLApi` and `ApiKey` returns the id where AWS returns the ARN. See [AppSync](appsync.md#cloudformation) for `Ref` and `Fn::GetAtt` compared with AWS. | | AppConfig | `Application`, `Environment` (`Tags` and `DeletionProtectionCheck` are accepted and not stored), `ConfigurationProfile` (`Tags`, `KmsKeyIdentifier`, `RetrievalRoleArn`, `Validators` and `DeletionProtectionCheck` are accepted and not stored), `DeploymentStrategy` (`Tags` are accepted and not stored; `ReplicateTo: SSM_DOCUMENT` writes no SSM document). `Ref` returns the AppConfig ID of each. See [AppConfig](appconfig.md#cloudformation) for updates and replacement. | diff --git a/src/main/java/io/floci/aws/services/apigateway/ApiGatewayService.java b/src/main/java/io/floci/aws/services/apigateway/ApiGatewayService.java index e6b179c20b..aa67312cbb 100644 --- a/src/main/java/io/floci/aws/services/apigateway/ApiGatewayService.java +++ b/src/main/java/io/floci/aws/services/apigateway/ApiGatewayService.java @@ -2511,8 +2511,29 @@ public class ApiGatewayService implements ResourceProvider, Resettable, PassedRo // ──────────────────────────── Models ──────────────────────────── - public Model createModel(String region, String apiId, Map request) { + /** A model name is alphanumeric, which the API and a stack's Model both require. */ + public static void requireModelName(String name) { + if (name == null || !name.matches("[A-Za-z0-9]+")) { + throw new AwsException("BadRequestException", + "Invalid model name specified: " + name + " (it must be alphanumeric)", 400); + } + } + + public synchronized Model createModel(String region, String apiId, Map request) { getRestApi(region, apiId); + String name = (String) request.get("name"); + requireModelName(name); + if (modelStore.get(modelKey(region, apiId, name)).isPresent()) { + throw new AwsException("ConflictException", "Model name already exists for this REST API", 409); + } + return storeModel(region, apiId, request); + } + + /** + * Writes the model the request describes, replacing one of the same name. An OpenAPI import takes + * its model names from the schema names, which need not be alphanumeric. + */ + private Model storeModel(String region, String apiId, Map request) { Model model = new Model(); model.setId(shortId(6)); model.setName((String) request.get("name")); @@ -2573,6 +2594,17 @@ public class ApiGatewayService implements ResourceProvider, Resettable, PassedRo return model; } + /** + * Puts the description and schema a model had back, a null one included, which a patch cannot + * express. For the stack rollback only. + */ + public void restoreModel(String region, String apiId, String modelName, String description, String schema) { + Model model = getModel(region, apiId, modelName); + model.setDescription(description); + model.setSchema(schema); + modelStore.put(modelKey(region, apiId, modelName), model); + } + public String getModelTemplate(String region, String apiId, String modelName) { getRestApi(region, apiId); Model model = getModel(region, apiId, modelName); @@ -4731,7 +4763,7 @@ public class ApiGatewayService implements ResourceProvider, Resettable, PassedRo } catch (JsonProcessingException e) { modelReq.put("schema", "{}"); } - createModel(region, apiId, modelReq); + storeModel(region, apiId, modelReq); } } diff --git a/src/main/java/io/floci/aws/services/cloudformation/provisioners/ApiGatewayRestApiCfnProvisioner.java b/src/main/java/io/floci/aws/services/cloudformation/provisioners/ApiGatewayRestApiCfnProvisioner.java index a3e0cebee1..c4a82aa32c 100644 --- a/src/main/java/io/floci/aws/services/cloudformation/provisioners/ApiGatewayRestApiCfnProvisioner.java +++ b/src/main/java/io/floci/aws/services/cloudformation/provisioners/ApiGatewayRestApiCfnProvisioner.java @@ -12,6 +12,8 @@ import io.floci.aws.services.apigateway.model.Authorizer; import io.floci.aws.services.apigateway.model.Deployment; import io.floci.aws.services.apigateway.model.EndpointConfiguration; import io.floci.aws.services.apigateway.model.EndpointType; +import io.floci.aws.services.apigateway.model.Model; +import io.floci.aws.services.apigateway.model.RequestValidator; import io.floci.aws.services.apigateway.model.RestApi; import io.floci.aws.services.apigateway.model.Stage; import io.floci.aws.services.cloudformation.CloudFormationTemplateEngine; @@ -49,6 +51,8 @@ public class ApiGatewayRestApiCfnProvisioner implements CfnResourceProvisioner { private static final String DEPLOYMENT = "AWS::ApiGateway::Deployment"; private static final String STAGE = "AWS::ApiGateway::Stage"; private static final String AUTHORIZER = "AWS::ApiGateway::Authorizer"; + private static final String MODEL = "AWS::ApiGateway::Model"; + private static final String REQUEST_VALIDATOR = "AWS::ApiGateway::RequestValidator"; /** * Where the entities a Resource or Method stack resource has named live, keyed by physical id: * the API of a Resource, and the API, resource and HTTP method of a Method. The physical id @@ -60,6 +64,12 @@ public class ApiGatewayRestApiCfnProvisioner implements CfnResourceProvisioner { /** Where a {@link Location} names an authorizer, in place of the HTTP method. */ private static final String AUTHORIZER_KIND = "AUTHORIZER"; private static final String AUTHORIZER_SNAPSHOT_ATTR = CfnRollback.APIGW_AUTHORIZER_UPDATE_SNAPSHOT_ATTR; + /** Where a {@link Location} names a model: the model name in place of the resource id. */ + private static final String MODEL_KIND = "MODEL"; + private static final String MODEL_SNAPSHOT_ATTR = CfnRollback.APIGW_MODEL_UPDATE_SNAPSHOT_ATTR; + private static final String VALIDATOR_SNAPSHOT_ATTR = CfnRollback.APIGW_VALIDATOR_UPDATE_SNAPSHOT_ATTR; + /** Where a {@link Location} names a request validator, in place of the HTTP method. */ + private static final String REQUEST_VALIDATOR_KIND = "REQUEST_VALIDATOR"; /** Where a {@link Location} names a stage: the stage name in place of the resource id. */ private static final String STAGE_KIND = "STAGE"; private static final String STAGE_SNAPSHOT_ATTR = CfnRollback.APIGW_STAGE_UPDATE_SNAPSHOT_ATTR; @@ -81,7 +91,7 @@ public class ApiGatewayRestApiCfnProvisioner implements CfnResourceProvisioner { @Override public Set resourceTypes() { - return Set.of(REST_API, RESOURCE, METHOD, DEPLOYMENT, STAGE, AUTHORIZER); + return Set.of(REST_API, RESOURCE, METHOD, DEPLOYMENT, STAGE, AUTHORIZER, MODEL, REQUEST_VALIDATOR); } @Override @@ -93,6 +103,8 @@ public class ApiGatewayRestApiCfnProvisioner implements CfnResourceProvisioner { case DEPLOYMENT -> provisionDeployment(r, props, ctx); case STAGE -> provisionStage(r, props, ctx); case AUTHORIZER -> provisionAuthorizer(r, props, ctx); + case MODEL -> provisionModel(r, props, ctx); + case REQUEST_VALIDATOR -> provisionRequestValidator(r, props, ctx); default -> throw new IllegalStateException("Unhandled type: " + r.getResourceType()); } } @@ -119,7 +131,7 @@ public class ApiGatewayRestApiCfnProvisioner implements CfnResourceProvisioner { } else if (METHOD.equals(resourceType)) { Location location = parseMethodId(physicalId); if (location != null) { - deleteLocation(physicalId, location, region); + deleteLocation(METHOD, physicalId, location, region); } } } @@ -135,13 +147,27 @@ public class ApiGatewayRestApiCfnProvisioner implements CfnResourceProvisioner { delete(resource.getResourceType(), physicalId, region); return; } - deleteLocation(physicalId, location, region); + deleteLocation(resource.getResourceType(), physicalId, location, region); } - private void deleteLocation(String physicalId, Location location, String region) { - if (location.stage()) { + /** + * A Method's location holds its own HTTP verb where the other kinds hold their kind, and a custom + * verb can spell one of them, so a Method is deleted as one whatever its verb is. + */ + private void deleteLocation(String resourceType, String physicalId, Location location, String region) { + if (METHOD.equals(resourceType) && location.httpMethod() != null) { + CfnDeletes.safeDelete("API method", physicalId, () -> apiGatewayService.deleteMethod( + region, location.restApiId(), location.resourceId(), location.httpMethod()), "NotFoundException"); + } else if (location.stage()) { CfnDeletes.safeDelete("API stage", physicalId, () -> apiGatewayService.deleteStage( region, location.restApiId(), location.resourceId()), "NotFoundException"); + } else if (location.model()) { + CfnDeletes.safeDelete("API model", physicalId, () -> apiGatewayService.deleteModel( + region, location.restApiId(), location.resourceId()), "NotFoundException"); + } else if (location.requestValidator()) { + CfnDeletes.safeDelete("API request validator", physicalId, + () -> apiGatewayService.deleteRequestValidator( + region, location.restApiId(), location.resourceId()), "NotFoundException"); } else if (location.authorizer()) { CfnDeletes.safeDelete("API authorizer", physicalId, () -> apiGatewayService.deleteAuthorizer( region, location.restApiId(), location.resourceId()), "NotFoundException"); @@ -183,7 +209,7 @@ public class ApiGatewayRestApiCfnProvisioner implements CfnResourceProvisioner { private void deleteMovedStage(ObjectNode record) { String name = record.path("name").asText(); - deleteLocation(name, new Location(record.path("restApiId").asText(), name, STAGE_KIND), + deleteLocation(STAGE, name, new Location(record.path("restApiId").asText(), name, STAGE_KIND), record.path("region").asText()); } @@ -205,6 +231,8 @@ public class ApiGatewayRestApiCfnProvisioner implements CfnResourceProvisioner { @Override public UpdateCleanupResult completeUpdate(StackResource resource) { resource.getAttributes().remove(AUTHORIZER_SNAPSHOT_ATTR); + resource.getAttributes().remove(MODEL_SNAPSHOT_ATTR); + resource.getAttributes().remove(VALIDATOR_SNAPSHOT_ATTR); ObjectNode pendingStage = readStageCleanup(resource); UpdateCleanupResult movedStage = pendingStage == null ? UpdateCleanupResult.notApplicable() : CfnLifecycleRecords.completePending(resource, STAGE_CLEANUP_ATTR, STAGE_SNAPSHOT_ATTR, @@ -221,6 +249,8 @@ public class ApiGatewayRestApiCfnProvisioner implements CfnResourceProvisioner { public void clearUpdate(StackResource resource) { resource.getAttributes().remove(CfnRollback.REST_API_UPDATE_SNAPSHOT_ATTR); resource.getAttributes().remove(AUTHORIZER_SNAPSHOT_ATTR); + resource.getAttributes().remove(MODEL_SNAPSHOT_ATTR); + resource.getAttributes().remove(VALIDATOR_SNAPSHOT_ATTR); resource.getAttributes().remove(STAGE_SNAPSHOT_ATTR); ReplacementCleanup.clear(resource); } @@ -258,6 +288,36 @@ public class ApiGatewayRestApiCfnProvisioner implements CfnResourceProvisioner { if (stageSnapshot != null) { return rollbackStageUpdate(resource, stageSnapshot); } + JsonNode modelSnapshot = MODEL.equals(resource.getResourceType()) + ? CfnRollback.updateSnapshot(resource, MODEL_SNAPSHOT_ATTR) : null; + if (modelSnapshot != null) { + if (CfnRollback.undoCreatedByUpdate(resource, modelSnapshot, MODEL_SNAPSHOT_ATTR, null, + (createdName, region) -> deleteEntity(resource, createdName, region))) { + return true; + } + apiGatewayService.restoreModel(modelSnapshot.path("region").asText(), + modelSnapshot.path("apiId").asText(), modelSnapshot.path("name").asText(), + CfnRollback.snapshotText(modelSnapshot, "description"), + CfnRollback.snapshotText(modelSnapshot, "schema")); + resource.getAttributes().remove(MODEL_SNAPSHOT_ATTR); + return true; + } + JsonNode validatorSnapshot = REQUEST_VALIDATOR.equals(resource.getResourceType()) + ? CfnRollback.updateSnapshot(resource, VALIDATOR_SNAPSHOT_ATTR) : null; + if (validatorSnapshot != null) { + if (CfnRollback.undoCreatedByUpdate(resource, validatorSnapshot, VALIDATOR_SNAPSHOT_ATTR, + "RequestValidatorId", (createdId, region) -> deleteEntity(resource, createdId, region))) { + return true; + } + apiGatewayService.updateRequestValidator(validatorSnapshot.path("region").asText(), + validatorSnapshot.path("apiId").asText(), validatorSnapshot.path("validatorId").asText(), + List.of(replacePatchOp("/validateRequestBody", + String.valueOf(validatorSnapshot.path("validateRequestBody").asBoolean())), + replacePatchOp("/validateRequestParameters", + String.valueOf(validatorSnapshot.path("validateRequestParameters").asBoolean())))); + resource.getAttributes().remove(VALIDATOR_SNAPSHOT_ATTR); + return true; + } if (ReplacementCleanup.rollback(resource, (type, physicalId, region) -> deleteEntity(resource, physicalId, region))) { return true; @@ -298,6 +358,16 @@ public class ApiGatewayRestApiCfnProvisioner implements CfnResourceProvisioner { return AUTHORIZER_KIND.equals(httpMethod); } + /** A model, recorded with {@link #MODEL_KIND} and its name as the resource id. */ + boolean model() { + return MODEL_KIND.equals(httpMethod); + } + + /** A request validator, recorded with {@link #REQUEST_VALIDATOR_KIND}. */ + boolean requestValidator() { + return REQUEST_VALIDATOR_KIND.equals(httpMethod); + } + /** A stage, recorded with {@link #STAGE_KIND} and its name as the resource id. */ boolean stage() { return STAGE_KIND.equals(httpMethod); @@ -737,6 +807,123 @@ public class ApiGatewayRestApiCfnProvisioner implements CfnResourceProvisioner { return true; } + /** + * The name is the physical id and what a method's {@code RequestModels} names. {@code Description} + * and {@code Schema} update in place, keeping the model; {@code RestApiId}, {@code Name} and + * {@code ContentType} are create-only, so a change to one makes a new model and the old one is + * deleted once the update commits. A model left without a name is given an alphanumeric one, as + * the API requires, and keeps it across an update that does not replace it. As on AWS, a model + * with a name of its own cannot be replaced without a new name. An in-place update keeps a snapshot + * of the description and schema, which a failed stack update puts back. + */ + private void provisionModel(StackResource r, JsonNode props, ProvisionContext ctx) { + // A snapshot describes the update in flight; one an earlier update left behind is stale. + r.getAttributes().remove(MODEL_SNAPSHOT_ATTR); + Map attributesBefore = new HashMap<>(r.getAttributes()); + String region = ctx.region(); + String apiId = ctx.resolveOptional(props, "RestApiId"); + String declared = ctx.resolveOptional(props, "Name"); + if (declared != null) { + ApiGatewayService.requireModelName(declared); + } + ProvisionContext.NamedChange named = ctx.changes(MODEL, props, declared, r.getLogicalId(), 0, false, + generated -> generated.replaceAll("[^A-Za-z0-9]", "")); + String name = named.name(); + boolean replaces = named.replaces(); + String description = ctx.resolveOptional(props, "Description"); + JsonNode schemaNode = props != null && props.has("Schema") + ? ctx.engine().resolveNode(props.get("Schema")) : null; + String schema = schemaNode == null || schemaNode.isNull() ? null + : schemaNode.isTextual() ? schemaNode.asText() : schemaNode.toString(); + String finalName = name; + Model live = ctx.isUpdate() && !replaces ? findPrior("API model", finalName, + () -> apiGatewayService.getModel(region, apiId, finalName)) : null; + if (live != null) { + ObjectNode snapshot = objectMapper.createObjectNode(); + snapshot.put("region", region); + snapshot.put("apiId", apiId); + snapshot.put("name", name); + snapshot.put("description", live.getDescription()); + snapshot.put("schema", live.getSchema()); + r.getAttributes().put(MODEL_SNAPSHOT_ATTR, snapshot.toString()); + List> ops = new ArrayList<>(); + if (description != null) { + ops.add(replacePatchOp("/description", description)); + } + if (schema != null) { + ops.add(replacePatchOp("/schema", schema)); + } + apiGatewayService.updateModel(region, apiId, name, ops); + } else { + Map req = new HashMap<>(); + req.put("name", name); + req.put("description", description); + String contentType = ctx.resolveOptional(props, "ContentType"); + if (contentType != null) { + req.put("contentType", contentType); + } + if (schema != null) { + req.put("schema", schema); + } + apiGatewayService.createModel(region, apiId, req); + } + r.setPhysicalId(name); + if (live == null && ctx.isUpdate() && !replaces) { + // The model the update started from is gone, so this one is the update's to undo. + CfnRollback.recordCreatedByUpdate(r, ctx, MODEL_SNAPSHOT_ATTR); + } + recordLocation(r, ctx, new Location(apiId, name, MODEL_KIND)); + ReplacementCleanup.record(r, ctx, attributesBefore); + } + + /** + * {@code ValidateRequestBody} and {@code ValidateRequestParameters} update in place, keeping the id + * a method names; {@code RestApiId} and {@code Name} are create-only, so a change to one makes a + * new validator and the old one is deleted once the update commits. An in-place update keeps a + * snapshot of the two flags, which a failed stack update puts back. + */ + private void provisionRequestValidator(StackResource r, JsonNode props, ProvisionContext ctx) { + r.getAttributes().remove(VALIDATOR_SNAPSHOT_ATTR); + Map attributesBefore = new HashMap<>(r.getAttributes()); + String region = ctx.region(); + String apiId = ctx.resolveOptional(props, "RestApiId"); + boolean body = Boolean.TRUE.equals(ctx.resolveOptionalBoolean(props, "ValidateRequestBody")); + boolean parameters = Boolean.TRUE.equals(ctx.resolveOptionalBoolean(props, "ValidateRequestParameters")); + PropertyChanges changes = ctx.isUpdate() ? ctx.changes(REQUEST_VALIDATOR, props) : null; + boolean replaces = changes != null && changes.requiresReplacement(); + RequestValidator live = ctx.isUpdate() && !replaces ? findPrior("API request validator", + ctx.priorPhysicalId(), + () -> apiGatewayService.getRequestValidator(region, apiId, ctx.priorPhysicalId())) : null; + String validatorId; + if (live != null) { + ObjectNode snapshot = objectMapper.createObjectNode(); + snapshot.put("region", region); + snapshot.put("apiId", apiId); + snapshot.put("validatorId", live.getId()); + snapshot.put("validateRequestBody", live.isValidateRequestBody()); + snapshot.put("validateRequestParameters", live.isValidateRequestParameters()); + r.getAttributes().put(VALIDATOR_SNAPSHOT_ATTR, snapshot.toString()); + validatorId = ctx.priorPhysicalId(); + apiGatewayService.updateRequestValidator(region, apiId, validatorId, List.of( + replacePatchOp("/validateRequestBody", String.valueOf(body)), + replacePatchOp("/validateRequestParameters", String.valueOf(parameters)))); + } else { + Map req = new HashMap<>(); + req.put("name", ctx.resolveOptional(props, "Name")); + req.put("validateRequestBody", body); + req.put("validateRequestParameters", parameters); + validatorId = apiGatewayService.createRequestValidator(region, apiId, req).getId(); + } + r.setPhysicalId(validatorId); + r.getAttributes().put("RequestValidatorId", validatorId); + if (live == null && ctx.isUpdate() && !replaces) { + // The validator the update started from is gone, so this one is the update's to undo. + CfnRollback.recordCreatedByUpdate(r, ctx, VALIDATOR_SNAPSHOT_ATTR); + } + recordLocation(r, ctx, new Location(apiId, validatorId, REQUEST_VALIDATOR_KIND)); + ReplacementCleanup.record(r, ctx, attributesBefore); + } + private void provisionMethod(StackResource r, JsonNode props, ProvisionContext ctx) { Map attributesBefore = new HashMap<>(r.getAttributes()); String region = ctx.region(); @@ -752,6 +939,13 @@ public class ApiGatewayRestApiCfnProvisioner implements CfnResourceProvisioner { req.put("authorizerId", authorizerId); } req.put("apiKeyRequired", Boolean.parseBoolean(ctx.resolveOrDefault(props, "ApiKeyRequired", "false"))); + String requestValidatorId = ctx.resolveOptional(props, "RequestValidatorId"); + if (requestValidatorId != null) { + req.put("requestValidatorId", requestValidatorId); + } + if (props != null && props.has("RequestModels")) { + req.put("requestModels", resolveStringMap(props, "RequestModels", engine)); + } apiGatewayService.putMethod(region, apiId, resourceId, httpMethod, req); // putMethod upper-cases the method, so a change of case alone names the same method. The @@ -972,7 +1166,7 @@ public class ApiGatewayRestApiCfnProvisioner implements CfnResourceProvisioner { String stageName = snapshot.path("stageName").asText(); String movedFrom = CfnRollback.snapshotText(snapshot, "movedFromApiId"); if (movedFrom != null) { - deleteLocation(stageName, new Location(apiId, stageName, STAGE_KIND), region); + deleteLocation(STAGE, stageName, new Location(apiId, stageName, STAGE_KIND), region); ObjectNode recorded = objectMapper.createObjectNode(); recorded.set(stageName, locationNode(new Location(movedFrom, stageName, STAGE_KIND))); resource.getAttributes().put(LOCATIONS_ATTR, recorded.toString()); diff --git a/src/main/java/io/floci/aws/services/cloudformation/provisioners/CfnRollback.java b/src/main/java/io/floci/aws/services/cloudformation/provisioners/CfnRollback.java index d7db0a1378..4b7933744c 100644 --- a/src/main/java/io/floci/aws/services/cloudformation/provisioners/CfnRollback.java +++ b/src/main/java/io/floci/aws/services/cloudformation/provisioners/CfnRollback.java @@ -206,6 +206,15 @@ public final class CfnRollback { */ public static final String APIGW_STAGE_UPDATE_SNAPSHOT_ATTR = "__FlociApiGatewayStageUpdateSnapshot"; + /** + * The description and schema an API Gateway model carried, or the two validation flags a request + * validator carried, before an in-place update, so a failed stack update can put them back. + * Written and spent by {@code ApiGatewayRestApiCfnProvisioner}. + */ + public static final String APIGW_MODEL_UPDATE_SNAPSHOT_ATTR = "__FlociApiGatewayModelUpdateSnapshot"; + + public static final String APIGW_VALIDATOR_UPDATE_SNAPSHOT_ATTR = "__FlociApiGatewayValidatorUpdateSnapshot"; + public static final String STACK_SET_UPDATE_SNAPSHOT_ATTR = "__FlociStackSetUpdateSnapshot"; /** diff --git a/src/main/resources/cloudformation/create-only-properties.json b/src/main/resources/cloudformation/create-only-properties.json index 96ae7b4ebd..f2815513a9 100644 --- a/src/main/resources/cloudformation/create-only-properties.json +++ b/src/main/resources/cloudformation/create-only-properties.json @@ -28,6 +28,15 @@ "ResourceId", "HttpMethod" ], + "AWS::ApiGateway::Model": [ + "ContentType", + "Name", + "RestApiId" + ], + "AWS::ApiGateway::RequestValidator": [ + "Name", + "RestApiId" + ], "AWS::ApiGateway::Resource": [ "PathPart", "ParentId", diff --git a/src/test/java/io/floci/aws/services/cloudformation/ApiGatewayCfnRequestValidationIntegrationTest.java b/src/test/java/io/floci/aws/services/cloudformation/ApiGatewayCfnRequestValidationIntegrationTest.java new file mode 100644 index 0000000000..d08f04cdbc --- /dev/null +++ b/src/test/java/io/floci/aws/services/cloudformation/ApiGatewayCfnRequestValidationIntegrationTest.java @@ -0,0 +1,91 @@ +package io.floci.aws.services.cloudformation; + +import io.floci.aws.testing.CfnTestStack; +import io.floci.aws.testing.RestAssuredJsonUtils; +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import software.amazon.awssdk.services.apigateway.ApiGatewayClient; +import software.amazon.awssdk.services.apigateway.model.ConflictException; +import software.amazon.awssdk.services.cloudformation.model.Stack; + +import static io.floci.aws.testing.CfnStackWaits.output; +import static io.restassured.RestAssured.given; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.hasSize; +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** + * A stack's Model and RequestValidator are created, and the Method that names them stores both. A model + * name the API already has is refused. + */ +@QuarkusTest +class ApiGatewayCfnRequestValidationIntegrationTest { + + private static final String TEMPLATE = """ + { + "Resources": { + "Api": {"Type":"AWS::ApiGateway::RestApi", "Properties":{"Name":"cfn-request-validation"}}, + "Item": {"Type":"AWS::ApiGateway::Model", "Properties":{ + "RestApiId":{"Ref":"Api"}, "Name":"Item", "ContentType":"application/json", + "Schema":{"type":"object"}}}, + "Check": {"Type":"AWS::ApiGateway::RequestValidator", "Properties":{ + "RestApiId":{"Ref":"Api"}, "Name":"body-only", "ValidateRequestBody":true}}, + "Put": {"Type":"AWS::ApiGateway::Method", "Properties":{ + "RestApiId":{"Ref":"Api"}, "ResourceId":{"Fn::GetAtt":["Api","RootResourceId"]}, + "HttpMethod":"PUT", "AuthorizationType":"NONE", + "RequestValidatorId":{"Ref":"Check"}, + "RequestModels":{"application/json":{"Ref":"Item"}}, + "Integration":{"Type":"MOCK"}}} + }, + "Outputs":{"ApiId":{"Value":{"Ref":"Api"}}, + "RootId":{"Value":{"Fn::GetAtt":["Api","RootResourceId"]}}, + "ModelRef":{"Value":{"Ref":"Item"}}, + "ValidatorRef":{"Value":{"Ref":"Check"}}, + "ValidatorAttr":{"Value":{"Fn::GetAtt":["Check","RequestValidatorId"]}}} + } + """; + + @RegisterExtension + final CfnTestStack stack = new CfnTestStack("apigw-cfn-request-validation-it"); + + @BeforeAll + static void configureRestAssured() { + RestAssuredJsonUtils.configureAwsContentTypes(); + } + + @Test + void methodStoresTheValidatorAndModelTheStackCreated() { + Stack created = stack.create(TEMPLATE); + String apiId = output(created, "ApiId"); + String validatorId = output(created, "ValidatorRef"); + + given().when().get("/restapis/" + apiId + "/models") + .then().statusCode(200) + .body("item.name", hasItem("Item")); + given().when().get("/restapis/" + apiId + "/requestvalidators") + .then().statusCode(200) + .body("item", hasSize(1)) + .body("item[0].id", equalTo(validatorId)) + .body("item[0].name", equalTo("body-only")) + .body("item[0].validateRequestBody", equalTo(true)); + given().when().get("/restapis/" + apiId + "/resources/" + output(created, "RootId") + "/methods/PUT") + .then().statusCode(200) + .body("requestValidatorId", equalTo(validatorId)) + .body("requestModels.'application/json'", equalTo("Item")); + + assertThat(output(created, "ModelRef"), equalTo("Item")); + assertThat(output(created, "ValidatorAttr"), equalTo(validatorId)); + } + + @Test + void aModelNameTheApiAlreadyHasIsRefused() { + String apiId = output(stack.create(TEMPLATE), "ApiId"); + + assertThrows(ConflictException.class, () -> stack.client(ApiGatewayClient.builder()) + .createModel(request -> request.restApiId(apiId).name("Item").contentType("application/json"))); + } +} diff --git a/src/test/java/io/floci/aws/services/cloudformation/provisioners/ApiGatewayRestApiCfnProvisionerTest.java b/src/test/java/io/floci/aws/services/cloudformation/provisioners/ApiGatewayRestApiCfnProvisionerTest.java index 015ab6f2c9..25cf364a65 100644 --- a/src/test/java/io/floci/aws/services/cloudformation/provisioners/ApiGatewayRestApiCfnProvisionerTest.java +++ b/src/test/java/io/floci/aws/services/cloudformation/provisioners/ApiGatewayRestApiCfnProvisionerTest.java @@ -9,6 +9,8 @@ import io.floci.aws.services.apigateway.model.Authorizer; import io.floci.aws.services.apigateway.model.Deployment; import io.floci.aws.services.apigateway.model.EndpointConfiguration; import io.floci.aws.services.apigateway.model.EndpointType; +import io.floci.aws.services.apigateway.model.Model; +import io.floci.aws.services.apigateway.model.RequestValidator; import io.floci.aws.services.apigateway.model.RestApi; import io.floci.aws.services.cloudformation.CloudFormationTemplateEngine; import io.floci.aws.services.cloudformation.model.StackResource; @@ -610,6 +612,249 @@ class ApiGatewayRestApiCfnProvisionerTest { verify(api).deleteMethod("us-east-1", "my-api", "d4e5f6", "X-CUSTOM"); } + @Test + void methodPassesItsRequestValidatorAndRequestModels() throws Exception { + StackResource r = resource("AWS::ApiGateway::Method", "Put"); + provisioner.provision(r, props(""" + {"RestApiId": "api-1", "ResourceId": "res-1", "HttpMethod": "PUT", + "RequestValidatorId": "val-1", "RequestModels": {"application/json": "Item"}} + """), ctx()); + + ArgumentCaptor> request = ArgumentCaptor.forClass(Map.class); + verify(api).putMethod(eq("us-east-1"), eq("api-1"), eq("res-1"), eq("PUT"), request.capture()); + assertEquals("val-1", request.getValue().get("requestValidatorId")); + assertEquals(Map.of("application/json", "Item"), request.getValue().get("requestModels")); + } + + @Test + void modelPublishesItsNameAndIsDeletedByName() throws Exception { + StackResource r = resource("AWS::ApiGateway::Model", "Item"); + provisioner.provision(r, props(""" + {"RestApiId": "api-1", "Name": "Item", "ContentType": "application/json", + "Description": "an item", "Schema": {"type": "object"}} + """), ctx()); + + assertEquals("Item", r.getPhysicalId()); + ArgumentCaptor> request = ArgumentCaptor.forClass(Map.class); + verify(api).createModel(eq("us-east-1"), eq("api-1"), request.capture()); + assertEquals("Item", request.getValue().get("name")); + assertEquals("application/json", request.getValue().get("contentType")); + assertEquals("{\"type\":\"object\"}", request.getValue().get("schema")); + + provisioner.delete(r, "us-east-1"); + + verify(api).deleteModel("us-east-1", "api-1", "Item"); + } + + @Test + void modelWithoutANameGetsAnAlphanumericOne() throws Exception { + StackResource r = resource("AWS::ApiGateway::Model", "Item"); + provisioner.provision(r, props("{\"RestApiId\": \"api-1\"}"), ctx()); + + assertTrue(r.getPhysicalId().matches("[A-Za-z0-9]+Item[0-9a-f]{12}"), r.getPhysicalId()); + verify(api).createModel(eq("us-east-1"), eq("api-1"), anyMap()); + } + + @Test + void modelWithANameThatIsNotAlphanumericIsRefused() throws Exception { + StackResource r = resource("AWS::ApiGateway::Model", "Item"); + + assertThrows(AwsException.class, () -> provisioner.provision(r, + props("{\"RestApiId\": \"api-1\", \"Name\": \"bad-name\"}"), ctx())); + + verify(api, never()).createModel(anyString(), anyString(), anyMap()); + } + + @Test + void modelUpdateKeepsTheModelAndPatchesItsDescriptionAndSchema() throws Exception { + when(api.getModel("us-east-1", "api-1", "Item")).thenReturn(new Model()); + StackResource r = resource("AWS::ApiGateway::Model", "Item"); + + provisioner.provision(r, props(""" + {"RestApiId": "api-1", "Name": "Item", "ContentType": "application/json", + "Description": "new", "Schema": {"type": "string"}} + """), ctx("Item", props(""" + {"RestApiId": "api-1", "Name": "Item", "ContentType": "application/json", + "Description": "old", "Schema": {"type": "object"}} + """))); + + assertEquals("Item", r.getPhysicalId()); + ArgumentCaptor>> ops = ArgumentCaptor.forClass(List.class); + verify(api).updateModel(eq("us-east-1"), eq("api-1"), eq("Item"), ops.capture()); + assertEquals(List.of( + Map.of("op", "replace", "path", "/description", "value", "new"), + Map.of("op", "replace", "path", "/schema", "value", "{\"type\":\"string\"}")), ops.getValue()); + verify(api, never()).createModel(anyString(), anyString(), anyMap()); + assertFalse(provisioner.hasReplacementUpdate(r)); + } + + @Test + void modelReplacementUnderItsOwnNameIsRefused() throws Exception { + StackResource r = resource("AWS::ApiGateway::Model", "Item"); + + assertThrows(AwsException.class, () -> provisioner.provision(r, props(""" + {"RestApiId": "api-1", "Name": "Item", "ContentType": "text/xml"} + """), ctx("Item", props(""" + {"RestApiId": "api-1", "Name": "Item", "ContentType": "application/json"} + """)))); + + verify(api, never()).createModel(anyString(), anyString(), anyMap()); + } + + @Test + void modelMovedToAnotherApiIsCreatedThereAndTheOldOneDeletedOnCommit() throws Exception { + StackResource r = resource("AWS::ApiGateway::Model", "Item"); + provisioner.provision(r, props("{\"RestApiId\": \"api-1\", \"Name\": \"First\"}"), ctx()); + + provisioner.provision(r, props("{\"RestApiId\": \"api-2\", \"Name\": \"Second\"}"), + ctx("First", props("{\"RestApiId\": \"api-1\", \"Name\": \"First\"}"))); + + assertEquals("Second", r.getPhysicalId()); + verify(api).createModel(eq("us-east-1"), eq("api-2"), anyMap()); + assertTrue(provisioner.hasReplacementUpdate(r)); + } + + @Test + void requestValidatorPublishesItsIdAndIsDeletedById() throws Exception { + RequestValidator created = new RequestValidator(); + created.setId("val-1"); + when(api.createRequestValidator(eq("us-east-1"), eq("api-1"), anyMap())).thenReturn(created); + + StackResource r = resource("AWS::ApiGateway::RequestValidator", "Check"); + provisioner.provision(r, props(""" + {"RestApiId": "api-1", "Name": "body-only", "ValidateRequestBody": true} + """), ctx()); + + assertEquals("val-1", r.getPhysicalId()); + assertEquals("val-1", r.getAttributes().get("RequestValidatorId")); + ArgumentCaptor> request = ArgumentCaptor.forClass(Map.class); + verify(api).createRequestValidator(eq("us-east-1"), eq("api-1"), request.capture()); + assertEquals("body-only", request.getValue().get("name")); + assertEquals(true, request.getValue().get("validateRequestBody")); + assertEquals(false, request.getValue().get("validateRequestParameters")); + + provisioner.delete(r, "us-east-1"); + + verify(api).deleteRequestValidator("us-east-1", "api-1", "val-1"); + } + + @Test + void requestValidatorUpdateKeepsTheIdAndPatchesTheFlags() throws Exception { + when(api.getRequestValidator("us-east-1", "api-1", "val-1")).thenReturn(new RequestValidator()); + StackResource r = resource("AWS::ApiGateway::RequestValidator", "Check"); + + provisioner.provision(r, props(""" + {"RestApiId": "api-1", "Name": "body-only", "ValidateRequestParameters": true} + """), ctx("val-1", props(""" + {"RestApiId": "api-1", "Name": "body-only", "ValidateRequestBody": true} + """))); + + assertEquals("val-1", r.getPhysicalId()); + assertEquals("val-1", r.getAttributes().get("RequestValidatorId")); + verify(api).updateRequestValidator("us-east-1", "api-1", "val-1", List.of( + Map.of("op", "replace", "path", "/validateRequestBody", "value", "false"), + Map.of("op", "replace", "path", "/validateRequestParameters", "value", "true"))); + verify(api, never()).createRequestValidator(anyString(), anyString(), anyMap()); + assertFalse(provisioner.hasReplacementUpdate(r)); + } + + @Test + void failedUpdateRestoresTheModelDescriptionAndSchema() throws Exception { + Model live = new Model(); + live.setDescription("old"); + live.setSchema("{\"type\":\"object\"}"); + when(api.getModel("us-east-1", "api-1", "Item")).thenReturn(live); + StackResource r = resource("AWS::ApiGateway::Model", "Item"); + provisioner.provision(r, props(""" + {"RestApiId": "api-1", "Name": "Item", "Description": "new", "Schema": {"type": "string"}} + """), ctx("Item", props(""" + {"RestApiId": "api-1", "Name": "Item", "Description": "old", "Schema": {"type": "object"}} + """))); + + assertTrue(provisioner.rollbackUpdate(r)); + + verify(api).restoreModel("us-east-1", "api-1", "Item", "old", "{\"type\":\"object\"}"); + assertFalse(r.getAttributes().containsKey(CfnRollback.APIGW_MODEL_UPDATE_SNAPSHOT_ATTR)); + } + + @Test + void failedUpdateRestoresTheRequestValidatorFlags() throws Exception { + RequestValidator live = new RequestValidator(); + live.setId("val-1"); + live.setValidateRequestBody(true); + when(api.getRequestValidator("us-east-1", "api-1", "val-1")).thenReturn(live); + StackResource r = resource("AWS::ApiGateway::RequestValidator", "Check"); + provisioner.provision(r, props(""" + {"RestApiId": "api-1", "Name": "body-only", "ValidateRequestParameters": true} + """), ctx("val-1", props(""" + {"RestApiId": "api-1", "Name": "body-only", "ValidateRequestBody": true} + """))); + + assertTrue(provisioner.rollbackUpdate(r)); + + verify(api).updateRequestValidator("us-east-1", "api-1", "val-1", List.of( + Map.of("op", "replace", "path", "/validateRequestBody", "value", "true"), + Map.of("op", "replace", "path", "/validateRequestParameters", "value", "false"))); + assertFalse(r.getAttributes().containsKey(CfnRollback.APIGW_VALIDATOR_UPDATE_SNAPSHOT_ATTR)); + } + + @Test + void failedUpdateDeletesTheModelItRecreatedBecauseThePriorWasGone() throws Exception { + when(api.getModel("us-east-1", "api-1", "Item")) + .thenThrow(new AwsException("NotFoundException", "Invalid model name specified", 404)); + StackResource r = resource("AWS::ApiGateway::Model", "Item"); + provisioner.provision(r, props("{\"RestApiId\": \"api-1\", \"Name\": \"Item\", \"Description\": \"new\"}"), + ctx("Item", props("{\"RestApiId\": \"api-1\", \"Name\": \"Item\", \"Description\": \"old\"}"))); + verify(api).createModel(eq("us-east-1"), eq("api-1"), anyMap()); + + assertTrue(provisioner.rollbackUpdate(r)); + + verify(api).deleteModel("us-east-1", "api-1", "Item"); + assertEquals("Item", r.getPhysicalId()); + } + + @Test + void failedUpdateDeletesTheRequestValidatorItRecreatedBecauseThePriorWasGone() throws Exception { + when(api.getRequestValidator("us-east-1", "api-1", "val-1")) + .thenThrow(new AwsException("NotFoundException", "Invalid Request Validator identifier", 404)); + RequestValidator created = new RequestValidator(); + created.setId("val-2"); + when(api.createRequestValidator(eq("us-east-1"), eq("api-1"), anyMap())).thenReturn(created); + StackResource r = resource("AWS::ApiGateway::RequestValidator", "Check"); + provisioner.provision(r, props("{\"RestApiId\": \"api-1\", \"Name\": \"body-only\"}"), + ctx("val-1", props("{\"RestApiId\": \"api-1\", \"Name\": \"body-only\"}"))); + + assertTrue(provisioner.rollbackUpdate(r)); + + verify(api).deleteRequestValidator("us-east-1", "api-1", "val-2"); + assertEquals("val-1", r.getPhysicalId()); + assertEquals("val-1", r.getAttributes().get("RequestValidatorId")); + } + + @Test + void methodWithAKindNamedVerbIsDeletedAsAMethod() throws Exception { + StackResource r = resource("AWS::ApiGateway::Method", "Custom"); + provisioner.provision(r, props(""" + {"RestApiId":"api-1","ResourceId":"res-1","HttpMethod":"MODEL","AuthorizationType":"NONE"} + """), ctx()); + + provisioner.delete(r, "us-east-1"); + + verify(api).deleteMethod("us-east-1", "api-1", "res-1", "MODEL"); + verify(api, never()).deleteModel(anyString(), anyString(), anyString()); + } + + @Test + void requestValidatorWithABooleanThatIsNotOneIsRefused() throws Exception { + StackResource r = resource("AWS::ApiGateway::RequestValidator", "Check"); + + assertThrows(AwsException.class, () -> provisioner.provision(r, props(""" + {"RestApiId": "api-1", "Name": "x", "ValidateRequestBody": "invalid"} + """), ctx())); + + verify(api, never()).createRequestValidator(anyString(), anyString(), anyMap()); + } + @Test void methodProvisionsMockTemplatesAndCorsResponses() throws Exception { StackResource r = resource("AWS::ApiGateway::Method", "Options"); @@ -705,6 +950,10 @@ class ApiGatewayRestApiCfnProvisionerTest { } private ProvisionContext ctx(String priorPhysicalId) { + return ctx(priorPhysicalId, null); + } + + private ProvisionContext ctx(String priorPhysicalId, JsonNode priorProperties) { CloudFormationTemplateEngine engine = mock(CloudFormationTemplateEngine.class); when(engine.resolve(any())).thenAnswer(inv -> { JsonNode node = inv.getArgument(0); @@ -716,7 +965,10 @@ class ApiGatewayRestApiCfnProvisionerTest { ((JsonNode) inv.getArgument(0)).forEach(value -> values.add(value.asText())); return values; }); - return new ProvisionContext(engine, "us-east-1", "000000000000", "my-stack", priorPhysicalId); + return priorProperties == null + ? new ProvisionContext(engine, "us-east-1", "000000000000", "my-stack", priorPhysicalId) + : new ProvisionContext(engine, "us-east-1", "000000000000", "my-stack", priorPhysicalId, + null, priorProperties); } /** diff --git a/src/test/resources/cloudformation/schema-surface.tsv b/src/test/resources/cloudformation/schema-surface.tsv index 9681f5fa86..1fe17c46b7 100644 --- a/src/test/resources/cloudformation/schema-surface.tsv +++ b/src/test/resources/cloudformation/schema-surface.tsv @@ -6,6 +6,8 @@ AWS::ApiGateway::Deployment DeploymentId DeploymentCanarySettings,Description,Re AWS::ApiGateway::DomainName DistributionDomainName,DistributionHostedZoneId,DomainNameArn,RegionalDomainName,RegionalHostedZoneId CertificateArn,DomainName,EndpointAccessMode,EndpointConfiguration,MutualTlsAuthentication,OwnershipVerificationCertificateArn,RegionalCertificateArn,RoutingMode,SecurityPolicy,Tags AWS::ApiGateway::GatewayResponse Id ResponseParameters,ResponseTemplates,ResponseType,RestApiId,StatusCode AWS::ApiGateway::Method ApiKeyRequired,AuthorizationScopes,AuthorizationType,AuthorizerId,HttpMethod,Integration,MethodResponses,OperationName,RequestModels,RequestParameters,RequestValidatorId,ResourceId,RestApiId +AWS::ApiGateway::Model ContentType,Description,Name,RestApiId,Schema +AWS::ApiGateway::RequestValidator RequestValidatorId Name,RestApiId,ValidateRequestBody,ValidateRequestParameters AWS::ApiGateway::Resource ResourceId ParentId,PathPart,RestApiId AWS::ApiGateway::RestApi RestApiId,RootResourceId ApiKeySourceType,BinaryMediaTypes,Body,BodyS3Location,CloneFrom,Description,DisableExecuteApiEndpoint,EndpointAccessMode,EndpointConfiguration,FailOnWarnings,MinimumCompressionSize,Mode,Name,Parameters,Policy,SecurityPolicy,Tags,Version AWS::ApiGateway::Stage AccessLogSetting,CacheClusterEnabled,CacheClusterSize,CanarySetting,ClientCertificateId,DeploymentId,Description,DocumentationVersion,MethodSettings,RestApiId,StageName,Tags,TracingEnabled,Variables diff --git a/src/test/resources/cloudformation/supported-resource-types.tsv b/src/test/resources/cloudformation/supported-resource-types.tsv index 87187ca0a1..759cea17d1 100644 --- a/src/test/resources/cloudformation/supported-resource-types.tsv +++ b/src/test/resources/cloudformation/supported-resource-types.tsv @@ -6,6 +6,8 @@ AWS::ApiGateway::Deployment ApiGatewayRestApiCfnProvisioner AWS::ApiGateway::DomainName ApiGatewayDomainCfnProvisioner AWS::ApiGateway::GatewayResponse ApiGatewayGatewayResponseCfnProvisioner AWS::ApiGateway::Method ApiGatewayRestApiCfnProvisioner +AWS::ApiGateway::Model ApiGatewayRestApiCfnProvisioner +AWS::ApiGateway::RequestValidator ApiGatewayRestApiCfnProvisioner AWS::ApiGateway::Resource ApiGatewayRestApiCfnProvisioner AWS::ApiGateway::RestApi ApiGatewayRestApiCfnProvisioner AWS::ApiGateway::Stage ApiGatewayRestApiCfnProvisioner diff --git a/src/test/resources/cloudformation/writable-property-gaps.tsv b/src/test/resources/cloudformation/writable-property-gaps.tsv index 30aab386d9..12d80ddd2c 100644 --- a/src/test/resources/cloudformation/writable-property-gaps.tsv +++ b/src/test/resources/cloudformation/writable-property-gaps.tsv @@ -10,8 +10,6 @@ AWS::ApiGateway::DomainName OwnershipVerificationCertificateArn accepted and ign AWS::ApiGateway::DomainName RoutingMode accepted and ignored, as the ApiGatewayDomainCfnProvisioner javadoc records AWS::ApiGateway::Method AuthorizationScopes accepted and ignored AWS::ApiGateway::Method OperationName accepted and ignored -AWS::ApiGateway::Method RequestModels accepted and ignored -AWS::ApiGateway::Method RequestValidatorId accepted and ignored AWS::ApiGateway::RestApi ApiKeySourceType accepted and ignored AWS::ApiGateway::RestApi BinaryMediaTypes accepted and ignored AWS::ApiGateway::RestApi CloneFrom accepted and ignored diff --git a/tools/docs/cfn_resource_types.yaml b/tools/docs/cfn_resource_types.yaml index a19261c517..60b67aec48 100644 --- a/tools/docs/cfn_resource_types.yaml +++ b/tools/docs/cfn_resource_types.yaml @@ -120,7 +120,7 @@ type_order: AWS::ApplicationAutoScaling: [ScalableTarget, ScalingPolicy] AWS::AutoScaling: [LaunchConfiguration, AutoScalingGroup, LifecycleHook] AWS::Route53: [HostedZone, RecordSet, RecordSetGroup, HealthCheck] - AWS::ApiGateway: [RestApi, Resource, Authorizer, Method, Deployment, Stage, Account, DomainName, BasePathMapping, GatewayResponse] + AWS::ApiGateway: [RestApi, Resource, Authorizer, Method, Model, RequestValidator, Deployment, Stage, Account, DomainName, BasePathMapping, GatewayResponse] AWS::ApiGatewayV2: [Api, Authorizer, Route, Integration, Stage, Deployment, DomainName, ApiMapping] AWS::AppSync: [GraphQLApi, GraphQLSchema, DataSource, FunctionConfiguration, Resolver, ApiKey] AWS::AppConfig: [Application, Environment, ConfigurationProfile, DeploymentStrategy]