From b8d1b817c9e84358ec2a7fafffa06e5dae1d7bca Mon Sep 17 00:00:00 2001 From: Ahmed Soliman <46458090+ahmd-soliman@users.noreply.github.com> Date: Tue, 19 May 2026 07:42:26 +0200 Subject: [PATCH] fix(apigateway): accept any Content-Type on Put/ImportRestApi (#925) * fix(apigateway): accept any Content-Type on PutRestApi and ImportRestApi The class-level @Consumes restricted these endpoints to application/json and application/json-patch+json, so JAX-RS returned 415 for any other Content-Type. The Terraform AWS provider sends the OpenAPI body as application/octet-stream, which broke aws_api_gateway_rest_api with an inline body. Use @Consumes(WILDCARD) on createRestApi and putRestApi, matching the pattern already used for opaque-body endpoints in BedrockRuntime, S3Control, and AppConfig. The underlying Swagger parser content-sniffs the body, so JSON and YAML payloads keep working regardless of the declared Content-Type. Closes #855 * ci: re-trigger sdk-test-node after transient npm registry 404 --- .../apigateway/ApiGatewayController.java | 2 + .../ApiGatewayOpenApiImportTest.java | 74 +++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayController.java b/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayController.java index 8b3ad8222b..a46099ac55 100644 --- a/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayController.java +++ b/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayController.java @@ -222,6 +222,7 @@ public class ApiGatewayController { @POST @Path("/restapis") + @Consumes(MediaType.WILDCARD) public Response createRestApi(@Context HttpHeaders headers, @QueryParam("mode") String mode, String body) { @@ -242,6 +243,7 @@ public class ApiGatewayController { @PUT @Path("/restapis/{apiId}") + @Consumes(MediaType.WILDCARD) public Response putRestApi(@Context HttpHeaders headers, @PathParam("apiId") String apiId, @QueryParam("mode") String mode, diff --git a/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayOpenApiImportTest.java b/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayOpenApiImportTest.java index 02c356eea3..0d1df24385 100644 --- a/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayOpenApiImportTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayOpenApiImportTest.java @@ -1288,6 +1288,80 @@ class ApiGatewayOpenApiImportTest { given().delete("/restapis/" + apiId); } + // ──────────────────────────── Content-Type Tolerance ──────────────────────────── + + @Test + @Order(70) + void importRestApi_octetStreamContentType() throws Exception { + String spec = """ + {"openapi": "3.0.1", "info": {"title": "OctetImport", "version": "1.0"}, "paths": {}} + """; + String body = given() + .contentType("application/octet-stream") + .queryParam("mode", "import") + .body(spec.getBytes()) + .when() + .post("/restapis") + .then() + .statusCode(201) + .body("name", equalTo("OctetImport")) + .extract().body().asString(); + + String apiId = mapper.readTree(body).get("id").asText(); + given().delete("/restapis/" + apiId); + } + + @Test + @Order(71) + void putRestApi_noContentType() throws Exception { + String createBody = given() + .contentType(ContentType.JSON) + .body("{\"name\": \"NoCtype\"}") + .post("/restapis") + .then().statusCode(201).extract().body().asString(); + String apiId = mapper.readTree(createBody).get("id").asText(); + + String spec = """ + {"openapi": "3.0.1", "info": {"title": "NoCtypeOverwritten", "version": "1.0"}, "paths": {}} + """; + given() + .queryParam("mode", "overwrite") + .body(spec.getBytes()) + .when() + .put("/restapis/" + apiId) + .then() + .statusCode(200) + .body("name", equalTo("NoCtypeOverwritten")); + + given().delete("/restapis/" + apiId); + } + + @Test + @Order(72) + void putRestApi_octetStreamContentType() throws Exception { + String createBody = given() + .contentType(ContentType.JSON) + .body("{\"name\": \"OctetOverwrite\"}") + .post("/restapis") + .then().statusCode(201).extract().body().asString(); + String apiId = mapper.readTree(createBody).get("id").asText(); + + String spec = """ + {"openapi": "3.0.1", "info": {"title": "OctetOverwritten", "version": "1.0"}, "paths": {}} + """; + given() + .contentType("application/octet-stream") + .queryParam("mode", "overwrite") + .body(spec.getBytes()) + .when() + .put("/restapis/" + apiId) + .then() + .statusCode(200) + .body("name", equalTo("OctetOverwritten")); + + given().delete("/restapis/" + apiId); + } + // ──────────────────────────── Cleanup ──────────────────────────── @Test