From 80c6473efe9fa31793353e457fdbf7dae99d7920 Mon Sep 17 00:00:00 2001 From: nenzen Date: Tue, 11 Nov 2025 10:52:30 +0100 Subject: [PATCH 1/2] Fix PathItem bug --- .../dsv/su/apimposter/io/MockFileLoader.java | 6 ++-- .../dsv/su/apimposter/io/MockFileParser.java | 8 ++--- .../su/apimposter/service/OpenApiService.java | 33 +++++++++---------- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/main/java/dsv/su/apimposter/io/MockFileLoader.java b/src/main/java/dsv/su/apimposter/io/MockFileLoader.java index acffdf5..7e5b543 100644 --- a/src/main/java/dsv/su/apimposter/io/MockFileLoader.java +++ b/src/main/java/dsv/su/apimposter/io/MockFileLoader.java @@ -71,7 +71,7 @@ public class MockFileLoader { @Scheduled(fixedDelayString = "${mock.reload-interval-ms}") public void reloadIfChanged() { if (hasChanged()) { - LOGGER.info("🔄 Reloading mock files..."); + LOGGER.info("Reloading mock files..."); reload(); } } @@ -135,7 +135,7 @@ public class MockFileLoader { openApiService.rebuild(endpoints); } catch (IOException e) { - LOGGER.error("❌ Failed to reload mock files: {}", e.getMessage()); + LOGGER.error("Failed to reload mock files: {}", e.getMessage()); } } @@ -176,7 +176,7 @@ public class MockFileLoader { }); } } catch (Exception e) { - LOGGER.error("❌ Failed to load globals from {}: {}", file, e.getMessage()); + LOGGER.error("Failed to load globals from {}: {}", file, e.getMessage()); } } } diff --git a/src/main/java/dsv/su/apimposter/io/MockFileParser.java b/src/main/java/dsv/su/apimposter/io/MockFileParser.java index a9e638e..f57b8b2 100644 --- a/src/main/java/dsv/su/apimposter/io/MockFileParser.java +++ b/src/main/java/dsv/su/apimposter/io/MockFileParser.java @@ -55,13 +55,13 @@ public class MockFileParser { // Handle empty file if (root == null) { - LOGGER.warn("⚠️ Skipping empty YAML file: {}", file); + LOGGER.warn("Skipping empty YAML file: {}", file); return; } // Ensure the root YAML object is a list if (!(root instanceof List rawList)) { - LOGGER.error("❌ Expected a YAML list in file: {} but got {}", file, root.getClass().getSimpleName()); + LOGGER.error("Expected a YAML list in file: {} but got {}", file, root.getClass().getSimpleName()); return; } @@ -82,12 +82,12 @@ public class MockFileParser { endpoints.add(endpoint); } catch (Exception e) { - LOGGER.error("⚠️ Skipping invalid endpoint in " + file + ": " + e.getMessage()); + LOGGER.error("Skipping invalid endpoint in " + file + ": " + e.getMessage()); } } } catch (Exception e) { - LOGGER.error("❌ Failed to parse " + file + ": " + e.getMessage()); + LOGGER.error("Failed to parse " + file + ": " + e.getMessage()); } } } diff --git a/src/main/java/dsv/su/apimposter/service/OpenApiService.java b/src/main/java/dsv/su/apimposter/service/OpenApiService.java index 6b7d3ce..70c1a80 100644 --- a/src/main/java/dsv/su/apimposter/service/OpenApiService.java +++ b/src/main/java/dsv/su/apimposter/service/OpenApiService.java @@ -53,28 +53,27 @@ public class OpenApiService { .tags(List.of(extractTag(path))) .parameters(pathParams(path)); - PathItem item = getPathItem(endpoint, operation); + // Check if PathItem already exists for this path + PathItem item = api.getPaths().get(path); + if (item == null) { + item = new PathItem(); + } + + // Add operation to existing PathItem based on method + HttpMethod method = endpoint.getMethod(); + switch (method) { + case GET -> item.get(operation); + case POST -> item.post(operation); + case PUT -> item.put(operation); + case DELETE -> item.delete(operation); + case PATCH -> item.patch(operation); + } + api.getPaths().addPathItem(path, item); } this.openAPI = api; } - /** - * Builds an OpenAPI {@link PathItem} object for a given mock endpoint and operation. - * @param endpoint the mock endpoint to describe - * @param operation the operation to associate with the endpoint - * @return the generated {@link PathItem} - */ - private static PathItem getPathItem(MockEndpoint endpoint, Operation operation) { - HttpMethod method = endpoint.getMethod(); - return switch (method) { - case GET -> new PathItem().get(operation); - case POST -> new PathItem().post(operation); - case PUT -> new PathItem().put(operation); - case DELETE -> new PathItem().delete(operation); - case PATCH -> new PathItem().patch(operation); - }; - } /** * Returns the most recently built OpenAPI specification. -- 2.39.5 From b1ff9d440faef34f66013f929cfb88cfb7c6e824 Mon Sep 17 00:00:00 2001 From: nenzen Date: Tue, 11 Nov 2025 10:56:28 +0100 Subject: [PATCH 2/2] Checkstyle fix --- src/main/java/dsv/su/apimposter/service/OpenApiService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/dsv/su/apimposter/service/OpenApiService.java b/src/main/java/dsv/su/apimposter/service/OpenApiService.java index 70c1a80..acb0788 100644 --- a/src/main/java/dsv/su/apimposter/service/OpenApiService.java +++ b/src/main/java/dsv/su/apimposter/service/OpenApiService.java @@ -67,6 +67,7 @@ public class OpenApiService { case PUT -> item.put(operation); case DELETE -> item.delete(operation); case PATCH -> item.patch(operation); + default -> throw new IllegalArgumentException("Unsupported HTTP method: " + method); } api.getPaths().addPathItem(path, item); -- 2.39.5