Skip to content

x-go-type-skip-optional-pointer not respected for optional map/slice-typed query parameters #2329

@benweint

Description

@benweint

When a map or slice-typed query parameter has x-go-type-skip-optional-pointer: true set, the generated type correctly lacks a pointer, but the generated client code in the New*Request assumes one, leading to a compilation error in the generated code.

oadpi-codegen version: 2.6.0 and latest main (c2095464aea566dafda7ff63b66b0f7e4fb51b42)
Go version: 1.25.0

Here's a simple repro case:

spec.yaml:

openapi: "3.0.0"
info:
  title: Reproduction
  version: "1.0"
paths:
  /things:
    get:
      operationId: listThings
      parameters:
        - name: tags
          in: query
          style: deepObject
          x-go-type-skip-optional-pointer: true
          schema:
            type: object
            additionalProperties:
              type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      type: string

config.yaml

package: api
generate:
  client: true
  models: true
output: api.gen.go

The generated params struct correctly omits the pointer:

type ListThingsParams struct {
	Tags map[string]string `json:"tags,omitempty"`
}

But the generated client code still tries to dereference it:

if params.Tags != nil {
    if queryFrag, err := runtime.StyleParamWithOptions("deepObject", true, "tags", *params.Tags, ...); err != nil {
    //                                                                            ^^^^^^^^^^^^^
    //                                                                            BUG: cannot indirect a map

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions