Light, fluffy, and always free - The AWS Local Emulator alternative
fix(apigateway): accept any Content-Type on Put/ImportRestApi (#925)
Ahmed Solimanb8d1b817c9e8
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.javaindex 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.javaindex 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