From 91ec6d29ef1251e5199651da8006ed8c415257ba Mon Sep 17 00:00:00 2001 From: soreavis <263610811+soreavis@users.noreply.github.com> Date: Fri, 13 Nov 2026 00:15:21 +0100 Subject: [PATCH] fix(apigateway): treat blank documentation part location fields as absent (#8153) Terraform's aws_api_gateway_documentation_part sends every location member: the provider sets each key present in the block's map, and the plugin SDK fills the keys the configuration leaves out with "". The service kept those blanks in the location and then rejected each one that does not apply to the part's type, so every type except RESPONSE_HEADER failed with "Invalid documentation part location field". A blank member is now dropped like an absent one: it is not stored or returned, and the type's default fills it where there is one. A non-blank member that does not apply to the type is still rejected, and a blank name on a type that requires one still fails as missing. Fixes #7706 --- .../apigateway/ApiGatewayService.java | 7 +- ...tewayDocumentationPartIntegrationTest.java | 68 +++++++++++++++++++ 2 files changed, 73 insertions(+), 2 deletions(-) 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 1ff171e0a9..818451b313 100644 --- a/src/main/java/io/floci/aws/services/apigateway/ApiGatewayService.java +++ b/src/main/java/io/floci/aws/services/apigateway/ApiGatewayService.java @@ -2531,11 +2531,14 @@ public class ApiGatewayService implements ResourceProvider, Resettable { || !Set.of("type", "path", "method", "statusCode", "name").contains(key)) { throw new AwsException("BadRequestException", "Invalid documentation part location", 400); } - location.put(key, fieldValue); + // Terraform sends unset location members as empty strings. + if (!fieldValue.isBlank()) { + location.put(key, fieldValue); + } } // AWS REST examples allow REQUEST_BODY without a name despite the model's required marker. if (DOCUMENTATION_PART_NAMED_TYPES.contains(type) && !"REQUEST_BODY".equals(type) - && (location.get("name") == null || location.get("name").isBlank())) { + && !location.containsKey("name")) { throw new AwsException("BadRequestException", "Documentation part location name is required", 400); } if (location.containsKey("name") && !DOCUMENTATION_PART_NAMED_TYPES.contains(type) diff --git a/src/test/java/io/floci/aws/services/apigateway/ApiGatewayDocumentationPartIntegrationTest.java b/src/test/java/io/floci/aws/services/apigateway/ApiGatewayDocumentationPartIntegrationTest.java index 68e1234eb5..02b9ae58fd 100644 --- a/src/test/java/io/floci/aws/services/apigateway/ApiGatewayDocumentationPartIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/apigateway/ApiGatewayDocumentationPartIntegrationTest.java @@ -192,6 +192,74 @@ class ApiGatewayDocumentationPartIntegrationTest { } } + @Test + void blankLocationFieldsAreTreatedAsAbsent() { + try (ApiGatewayClient client = client()) { + String apiId = client.createRestApi(request -> request.name("documentation-part-blank-fields")).id(); + try { + CreateDocumentationPartResponse api = client.createDocumentationPart(request -> request + .restApiId(apiId).location(DocumentationPartLocation.builder() + .type(DocumentationPartType.API).method("").name("").path("").statusCode("").build()) + .properties("{}")); + assertEquals(DocumentationPartLocation.builder().type(DocumentationPartType.API).build(), + api.location()); + assertThrows(ConflictException.class, () -> client.createDocumentationPart(request -> request + .restApiId(apiId).location(DocumentationPartLocation.builder() + .type(DocumentationPartType.API).build()) + .properties("{}"))); + + CreateDocumentationPartResponse model = client.createDocumentationPart(request -> request + .restApiId(apiId).location(DocumentationPartLocation.builder() + .type(DocumentationPartType.MODEL).name("Example").method("").path("") + .statusCode("").build()) + .properties("{\"title\":\"Example\"}")); + assertEquals(DocumentationPartLocation.builder().type(DocumentationPartType.MODEL) + .name("Example").build(), model.location()); + BadRequestException blankName = assertThrows(BadRequestException.class, + () -> client.createDocumentationPart(request -> request.restApiId(apiId) + .location(DocumentationPartLocation.builder().type(DocumentationPartType.MODEL) + .name("").build()) + .properties("{}"))); + assertEquals("Documentation part location name is required", blankName.awsErrorDetails().errorMessage()); + + CreateDocumentationPartResponse response = client.createDocumentationPart(request -> request + .restApiId(apiId).location(DocumentationPartLocation.builder() + .type(DocumentationPartType.RESPONSE).method("POST").path("/example") + .statusCode("200").name("").build()) + .properties("{\"description\":\"OK\"}")); + assertEquals(DocumentationPartLocation.builder().type(DocumentationPartType.RESPONSE) + .method("POST").path("/example").statusCode("200").build(), response.location()); + + CreateDocumentationPartResponse header = client.createDocumentationPart(request -> request + .restApiId(apiId).location(DocumentationPartLocation.builder() + .type(DocumentationPartType.RESPONSE_HEADER).name("X-Request-Id").statusCode("") + .build()) + .properties("{}")); + assertEquals(DocumentationPartLocation.builder().type(DocumentationPartType.RESPONSE_HEADER) + .name("X-Request-Id").path("/").method("*").statusCode("*").build(), header.location()); + } finally { + client.deleteRestApi(request -> request.restApiId(apiId)); + } + } + } + + @Test + void locationFieldInvalidForTypeIsRejected() { + try (ApiGatewayClient client = client()) { + String apiId = client.createRestApi(request -> request.name("documentation-part-invalid-field")).id(); + try { + BadRequestException invalid = assertThrows(BadRequestException.class, + () -> client.createDocumentationPart(request -> request.restApiId(apiId) + .location(DocumentationPartLocation.builder().type(DocumentationPartType.MODEL) + .name("Example").method("GET").build()) + .properties("{}"))); + assertEquals("Invalid documentation part location field", invalid.awsErrorDetails().errorMessage()); + } finally { + client.deleteRestApi(request -> request.restApiId(apiId)); + } + } + } + @Test void nullRequestBodyReturnsBadRequest() { try (ApiGatewayClient client = client()) {