OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Go] api.mustache template change to use strings.replace for localVarPath not importing strings lib
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
Modified api.mustache template to replace localVarPath. In files where strings package is not already present by default, generator is not importing the lib for strings causing compilation failure. Manually adding the imports causes duplicate import error.
openapi-generator version
4.3.1
OpenAPI declaration file content or url
https://gist.github.com/shylasrinivas/ba6cc06dbc5a731b00f5d06d0bb6d8ee
Line in api.mustache causing this issue -
localVarPath = strings.Replace(localVarPath, "__", "?" , -1)
Command line used for generation
openapi-generator generate -g go -p enumClassPrefix=true -p structPrefix=true -t ~/bindings/templates -i hcl.yaml -o ~/bindings/hcl
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/issues/5231
Suggest a fix
Used import alias functionality in go and added another import for strings Eg: strings and _strings. This fixes the compilation issue, however the code in the bindings does not look good.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Inspect the api.mustache template and the localVarPath strings.Replace line, then reproduce generation with the provided OpenAPI declaration and command. Confirm that generated Go files compile when strings was not previously imported and that existing strings imports do not become duplicates.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100