Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,13 @@ public void processOpts() {
additionalProperties.put("feign-okhttp", "true");
} else if (isLibrary(FEIGN_HC5)) {
additionalProperties.put("feign-hc5", "true");
setTemplateDir(FEIGN);
// Only fall back to the built-in "feign" template directory when the user has not
// provided a custom template directory. super.processOpts() already wrote any
// user-supplied templateDir back into additionalProperties, so checking for the
// key's presence reliably distinguishes "user provided" from "not provided".
if (!additionalProperties.containsKey(CodegenConstants.TEMPLATE_DIR)) {
setTemplateDir(FEIGN);
}
setLibrary(FEIGN);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4180,4 +4180,35 @@ public void testOneOfInterfaceWithEnumDiscriminatorHavingCustomDescription3_1()
.fileContains("public FruitType getFruitType()");
}

/**
* Regression: without a user-provided template dir, feign-hc5 should still resolve
* built-in templates from the "feign" folder (same behaviour as before the fix).
*/
@Test
public void testFeignHc5TemplateDirDefaultsToFeign() {
final JavaClientCodegen codegen = new JavaClientCodegen();
codegen.setLibrary(FEIGN_HC5);
codegen.processOpts();

assertEquals(codegen.templateDir(), FEIGN,
"feign-hc5 without a custom templateDir should use the 'feign' built-in template directory");
}

/**
* Bug fix: a user-provided templateDir must not be overwritten when library=feign-hc5.
* Previously setTemplateDir(FEIGN) was called unconditionally and silently replaced the
* user's path.
*/
@Test
public void testFeignHc5CustomTemplateDirIsPreserved() {
final String customTemplateDir = "/custom/templates";
final JavaClientCodegen codegen = new JavaClientCodegen();
codegen.setLibrary(FEIGN_HC5);
codegen.additionalProperties().put(CodegenConstants.TEMPLATE_DIR, customTemplateDir);
codegen.processOpts();

assertEquals(codegen.templateDir(), customTemplateDir,
"feign-hc5 must preserve a user-provided templateDir and not overwrite it with 'feign'");
}

}