OpenAPITools / OpenAPITools/openapi-generator
[BUG] go code generator creates invalid code for models with a field prefixed with "has_"
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The Snowflake REST API specs has a User schema with field "HasPassword". If you use openapi-generator to generate go code from these, it generates a struct field named HasPassword as well as a function HasPassword, and these conflict, leading to compilation failure
openapi-generator version
7.12.0
OpenAPI declaration file content or url
Generation Details
wget https://raw.githubusercontent.com/snowflakedb/snowflake-rest-api-specs/refs/heads/main/releases/8.40/specifications/user.yaml
wget https://raw.githubusercontent.com/snowflakedb/snowflake-rest-api-specs/refs/heads/main/releases/8.40/specifications/common.yaml
openapi-generator generate -g go -i user.yaml --git-user-id=snowflakedb --git-repo-id=snowflake-rest-api-specs -o built/
cd built
go get github.com/stretchr/testify/assert
go get golang.org/x/oauth2
go get golang.org/x/net/context
go build
This yields the following compiler errors
./model_user.go:164:16: field and method with the same name HasPassword
./model_user.go:76:2: other declaration of HasPassword
./model_user.go:676:16: field and method with the same name HasRsaPublicKey
./model_user.go:77:2: other declaration of HasRsaPublicKey
./model_user.go:983:10: invalid operation: cannot indirect o.HasPassword (value of type func() bool)
./model_user.go:992:9: cannot use o.HasPassword (value of type func() bool) as *bool value in return statement
./model_user.go:1006:2: cannot assign to o.HasPassword (neither addressable nor a map index expression)
./model_user.go:1015:10: invalid operation: cannot indirect o.HasRsaPublicKey (value of type func() bool)
./model_user.go:1024:9: cannot use o.HasRsaPublicKey (value of type func() bool) as *bool value in return statement
./model_user.go:1038:2: cannot assign to o.HasRsaPublicKey (neither addressable nor a map index expression)
Steps to reproduce
- See CLI steps
Related issues/PRs
Suggest a fix
Have the generator come up with a better name for the Has* functions, or add a way to skip these.
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
Reproduce the issue with the Snowflake specification and the openapi-generator CLI commands in the report, then inspect generated model_user.go and its Go compiler errors. Trace the Go generator logic that produces the HasPassword and HasRsaPublicKey fields and methods; done means generated code builds without those name conflicts and the behavior has regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100