From 5ab9e7122c7d6def455480b856ab2804ce5d60f0 Mon Sep 17 00:00:00 2001 From: Zhiwei Liang Date: Mon, 16 Nov 2026 03:59:07 +0000 Subject: [PATCH] [core] Build the operation map for APIs and webhooks with one helper In DefaultGenerator, processOperations and processWebhooks(config, tag, ...) built their OperationMap with the same code: class name, path prefix and, if the generator asks for it, unique nicknames. That code moves to a private toOperationMap(config, tag, ops). The OperationsMap and WebhooksMap types and the postProcessOperationsWithModels and postProcessWebhooksWithModels hooks are unchanged, and the calls on the generator configuration happen in the same order as before. No generated output changes. --- .../codegen/DefaultGenerator.java | 74 +++++++++---------- 1 file changed, 34 insertions(+), 40 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..0875bac1ed67 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 @@ -1647,26 +1647,7 @@ private static String generateParameterId(Parameter parameter) { private OperationsMap processOperations(CodegenConfig config, String tag, List ops, List allModels) { OperationsMap operations = new OperationsMap(); - OperationMap objs = new OperationMap(); - objs.setClassname(config.toApiName(tag)); - objs.setPathPrefix(config.toApiVarName(tag)); - - // check for nickname uniqueness - if (config.getAddSuffixToDuplicateOperationNicknames()) { - Set opIds = new HashSet<>(); - int counter = 0; - for (CodegenOperation op : ops) { - String opId = op.nickname; - if (opIds.contains(opId)) { - counter++; - op.nickname += "_" + counter; - } - opIds.add(opId); - } - } - objs.setOperation(ops); - - operations.setOperation(objs); + operations.setOperation(toOperationMap(config, tag, ops)); operations.put("package", config.apiPackage()); Set allImports = new ConcurrentSkipListSet<>(); @@ -1691,26 +1672,7 @@ private OperationsMap processOperations(CodegenConfig config, String tag, List wks, List allModels) { WebhooksMap operations = new WebhooksMap(); - OperationMap objs = new OperationMap(); - objs.setClassname(config.toApiName(tag)); - objs.setPathPrefix(config.toApiVarName(tag)); - - // check for nickname uniqueness - if (config.getAddSuffixToDuplicateOperationNicknames()) { - Set opIds = new HashSet<>(); - int counter = 0; - for (CodegenOperation op : wks) { - String opId = op.nickname; - if (opIds.contains(opId)) { - counter++; - op.nickname += "_" + counter; - } - opIds.add(opId); - } - } - objs.setOperation(wks); - - operations.setWebhooks(objs); + operations.setWebhooks(toOperationMap(config, tag, wks)); operations.put("package", config.apiPackage()); Set allImports = new ConcurrentSkipListSet<>(); @@ -1733,6 +1695,38 @@ private WebhooksMap processWebhooks(CodegenConfig config, String tag, List ops) { + OperationMap objs = new OperationMap(); + objs.setClassname(config.toApiName(tag)); + objs.setPathPrefix(config.toApiVarName(tag)); + + // check for nickname uniqueness + if (config.getAddSuffixToDuplicateOperationNicknames()) { + Set opIds = new HashSet<>(); + int counter = 0; + for (CodegenOperation op : ops) { + String opId = op.nickname; + if (opIds.contains(opId)) { + counter++; + op.nickname += "_" + counter; + } + opIds.add(opId); + } + } + objs.setOperation(ops); + return objs; + } + /** * Transforms a set of imports to a map with key config.toModelImport(import) and value the import string. *