Skip to content

Generated CLI does not compile when using arrays as query parameters #2735

@kevinbarbour

Description

@kevinbarbour

Problem statement

When generating a CLI from the enclosed swagger spec the code produced does not compile.
The code that is generated tries to assign a value of type *[]int64 to a variable of type []int64.

➜ go build ./gen/cmd/cli                                 
# github.com/kevinbarbour/scratch/gen/cli
gen/cli/get_pet_operation.go:99:9: cannot use &idsFlagValues (type *[]int64) as type []int64 in assignment

Is seems that the problem comes from the retrieveflag template assuming that any Nullable parameter should be assigned as a pointer which is not true for these slices.

Swagger specification

swagger: "2.0"
info:
  title: "sample"
  version: "1"
paths:
  /pet:
    get:
      parameters:
      - in: "query"
        name: "ids"
        type: "array"
        items:
          type: "integer"
      responses:
        200:
          description: "good"

Steps to reproduce

Generate a CLI from the above swagger spec and attempt to run or compile it.

Environment

go version: go1.17.8
OS: macOS 12.2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions