Light, fluffy, and always free - The AWS Local Emulator alternative
fix(apigateway): support _custom_id_ tag on create-rest-api (#644)
Hector Venturacb0a82b74957
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 66f352e2c6..7fd58d8abb 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@@ -1028,6 +1028,11 @@ public class ApiGatewayController {node.put("name", api.getName());if (api.getDescription() != null) node.put("description", api.getDescription());node.put("createdDate", api.getCreatedDate());+ if (api.getTags() != null && !api.getTags().isEmpty()) {+ ObjectNode tagsNode = objectMapper.createObjectNode();+ api.getTags().forEach(tagsNode::put);+ node.set("tags", tagsNode);+ }return node;}diff --git a/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayService.java b/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayService.javaindex d2b34a6739..4769bfefe7 100644--- a/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayService.java+++ b/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayService.java@@ -82,11 +82,19 @@ public class ApiGatewayService {String name = (String) request.get("name");String description = (String) request.get("description");+ @SuppressWarnings("unchecked")+ Map<String, String> tags = request.get("tags") instanceof Map<?, ?> m+ ? (Map<String, String>) m : new HashMap<>();++ String customId = tags.get("_custom_id_");+ String apiId = (customId != null && !customId.isBlank()) ? customId : shortId(10);+RestApi api = new RestApi();- api.setId(shortId(10));+ api.setId(apiId);api.setName(name);api.setDescription(description);api.setCreatedDate(System.currentTimeMillis() / 1000L);+ api.setTags(tags);apiStore.put(apiKey(region, api.getId()), api);diff --git a/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayIntegrationTest.javaindex 9880bab687..99ff795257 100644--- a/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayIntegrationTest.java@@ -336,4 +336,39 @@ class ApiGatewayIntegrationTest {.then().statusCode(404);}++ // ──────────────────────────── _custom_id_ tag ────────────────────────────++ @Test @Order(50)+ void createRestApi_customIdTag_usesTagValueAsApiId() {+ String body = """+ {"name":"custom-id-api","tags":{"_custom_id_":"MYCUSTOMNAME"}}+ """;+ given()+ .contentType(ContentType.JSON)+ .body(body)+ .when().post("/restapis")+ .then()+ .statusCode(201)+ .body("id", equalTo("MYCUSTOMNAME"))+ .body("tags._custom_id_", equalTo("MYCUSTOMNAME"));+ }++ @Test @Order(51)+ void getRestApi_customId_resolvesById() {+ given()+ .when().get("/restapis/MYCUSTOMNAME")+ .then()+ .statusCode(200)+ .body("id", equalTo("MYCUSTOMNAME"))+ .body("name", equalTo("custom-id-api"));+ }++ @Test @Order(52)+ void deleteRestApi_customId() {+ given()+ .when().delete("/restapis/MYCUSTOMNAME")+ .then()+ .statusCode(202);+ }}