Closed
Description
Problem statement
go-swagger generate client generates wrong value type in default parameters for a
swagger formData parameter of type []string
Swagger specification
https://raw.githubusercontent.com/CurrencyCloud/currencycloud-swagger/master/src/reference.yaml
This is the parameter that is the problem:
- name: payment_types[]
in: formData
required: false
type: array
items:
type: string
enum:
- priority
- regular
default:
- regular
description: >-
Currencycloud supports two types of payment: "priority", made
using the SWIFT network; and "regular", made using the local bank
network.
Steps to reproduce
mkdir -p $GOPATH/src/github.com/nkobber/go-swagger-test/currencycloud
cd $GOPATH/src/github.com/nkobber/go-swagger-test
curl https://raw.githubusercontent.com/CurrencyCloud/currencycloud-swagger/master/src/reference.yaml --output swagger.yaml
swagger generate client --target ./currencycloud --name currencycloud
go build ./...
Produces
# go build ./...
# github.com/nkobber/go-swagger-test/currencycloud/client/beneficiaries
currencycloud/client/beneficiaries/create_beneficiary_parameters.go:31:3: cannot use paymentTypesDefault (type []interface {}) as type []string in field value
currencycloud/client/beneficiaries/create_beneficiary_parameters.go:46:3: cannot use paymentTypesDefault (type []interface {}) as type []string in field value
currencycloud/client/beneficiaries/create_beneficiary_parameters.go:61:3: cannot use paymentTypesDefault (type []interface {}) as type []string in field value
currencycloud/client/beneficiaries/create_beneficiary_parameters.go:76:3: cannot use paymentTypesDefault (type []interface {}) as type []string in field value
currencycloud/client/beneficiaries/update_beneficiary_parameters.go:31:3: cannot use paymentTypesDefault (type []interface {}) as type []string in field value
currencycloud/client/beneficiaries/update_beneficiary_parameters.go:46:3: cannot use paymentTypesDefault (type []interface {}) as type []string in field value
currencycloud/client/beneficiaries/update_beneficiary_parameters.go:61:3: cannot use paymentTypesDefault (type []interface {}) as type []string in field value
currencycloud/client/beneficiaries/update_beneficiary_parameters.go:76:3: cannot use paymentTypesDefault (type []interface {}) as type []string in field value
currencycloud/client/beneficiaries/validate_beneficiary_parameters.go:29:3: cannot use paymentTypesDefault (type []interface {}) as type []string in field value
currencycloud/client/beneficiaries/validate_beneficiary_parameters.go:42:3: cannot use paymentTypesDefault (type []interface {}) as type []string in field value
currencycloud/client/beneficiaries/validate_beneficiary_parameters.go:42:3: too many errors
create_beneficiary_parameters.go:
func NewCreateBeneficiaryParams() *CreateBeneficiaryParams {
var (
defaultBeneficiaryDefault = bool(false)
paymentTypesDefault = []interface{}{"regular"}
)
return &CreateBeneficiaryParams{
DefaultBeneficiary: &defaultBeneficiaryDefault,
PaymentTypes: paymentTypesDefault,
timeout
6AFF
span>: cr.DefaultTimeout,
}
}
should instead be
func NewCreateBeneficiaryParams() *CreateBeneficiaryParams {
var (
defaultBeneficiaryDefault = bool(false)
paymentTypesDefault = []string{"regular"}
)
return &CreateBeneficiaryParams{
DefaultBeneficiary: &defaultBeneficiaryDefault,
PaymentTypes: paymentTypesDefault,
timeout: cr.DefaultTimeout,
}
}
Let me know if you need any more info
Environment
swagger version: v0.17.0, 0.16.0, 0.13.0
Go version: 1.11
OS: macOS Mojave 10.14