Skip to content

Commit 1d3ef5c

Browse files
authored
fix(java): preserve user templateDir for feign-hc5 library (#23231)
1 parent 1cf040f commit 1d3ef5c

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,13 @@ public void processOpts() {
850850
additionalProperties.put("feign-okhttp", "true");
851851
} else if (isLibrary(FEIGN_HC5)) {
852852
additionalProperties.put("feign-hc5", "true");
853-
setTemplateDir(FEIGN);
853+
// Only fall back to the built-in "feign" template directory when the user has not
854+
// provided a custom template directory. super.processOpts() already wrote any
855+
// user-supplied templateDir back into additionalProperties, so checking for the
856+
// key's presence reliably distinguishes "user provided" from "not provided".
857+
if (!additionalProperties.containsKey(CodegenConstants.TEMPLATE_DIR)) {
858+
setTemplateDir(FEIGN);
859+
}
854860
setLibrary(FEIGN);
855861
}
856862

modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4180,4 +4180,35 @@ public void testOneOfInterfaceWithEnumDiscriminatorHavingCustomDescription3_1()
41804180
.fileContains("public FruitType getFruitType()");
41814181
}
41824182

4183+
/**
4184+
* Regression: without a user-provided template dir, feign-hc5 should still resolve
4185+
* built-in templates from the "feign" folder (same behaviour as before the fix).
4186+
*/
4187+
@Test
4188+
public void testFeignHc5TemplateDirDefaultsToFeign() {
4189+
final JavaClientCodegen codegen = new JavaClientCodegen();
4190+
codegen.setLibrary(FEIGN_HC5);
4191+
codegen.processOpts();
4192+
4193+
assertEquals(codegen.templateDir(), FEIGN,
4194+
"feign-hc5 without a custom templateDir should use the 'feign' built-in template directory");
4195+
}
4196+
4197+
/**
4198+
* Bug fix: a user-provided templateDir must not be overwritten when library=feign-hc5.
4199+
* Previously setTemplateDir(FEIGN) was called unconditionally and silently replaced the
4200+
* user's path.
4201+
*/
4202+
@Test
4203+
public void testFeignHc5CustomTemplateDirIsPreserved() {
4204+
final String customTemplateDir = "/custom/templates";
4205+
final JavaClientCodegen codegen = new JavaClientCodegen();
4206+
codegen.setLibrary(FEIGN_HC5);
4207+
codegen.additionalProperties().put(CodegenConstants.TEMPLATE_DIR, customTemplateDir);
4208+
codegen.processOpts();
4209+
4210+
assertEquals(codegen.templateDir(), customTemplateDir,
4211+
"feign-hc5 must preserve a user-provided templateDir and not overwrite it with 'feign'");
4212+
}
4213+
41834214
}

0 commit comments

Comments
 (0)