From 93e72f965428451aa6d3f23b2bf7adcd5f22b286 Mon Sep 17 00:00:00 2001 From: Zhiwei Liang Date: Sun, 15 Nov 2026 23:08:18 +0000 Subject: [PATCH] [core] Share path and webhook operation processing in DefaultGenerator DefaultGenerator handled webhooks with a copy of the code for paths: processPaths(Paths) and processWebhooks(Map) were the same loop over the path items and their eight HTTP methods. Both now delegate to a private processPathItems(Map). The public methods are unchanged. No generated output changes. --- .../codegen/DefaultGenerator.java | 45 ++++++++----------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java index 32e007608571..9eab55acdb56 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java @@ -1482,14 +1482,28 @@ private File processTemplateToFile(Map templateData, String temp } public Map> processPaths(Paths paths) { + return processPathItems(paths); + } + + public Map> processWebhooks(Map webhooks) { + return processPathItems(webhooks); + } + + /** + * Collects the operations of the given path items (paths or webhooks), grouped by tag. + * + * @param pathItems The path items by path or webhook name, may be null + * @return The operations by tag + */ + private Map> processPathItems(Map pathItems) { Map> ops = new TreeMap<>(); - // when input file is not valid and doesn't contain any paths - if (paths == null) { + // no paths (the input file is not valid) or no webhooks + if (pathItems == null) { return ops; } - for (Map.Entry pathsEntry : paths.entrySet()) { - String resourcePath = pathsEntry.getKey(); - PathItem path = pathsEntry.getValue(); + for (Map.Entry pathItemEntry : pathItems.entrySet()) { + String resourcePath = pathItemEntry.getKey(); + PathItem path = pathItemEntry.getValue(); processOperation(resourcePath, "get", path.getGet(), ops, path); processOperation(resourcePath, "head", path.getHead(), ops, path); processOperation(resourcePath, "put", path.getPut(), ops, path); @@ -1502,27 +1516,6 @@ public Map> processPaths(Paths paths) { return ops; } - public Map> processWebhooks(Map webhooks) { - Map> ops = new TreeMap<>(); - // when input file is not valid and doesn't contain any paths - if (webhooks == null) { - return ops; - } - for (Map.Entry webhooksEntry : webhooks.entrySet()) { - String resourceKey = webhooksEntry.getKey(); - PathItem path = webhooksEntry.getValue(); - processOperation(resourceKey, "get", path.getGet(), ops, path); - processOperation(resourceKey, "head", path.getHead(), ops, path); - processOperation(resourceKey, "put", path.getPut(), ops, path); - processOperation(resourceKey, "post", path.getPost(), ops, path); - processOperation(resourceKey, "delete", path.getDelete(), ops, path); - processOperation(resourceKey, "patch", path.getPatch(), ops, path); - processOperation(resourceKey, "options", path.getOptions(), ops, path); - processOperation(resourceKey, "trace", path.getTrace(), ops, path); - } - return ops; - } - private void processOperation(String resourcePath, String httpMethod, Operation operation, Map> operations, PathItem path) { if (operation == null) { return;