oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

Generated clients fail to invoke `New...Request` with `value is a nil pointer` when using `prefer-skip-optional-pointer-with-omitzero`

Open jamietanna opened this issue 5 months ago • 3 comments

Also, if you generate clients with this:

  prefer-skip-optional-pointer: true
  prefer-skip-optional-pointer-with-omitzero: true

and add this to a parameter like this:

- name: parentTag
  in: header
  description: Version string of parent model, if any model
  x-go-type-skip-optional-pointer: false
  required: false
  schema:
    type: string
    example: parentTag

Client call will fail with value is a nil pointer error. If you remove x-go-type-skip-optional-pointer from the field, the client adds the parameters to the query even if they are zero-values, resulting in a 400 on the server side.

Originally posted by @juan-carvajal in #2044

jamietanna avatar Sep 03 '25 10:09 jamietanna

@juan-carvajal to confirm, what's the intent behind the x-go-type-skip-optional-pointer: false on the header parameter?

Just trying to confirm, as it'll generate:

	// ParentTag Version string of parent model, if any model
	ParentTag *string `json:"parentTag,omitempty"`

jamietanna avatar Sep 03 '25 10:09 jamietanna

Hmm, I think that this may be a case of incorrect location for the extension.

@juan-carvajal, with the following patch:

diff --git internal/test/issues/2074/api.yaml internal/test/issues/2074/api.yaml
index 458bb99..8287fd5 100644
--- internal/test/issues/2074/api.yaml
+++ internal/test/issues/2074/api.yaml
@@ -17,11 +17,11 @@ paths:
         - name: parentTag
           in: header
           description: Version string of parent model, if any model
-          x-go-type-skip-optional-pointer: false
           required: false
           schema:
             type: string
             example: parentTag
+            x-go-type-skip-optional-pointer: false

I see that this gets generated correctly - check out #2075 for an example

Let me know if this is what you were looking for!

jamietanna avatar Sep 03 '25 10:09 jamietanna

Hi @jamietanna ! Will take a look, thanks for looking into it.

juan-carvajal avatar Sep 04 '25 15:09 juan-carvajal