Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][Go] Inability to search using null param #20026

Open
2 of 6 tasks
ezeriver94 opened this issue Nov 5, 2024 · 0 comments
Open
2 of 6 tasks

[BUG][Go] Inability to search using null param #20026

ezeriver94 opened this issue Nov 5, 2024 · 0 comments

Comments

@ezeriver94
Copy link

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

Openapi.yaml

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)
			}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant