-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Labels
Description
Problem statement
The code generator emits invalid go code for parameters of array types that have an empty array as default value, e.g.:
- sample input
swagger: "2.0"
info:
title: Sample API
description: API description in Markdown.
version: 1.0.0
host: api.example.com
basePath: /v1
schemes:
- https
paths:
/users:
get:
summary: Returns a list of users in certain locations.
description: Optional extended description in Markdown.
produces:
- application/json
responses:
200:
description: OK
parameters:
- name: locations
in: query
type: array
description: Locations filter
default: []
items:
type: string
- trying to generate a client:
$ swagger generate client -f swagger.yml
2021/03/09 10:04:16 validating spec /tmp/swagger-test/swagger.yml
2021/03/09 10:04:16 preprocessing spec with option: minimal flattening
2021/03/09 10:04:16 building a plan for generation
2021/03/09 10:04:16 generation target ./
2021/03/09 10:04:16 planning definitions (found: 0)
2021/03/09 10:04:16 planning operations (found: 1)
2021/03/09 10:04:16 grouping operations into packages (packages: 1)
2021/03/09 10:04:16 operations for package packages "operations" (found: 1)
2021/03/09 10:04:16 planning meta data and facades
2021/03/09 10:04:16 rendering 2 templates for operation
2021/03/09 10:04:16 name field GetUsers
2021/03/09 10:04:16 package field operations
2021/03/09 10:04:16 creating generated file "get_users_parameters.go" in "client/operations" as parameters
2021/03/09 10:04:16 executed template asset:clientParameter
2021/03/09 10:04:16 source formatting failed on template-generated source ("client/operations/get_users_parameters.go" for parameters). Check that your template produces valid code
2021/03/09 10:04:16 unformatted generated source "get_users_parameters.go" has been dumped for template debugging purposes. DO NOT build on this source!
source formatting on generated source "parameters" failed: client/operations/get_users_parameters.go:96:37: expected operand, found ',' (and 10 more errors)
- inspecting
client/operations/get_users_parameters.go
:
[...]
/ SetDefaults hydrates default values in the get users params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *GetUsersParams) SetDefaults() {
var (
locationsDefault = []string{,}
)
[...]