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 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.java index 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 tags = request.get("tags") instanceof Map m + ? (Map) 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.java index 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); + } }