Open superboum opened 1 year ago
Another case, where generated helper functions are problematic is when there are two fields, one named with prefix has
together with the name of the other field. So for example previousPage
and hasPreviousPage
. In that case (at least if previousPage
is not a required field), a helper method is generated for optional previousPage
field:
// HasPrevPage returns a boolean if a field has been set.
func (o *PaginatedDto) HasPreviousPage() bool {
if o != nil && !IsNil(o.PrevPage) {
return true
}
return false
}
The code is not compiling because generated dto struct has field and method with same name:
Type '*PaginatedDto' has both field and method named 'HasPreviousPage'
As nice, as it is, to have all the convenient helper functions, I think it would be better / more robust, if only one getter and one setter would be generated for each field. If the getter would return value and ok
bool, functionality wouldn't suffer, I think.
thanks for reporting the issue.
looks like we need an option to skip these helper methods, right?
please use name mappings option to workaround these issues for the time being, e.g.
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g go -i /tmp/aa.yaml -o /tmp/gogo2 --name-mappings barOk=barAlright
ref: https://github.com/openapitools/openapi-generator/blob/master/docs/customization.md#name-mapping
Bug Report Checklist
Description
When I try to load a Go library generated from an OpenAPI spec containing 2 fields, one named
bar
and the other onebarOk
, I get the following error:I expect to load the library without an error, and more specifically, I expect that OpenAPI does not generate two functions with the same name in the same file / module / namespace.
openapi-generator version
I don't think it's a regression, I detected the bug after we extended our API with this 2 fields. In other words, I can't say if the bug has always been present or has been added after some changes.
OpenAPI declaration file content or url
Generation Details
How I generate the Golang library:
Then when I try to build it:
I get the following error:
Function at line 54:
Function at line 76:
Steps to reproduce
Check the section above.
Related issues/PRs
I have not found any related issue
Suggest a fix
I don't know how to fix this bug now. I don't have any workaround yet except manually patching the generated code.