OpenAPITools / OpenAPITools/openapi-generator
[BUG][Go] Inability to search using null param
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
When there is a query param in the form of array of nullable elements, there is no way to use it to search for that property being nil. The method parameterAddToHeaderOrQuery apparently supports it by checking
if v == reflect.ValueOf(nil) {
value = "null"
}
but is not enough as the element received, if nil, doesn't make that assertion true.
openapi-generator version
7.9.0
OpenAPI declaration file content or url
Generation Details
docker run --rm --env JAVA_OPTS=-DmaxYamlCodePoints=9999999 -v "${PWD}:/local" openapitools/openapi-generator-cli:v7.9.0 \
generate \
--config /local/.openapi-generator/config.yaml \
--input-spec /local/api/openapi.yaml \
--output /local \
--inline-schema-options RESOLVE_INLINE_ENUMS=true \
--http-user-agent go-netbox/$(cat api/netbox_version)
Steps to reproduce
Based on the Openapi example provided before, I can run
client.DcimAPI.DcimDevicesList(ctx).ClusterId([]*int32{nil}).Execute()
to search for devices with cluster_id=nil. This will fail in parameterAddToHeaderOrQuery as it enters in the case
case reflect.Ptr:
parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, v.Elem().Interface(), style, collectionType)
return
and panics in v.Elem().Interface() as the pointer is nil
Suggest a fix
My issue was fixed when manually editing the mentioned method considering the pointer being nil
if v.IsNil(){
parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, nil, style, collectionType)
} else {
parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, v.Elem().Interface(), style, collectionType)
}
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
Start by locating the Go client's parameterAddToHeaderOrQuery method and reproduce the issue with DcimAPI.DcimDevicesList(ctx).ClusterId([]*int32{nil}).Execute(). Trace the reflect.Ptr handling for a nil pointer and verify that the request represents the nullable query element as null without panicking. Add or update a regression test if the relevant test location is identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100