[BUG] [aspnetcore] Template modification (-t/--template-dir) does not work
Bug Report Checklist
- [x] Have you provided a full/minimal spec to reproduce the issue?
- [x] Have you validated the input using an OpenAPI validator (example)?
- [x] What's the version of OpenAPI Generator used?
- [x] Have you search for related issues/PRs?
- [x] What's the actual output vs expected output?
- [ ] [Optional] Bounty to sponsor the fix (example)
Description
Custom templates provided via -t/--template-dir are not being applied for aspnetcore generator in 4.3.1. Works fine in 4.3.0
openapi-generator version
4.3.1
OpenAPI declaration file content or url
Command line used for generation
openapi-generator-cli generate -g aspnetcore -i input.yaml -o out-dir -t templates
Steps to reproduce
Modify any mustache template for aspnetcore, run generate with -t pointing to directory with modified template. Files are generated according to embedded template, any modifications are lost.
Related issues/PRs
Could not find any
Suggest a fix
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AspNetCoreServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AspNetCoreServerCodegen.java
index fcd882f6d9..403392e03c 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AspNetCoreServerCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AspNetCoreServerCodegen.java
@@ -547,7 +547,7 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
compatibilityVersion = "Version_" + aspnetCoreVersion.getOptValue().replace(".", "_");
}
LOGGER.info("ASP.NET core version: " + aspnetCoreVersion.getOptValue());
- embeddedTemplateDir = templateDir = "aspnetcore/" + determineTemplateVersion(aspnetCoreVersion.getOptValue());
+ embeddedTemplateDir = "aspnetcore/" + determineTemplateVersion(aspnetCoreVersion.getOptValue());
additionalProperties.put(COMPATIBILITY_VERSION, compatibilityVersion);
}
👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.
The team will review the labels and make any necessary changes.
Adding a +1 to this. My team is evaluating this capability right now and are running into issues with template overrides with aspnetcore as well.
Same here... I need to modify the template for the controllers to replace IActionResult with ActionResult<{{dataType}}>
@wing328 Any chance that this could be a point release prior to 5.0?
I remember there was a PR to fix it. Did you have a chance to try the latest master?
Also for the customization you guys mentioned, please also open an issue (ticket) for tracking as we can potentially incorporate these enhancements in the default template.
@wing328 Please disregard, the latest 5.0.0-beta worked flawlessly
@InfoSec812 thanks for the confirmation.