8000 go-swagger generate client generates wrong default formData parameter type for array of strings · Issue #1753 · go-swagger/go-swagger · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
go-swagger generate client generates wrong default formData parameter type for array of strings #1753
Closed
@nkobber

Description

@nkobber

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: 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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0