mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
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
This commit is contained in:
1 parent
ef785e3269
commit
91ec6d29ef
2 files changed
+73
-2
No files matched your search
@@ -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)
|
||||
|
||||
+68
@@ -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()) {
|
||||
|
||||
Reference in new issue
Block a user