Repository: go-swagger/go-swagger (go)

Issue:
Optional Headers array parameters generated client code doesn't compile
## Problem statement
When generating code for an API describing a header parameter X of array type, I got a "joinedX declared but not used" compilation error.

## Swagger specification
https://swagger.io/docs/specification/2-0/describing-parameters/#array-and-multi-value-parameters

```yaml
swagger: '2.0'
# ...
paths:
  /example:
    post:
        summary: example
        description: ''
        operationId: examplePost
        parameters:
          - name: Foo
            in: header
            type: array
            required: false
            items:
              type: string
            description: 'a reproducer for this ticket'
```

The corresponding generated code is incorrect functionnally (parameter isn't bound to the request) and doesn't even compile:
```go
// WriteToRequest writes these params to a swagger request
func (o *FooParam) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
        // ...
	valuesFoo := o.Foo
	joinedFoo := swag.JoinByFormat(valuesFoo , "")
	// nothing else is done with 'joinedFoo' variable before the return of that function, while I assume it should have been bound to 'r' with 'r.SetHeaderParam(...)'

```

## Steps to reproduce
For convenience I've made a reproducer available at this repository:
https://github.com/xaxa06/goswagger-2471 (follow instructions in README.md there).

Otherwise, call go swagger generator with a YAML similar to above example and try to include the generated code in a main go function -> go compiler will complain about the declared but not used variable.
```sh
> swagger generate client --target pkg/example --name example --spec example.yaml
> go build
# ...
pkg/example/client/operations/example_post_parameters.go:129:2: joinedFoo declared but not used
```

## Environment
swagger version: 0.25.0
go version: 1.15.6
OS:  Linux (Debian 10)


Pull request:
generate client: added support for array parameter in header
* fixed #2471
* reindented client parameter template for lisibility

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>

Patch:
diff --git a/fixtures/bugs/2471/.gitignore b/fixtures/bugs/2471/.gitignore
new file mode 100644
index 00000000..1e16265b
--- /dev/null
+++ b/fixtures/bugs/2471/.gitignore
@@ -0,0 +1,3 @@
+gen-*
+!gen-fixtures.sh
+*.log
diff --git a/fixtures/bugs/2471/fixture-2471.yaml b/fixtures/bugs/2471/fixture-2471.yaml
new file mode 100644
index 00000000..27d0623f
--- /dev/null
+++ b/fixtures/bugs/2471/fixture-2471.yaml
@@ -0,0 +1,43 @@
+swagger: '2.0'
+basePath: /
+host: localhost
+info:
+  version: 0.1.0
+  title: Reproducer
+  description: |
+    Reproducer for https://github.com/go-swagger/go-swagger/issues/2471
+consumes:
+  - application/json
+produces:
+  - plain/text
+schemes:
+  - http
+paths:
+  /example/{FooPath}:
+    post:
+        summary: example
+        description: ''
+        operationId: examplePost
+        parameters:
+          - name: Foo
+            in: header
+            type: array
+            required: false
+            items:
+              type: string
+            description: 'a reproducer for this ticket'
+          - name: FooQuery
+            in: query
+            type: array
+            required: false
+            items:
+              type: string
+          - name: FooPath
+            in: path
+            type: array
+            required: true
+            items:
+              type: string
+        responses:
+          '201':
+            description: OK
diff --git a/fixtures/bugs/2471/gen-fixtures.sh b/fixtures/bugs/2471/gen-fixtures.sh
new file mode 100755
index 00000000..ded2ce03
--- /dev/null
+++ b/fixtures/bugs/2471/gen-fixtures.sh
@@ -0,0 +1,78 @@
+#! /bin/bash
+if [[ ${1} == "--clean" ]] ; then
+    clean=1
+fi
+continueOnError=
+# A small utility to build fixture servers
+testcases="${testcases} fixture-2471.yaml"
+export SWAGGER_DEBUG=1
+for opts in  "" "--with-flatten=full" "--with-expand" ; do
+for testcase in ${testcases} ; do
+    grep -q discriminator ${testcase}
+    discriminated=$?
+    if [[ ${discriminated} -eq 0 && ${opts} == "--with-expand" ]] ; then
+        echo "Skipped ${testcase} with ${opts}: discriminator not supported with ${opts}"
+        continue
+    fi
+    spec=${testcase}
+    testcase=`basename ${testcase}`
+    if [[ -z ${opts} ]]; then
+        target=./gen-${testcase%.*}-minimal
+    elif [[ ${opts} == "--with-flatten=full" ]] ; then
+        target=./gen-${testcase%.*}-flatten
+    else
+        target=./gen-${testcase%.*}-expand
+    fi
+    serverName="codegensrv"
+    rm -rf ${target}
+    mkdir ${target}
+    echo "Server generation for ${spec} with opts=${opts}"
+    serverName="nrcodegen"
+    swagger generate server --skip-validation ${opts} --spec ${spec} --target ${target} --name=${serverName} 1>${testcase%.*}.log 2>&1
+    #
+    if [[ $? != 0 ]] ; then
+        echo "Generation failed for ${spec}"
+        if [[ ! -z ${continueOnError} ]] ; then
+            failures="${failures} codegen:${spec}"
+            continue
+        else
+            exit 1
+        fi
+    fi
+    echo "${spec}: Generation OK"
+    if [[ ! -d ${target}/models ]] ; then
+        echo "No model in this spec! Continue building server"
+    fi
+    if [[ -d ${target}/cmd/${serverName}"-server" ]] ; then
+        (cd ${target}/cmd/${serverName}"-server"; go build)
+        #(cd ${target}/models; go build)
+        if [[ $? != 0 ]] ; then
+            echo "Build failed for ${spec}"
+            if [[ ! -z ${continueOnError} ]] ; then
+                failures="${failures} build:${spec}"
+                continue
+            else
+                exit 1
+            fi
+        fi
+        echo "${spec}: Build OK"
+        if [[ -n ${clean} ]] ; then
+             rm -rf ${target}
+        fi
+    fi
+
+    swagger generate client --skip-validation ${opts} --spec ${spec} --target ${target} --name=${serverName} 1>${testcase%.*}.log 2>&1
+    (cd ${target}/client; go build)
+    if [[ $? != 0 ]] ; then
+      echo "Client build failed for ${spec}"
+      exit 1
+    fi
+    echo "${spec}: Client build OK"
+done
+done
+if [[ ! -z ${failures} ]] ; then
+    echo ${failures}|tr ' ' '\n'
+else
+    echo "No failures"
+fi
+exit
diff --git a/generator/bindata.go b/generator/bindata.go
index 959496cd..0d372901 100644
--- a/generator/bindata.go
+++ b/generator/bindata.go
@@ -2,7 +2,7 @@
 // sources:
 // templates/client/client.gotmpl (5.125kB)
 // templates/client/facade.gotmpl (3.83kB)
-// templates/client/parameter.gotmpl (12.261kB)
+// templates/client/parameter.gotmpl (12.977kB)
 // templates/client/response.gotmpl (6.363kB)
 // templates/contrib/stratoscale/client/client.gotmpl (3.591kB)
 // templates/contrib/stratoscale/client/facade.gotmpl (2.078kB)
@@ -151,7 +151,7 @@ func templatesClientFacadeGotmpl() (*asset, error) {
 	return a, nil
 }
 
-var _templatesClientParameterGotmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x5a\x5f\x73\xdb\xb8\x11\x7f\xe7\xa7\xd8\xaa\xe9\x55\xf4\x38\xd4\x3d\xfb\x46\x9d\xc9\xd9\xb9\xc6\x9d\x69\x2e\x4d\x3c\xd7\x87\x4c\xa6\x03\x93\x2b\x09\x77\x24\x40\x03\xa0\x14\x95\xc3\xef\xde\xc1\x1f\x92\x20\x45\x4a\x54\x12\xc7\x77\xd3\x3c\x59\x04\x81\xc5\xee\x6f\x7f\xfb\x07\xa0\x17\x0b\xb8\xe6\x09\xc2\x1a\x19\x0a\xa2\x30\x81\xfb\x3d\xac\xf9\x73\xb9\x23\xeb\x35\x8a\x1f\xe0\xe6\x67\x78\xfd\xf3\x1d\xbc\xbc\xb9\xbd\x8b\x82\x20\x28\x4b\xa0\x2b\x88\xae\x79\xbe\x17\x74\xbd\x51\xf0\xbc\xaa\x16\x0b\x28\x4b\x88\x79\x96\x21\x53\xbd\x77\x65\x09\xc8\x12\xa8\xaa\x20\x08\x72\x12\xff\x46\xd6\xa8\x27\x47\x6f\xdc\x6f\xfd\x62\xb1\x80\xbb\x0d\x95\xb0\xa2\x29\xc2\x8e\xc8\xae\x32\x6a\x83\xe0\xb4\x01\xc5\x79\x1a\xe9\xf9\x2f\x13\xaa\x28\x5b\x83\x6a\xd6\x65\x66\xc7\x5c\xf0\x2d\xc2\xaa\x50\x46\xd4\x06\x19\xec\x79\x01\x02\x9f\x8b\x82\x75\x24\xd5\x5b\x18\xb5\x09\x4b\x82\x80\x66\x39\x17\x0a\xe6\x01\xc0\x2c\xe6\x4c\xe1\x47\x35\xd3\xbf\x19\xaa\xc5\x46\xa9\xdc\x3c\x28\x9a\xe1\x2c\xd0\xbf\xd6\x54\x6d\x8a\xfb\x28\xe6\xd9\x62\xcd\x9f\xf3\x1c\x19\xc9\xe9\x02\x85\xe0\x42\xce\xc6\x27\x88\x82\x59\x19\x00\xb1\x38\x31\x69\x11\xa7\x14\x99\x3a\x22\x4d\x2a\xb1\xca\x8e\x4e\xd8\x91\xf5\x91\xd7\x5b\x92\xd2\x84\x28\x6b\x92\x76\xad\xc1\x40\x42\x74\x83\x2b\x52\xa4\xea\xd6\x3d\x57\x55\xef\xbd\xf7\x22\x34\x0e\x7c\x8d\xbb\xb2\x84\x9c\xc8\x98\xa4\xf4\xbf\x08\xd1\x6b\x92\x69\xef\xbe\x21\x82\x64\x12\x62\x81\x44\xa1\x04\x02\x0c\x77\x70\x6c\x26\xbf\xff\x15\x63\xa5\x45\xee\xa8\xda\x18\x9f\x25\x56\x19\xd8\x92\xb4\x40\x09\x94\x51\x45\xcd\xda\x24\x0a\x56\x05\x8b\x4f\x6c\x3e\x0f\xe1\xe2\xd8\x8e\xa5\xb3\x6d\xa5\x59\x69\x46\xaa\x6a\x4b\x84\x61\x42\x59\x82\x20\x6c\x8d\xde\x2b\x37\xf5\x15\x91\x0e\xa4\x66\x8c\x71\x05\xd1\xad\xfc\x89\xa6\x68\x66\xdb\x17\x5b\x22\x98\xde\x2f\xba\xbd\xa9\xaa\x7a\xc9\xb2\xde\xf1\x56\xbe\x11\x34\xa3\x8a\x6e\x51\xcf\x8e\xfe\xce\xef\xf6\x39\x56\xd5\xdc\x06\x8e\x91\x90\x0b\xca\xd4\x0a\x66\x7f\xf9\xf3\x76\xd6\xb8\xa6\xd5\xc4\x13\x01\x55\x15\xb6\x11\x67\xd4\xb7\xbf\xbd\x1f\x46\x6a\x00\xd0\x99\x28\x50\x15\x82\xc1\x77\x87\x38\xd5\x30\x95\x67\xa1\x71\x20\xe4\xca\x19\x4c\x58\x02\x73\x07\xd4\x0b\x21\xc8\x3e\x6c\x1e\xff\x49\xf2\xfa\x41\x8b\xa3\x32\xd6\x66\x31\xa2\xb8\x08\x61\xce\x85\x9e\xf3\xba\x48\x53\x72\x9f\x22\x40\x08\x55\xf5\x9d\x6f\x9f\x87\x33\x34\x40\x5f\x0e\x82\x10\x00\x98\xe1\x98\x64\x68\x95\xbc\xa3\x19\xf2\x42\x39\x62\x5c\x41\x2c\x6a\x9c\xdd\x1b\x2d\xa8\x0a\xaa\x09\x5c\xff\x37\x55\x1b\xb7\xe8\xb1\x68\x7f\x69\x60\xd4\x73\xc8\x3d\x4d\xa9\xda\x83\xe2\x20\x51\x01\x01\xe5\x76\xe6\x0c\x08\x08\x7c\x28\x50\xaa\x29\x41\xe2\x69\x3d\xaf\x65\xe8\xbf\xd1\x4d\x21\x88\xa2\x9c\x7d\x0b\xa2\xa7\x0c\x22\x6d\xf6\x1f\x2c\x84\xd4\xa7\x04\xce\xb5\x2d\xbc\x4f\x10\x38\xae\xe4\xc3\x8a\x8b\xf3\x23\xc7\xa9\x3d\x8f\xd5\xc7\x5a\x50\xe4\xc6\x9e\x36\x6e\x5a\xf7\x58\x1a\xfe\x1f\x86\xce\xd7\xaa\x3f\x5d\xa8\x27\xc5\x8f\xa3\xc8\x15\xc4\xea\xe3\x79\x71\xf2\xea\xee\xee\xcd\xb5\xe9\x0e\x9f\x22\x54\x0a\xa9\x78\x06\x9e\x0e\x9f\x14\x34\xed\xfa\xb9\x6d\x74\xe1\x42\xf7\xd9\x91\x1d\xfb\x16\x37\xdf\xe2\x66\x00\x87\x96\x34\x57\x60\x59\xd3\x06\xce\x51\xc2\xe8\xb4\x4c\x28\x93\x40\xd2\xd4\xd0\x3a\xd7\xe3\xa8\x50\x48\xcb\x6c\xcd\x76\x6e\xde\xbc\x78\x73\xab\x77\xcb\x39\x65\x2a\xd0\xd4\xd6\x83\x65\x09\x9b\x22\x23\xcc\x17\x0d\x3c\x47\xdb\x1d\x81\xda\xe7\x34\x26\x69\x6a\xce\xab\x12\x81\x08\x84\x9d\xa0\x4a\x21\xd3\x62\x09\x18\x6a\xbf\x75\x11\x72\xb1\x08\xd4\x3e\xc7\xa3\xd1\x2a\x95\x28\x62\x05\x65\x30\xec\xc0\x11\x6b\xcb\x52\xbb\xf5\x06\xb5\x13\x72\xa3\x59\x4d\xa8\xfb\x94\xc7\xbf\x35\x87\xf4\xde\x0c\x1f\xeb\x8b\x85\x7d\xea\xb4\x1f\xda\xda\xcf\x64\x82\x9b\x74\xcb\x14\x8a\x15\x89\xb1\x1d\x7a\xa7\x04\x92\x6c\x84\x2c\x17\x3e\x09\x46\x03\xd6\x05\xa0\xa3\x4a\x2a\xf5\x2f\x77\x8c\x36\xd0\x24\x6f\x91\x24\xd7\x29\x97\x28\xda\x50\xf2\x2e\x27\x8e\x36\x33\xdd\x4e\x38\x68\x12\x77\xbf\xd6\x07\xe0\x27\x45\x3f\x9b\xb9\xc4\xae\xd3\x5e\x17\xd9\xde\x46\x24\x49\xa4\xa1\x5b\xd3\x83\xf3\x71\xf6\x19\x06\x4b\x9b\x6e\x75\xde\x89\xde\x62\x8c\x74\x8b\xa2\x9e\x70\x2c\x20\xc2\x93\xca\x7c\xce\x39\xa0\xaf\x4a\xf4\x0e\xd5\x94\xbd\xc2\x36\xa7\x0d\x48\x71\x28\x9e\x90\xf5\x55\x41\x9c\x68\x57\x1f\xc3\x31\x98\x8e\x91\x70\x59\xdb\xe3\x91\xa9\x26\x62\x63\x72\xdd\xc6\x3e\x32\x6f\x3e\xbb\xe1\x1d\x22\x88\x27\x74\x2a\x0f\x9e\xc2\xfe\xae\xa6\x87\xe6\x8f\x59\x58\xeb\xba\xd4\xed\x9e\xe7\x43\x2f\x65\x34\x66\x78\x63\x8f\xec\xc9\x2f\xd1\x85\x0d\x39\xf3\x40\xee\x54\x97\x3e\x1d\x1c\x43\x5a\xf7\xd0\x18\x33\xd8\x53\x70\xe9\xfa\x12\x6d\xd1\x40\xdd\x1e\x2e\x03\xb6\xc0\x36\xf6\xfa\x67\x71\xb3\x85\x29\x42\x87\x96\x3f\x1b\x35\xfd\xd9\x09\xdb\x9f\x9d\xae\x06\x46\xa7\xf9\xa0\x2a\x5f\xa6\x13\xf8\xda\x65\xdf\xc9\xeb\x73\xfa\xd9\x30\xa9\x0f\x10\x3c\xac\x61\xe3\x08\x7d\x5a\x1d\x3b\x64\x41\xaf\x39\x7e\x7c\x1a\x9c\x61\xe3\x1f\x9d\x05\xa3\x7e\x1e\x72\xca\x72\x30\x26\x5d\x8c\xbb\x26\x52\x47\xb6\xa0\x0a\xef\xb8\xeb\xf3\xcd\x09\x00\xa5\x3b\x12\x58\xdf\xd8\xd3\x40\xfd\x19\xaa\x73\x64\xfe\x94\x0c\xde\xd9\x6f\x2e\xa0\x36\xdb\x26\x23\x37\x7e\x09\x02\xd7\x60\x3f\x16\x45\x6f\x71\x4d\xa5\x12\xfb\x10\xcc\xc7\x2a\x7b\xc0\xa0\x2b\xfd\x04\x57\x4b\x10\x9a\xe6\xf5\x4d\xf0\x99\x2d\x4a\xf8\x83\x91\xf2\xa7\x25\x30\x9a\x1a\x7c\x9b\x28\x40\x21\xcc\x39\x0d\x34\x88\x20\x50\xc2\xfb\x0f\x66\x7f\xe3\x84\x4e\x92\xac\xdb\x71\xe7\x6e\xc7\x0b\x43\x2d\x47\x2a\xfd\xe7\x47\x9e\xec\xcd\xfc\xb0\xfd\x3a\x65\xc9\xe8\x93\xc8\x92\xec\x45\x9a\xf2\xdd\xcb\x2c\x57\xfb\x5f\x48\x5a\xa0\x5e\x41\x57\x26\x30\xcd\xf3\xcb\x8f\xb9\x40\x29\xed\x51\xa8\xd1\x1e\xea\x93\x7c\x7b\xd3\x70\x2b\xff\x55\xa0\xd8\xd7\xcc\x0b\x00\x16\x0b\x78\xd0\x43\xd6\xb9\x46\x64\x1d\xe3\xde\xaa\x46\x1d\x7b\x47\xf1\x20\x06\x7d\x0a\x1d\x26\x5b\xa7\x9c\xd0\xd1\x20\x3c\x26\x6e\x69\xb8\x33\xb0\x5c\x3b\xa2\x0d\x94\xb1\xe5\x57\xcb\x91\xdd\x3d\x5c\x1e\x86\xae\x0c\xdc\x4a\x6d\xfa\x4f\x5c\x64\x44\x29\x14\x2e\x4e\xfd\xe7\xf9\xc8\xc6\xe1\x49\xd5\x1a\x5c\xaf\xcd\x45\x94\x2f\x34\x7a\xa7\x04\x65\xeb\x79\xe8\x0e\x79\xcd\x9f\x26\x79\xf4\xb8\xd0\x20\x3d\x60\x8a\x43\x7a\x36\x6b\xc8\xd0\xcc\xf6\x83\xa5\xe5\xc4\xdc\xbf\xf4\x79\x98\x35\x52\x2e\x47\xa4\x4f\x8a\x97\xa3\xba\x57\xfd\x5b\x23\x0d\x9c\xbb\x5c\x22\x6a\xd3\x65\x6a\x4e\xd4\x66\x90\xa8\x3d\x83\x9a\x95\xe3\xf6\x4c\xf1\xef\x10\xfd\x2f\x5a\x87\x0c\x30\xcb\x73\xfd\x61\x6d\xe9\x39\x3b\x3c\x4b\xf2\xf9\x94\x99\xea\x1b\x0f\xf1\x57\x48\x12\x14\x5d\xcc\x37\x66\x6c\x0a\xea\xde\xea\x6f\xb8\x9f\x85\xbb\x96\xea\xa1\xde\xec\xe9\x77\x09\x43\xe9\x78\x7a\x92\x6d\xaf\x8c\x8c\x53\x57\x5c\x64\xf6\xbf\x4e\x86\xfc\x7a\xe0\xd9\x46\x8f\xa3\x7e\x1d\xf2\xcb\x00\x16\x3d\x34\xfc\x1c\xd1\x37\xad\x7b\xc5\xd5\xa2\x56\x73\xd3\x98\x71\x4e\xe1\x5a\x7d\xd9\xc2\x35\x26\x6e\x62\xe1\x1a\x5b\x3e\xa5\x70\xad\x3e\xa7\x70\x8d\x6c\x1c\x9e\x54\xed\x51\x0a\xd7\x80\x29\x13\x0b\x57\x13\x37\xe3\xbc\x1c\x16\xfe\x08\x75\x6b\xe4\xf7\x39\x2d\x5d\xe5\x5f\xec\x7a\xe9\xc1\x76\x8e\x55\x4f\x27\xaf\x83\x6c\x3d\x73\xbd\xa1\x69\x7b\xd8\xd0\x8d\xa7\x19\xf1\xdc\xef\x06\x86\x5c\xa8\x23\xc4\x7e\x47\x1b\xf6\xc8\xfb\x0f\xd2\xf8\x58\xd3\x8f\x0b\xf8\xcf\x25\x6c\x8d\x2b\x4c\xef\x7b\xce\x59\xca\x3b\x33\x79\xc0\x84\x27\x93\xb1\xf3\xd4\x31\x1d\x97\x40\xf2\x1c\x59\x32\x3f\x32\xc9\x66\xab\x3e\x30\x5d\x0c\x0f\x2a\x92\x75\xea\xb6\x33\xe7\x44\x1c\x74\x0e\x7e\x03\x62\xdb\x29\x61\xaf\x2c\x68\x5f\x8c\xdb\xd8\x44\xf9\x11\xb4\x1b\x80\x3b\xe8\x9f\x85\xf6\x70\xe6\xfd\x9d\x29\xf6\x2b\xa7\x0c\x93\xb1\x64\xa8\x4f\xa9\xd1\x3f\x38\x65\x3f\xee\x2d\xf0\xc7\x69\x31\x2b\xcb\xe8\x9a\xa7\x29\xc6\x8a\x72\x66\x57\x54\xd5\x2c\x1c\x3d\x40\x35\xa7\x27\x62\x42\x74\x42\x93\x34\xa5\xd7\x1e\xb3\x49\xb3\x2b\x8a\xce\xed\x2f\x5c\xfa\xf1\x7b\x8c\xba\x74\x4e\xd6\x7a\x42\xa2\x7d\x14\xa5\xfd\x23\x40\xdd\xff\x8f\x2b\x6d\x6f\xa4\xda\x35\x09\x47\x69\x72\xa5\x2c\x72\xf3\xaf\xb1\x5b\x22\x28\x49\x04\x8d\x81\x88\x75\x91\x21\x53\xf2\x12\x24\x65\x31\xc2\x0e\xa1\x90\x98\x80\x4f\x16\x2b\x72\x87\x10\x13\xe6\xbe\xaf\x6e\x10\x56\x54\x48\x05\x54\x61\x06\xd4\xfe\x4b\xae\xd5\x88\x48\xa0\xea\xaf\xed\xe7\x59\x3d\x43\x02\x5f\xd9\x6f\xb5\x02\xb7\x94\x17\xd2\x8a\xb4\x0b\x2c\x62\xa0\xf8\x1a\xd5\x06\x85\x45\x3d\x45\x36\x3f\x02\x65\x08\x7f\x83\xef\xeb\x46\xea\xfc\x53\xcf\x11\xc9\xef\xbf\xff\x30\xb9\x5b\x1b\xfe\xc2\x1f\x1c\x7e\x90\xb4\x21\xd3\xd4\x29\xaf\x84\xe9\xd2\xf4\x2e\xde\x60\x46\xfc\x2f\xaa\xde\x98\xcd\x13\x30\x37\x4c\x68\x46\xdd\x25\x8a\xc9\xa5\x61\xff\xa5\xb9\x58\x19\x7e\xd5\x2b\xbe\x07\x97\x79\x3a\xe9\x4c\xe8\xfa\x3a\x7d\x74\x0f\xfe\xc6\xca\xf9\x17\xe9\x85\x7f\x8f\x00\x55\xd0\xe9\x50\xcc\xaf\xce\xe1\xc2\x11\x58\xa0\xf4\x89\xda\xda\xc8\x85\x8c\xae\x79\x96\x73\x49\x15\xfe\x62\xff\x77\x9b\x72\xf6\x52\xbf\xd1\xab\x74\xa6\x70\xfc\x72\x8b\x18\x4d\x83\x2a\xf8\x5f\x00\x00\x00\xff\xff\x42\x0a\x05\x41\xe5\x2f\x00\x00")
+var _templatesClientParameterGotmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x5b\x5b\x6f\xdb\xc8\x15\x7e\xe7\xaf\x38\x55\xd3\xad\x64\x38\xd4\x3e\x7b\xa1\x02\x59\x3b\xdb\xb8\x40\xb3\x6e\x62\x6c\x1f\x82\xa0\x18\x93\x47\xd2\xec\x92\x33\xf4\xcc\x50\x8a\x2a\xf0\xbf\x17\x73\x21\x39\xa4\x48\x8a\xf2\x25\xde\x45\xf3\x64\x72\x2e\x67\xce\xe5\x3b\xb7\xa1\x3c\x9f\xc3\x25\x8f\x11\x56\xc8\x50\x10\x85\x31\xdc\xed\x60\xc5\x5f\xcb\x2d\x59\xad\x50\xfc\x00\x57\x3f\xc3\xfb\x9f\x6f\xe1\xed\xd5\xf5\x6d\x18\x04\xc1\x7e\x0f\x74\x09\xe1\x25\xcf\x76\x82\xae\xd6\x0a\x5e\x17\xc5\x7c\x0e\xfb\x3d\x44\x3c\x4d\x91\xa9\xd6\xdc\x7e\x0f\xc8\x62\x28\x8a\x20\x08\x32\x12\xfd\x46\x56\xa8\x17\x87\x37\xee\x59\x4f\xcc\xe7\x70\xbb\xa6\x12\x96\x34\x41\xd8\x12\xd9\x64\x46\xad\x11\x1c\x37\xa0\x38\x4f\x42\xbd\xfe\x6d\x4c\x15\x65\x2b\x50\xd5\xbe\xd4\x9c\x98\x09\xbe\x41\x58\xe6\xca\x90\x5a\x23\x83\x1d\xcf\x41\xe0\x6b\x91\xb3\x06\xa5\xf2\x08\xc3\x36\x61\x71\x10\xd0\x34\xe3\x42\xc1\x34\x00\x98\x44\x9c\x29\xfc\xa2\x26\xfa\x99\xa1\x9a\xaf\x95\xca\xcc\x8b\xa2\x29\x4e\x02\xfd\xb4\xa2\x6a\x9d\xdf\x85\x11\x4f\xe7\x2b\xfe\x9a\x67\xc8\x48\x46\xe7\x28\x04\x17\x72\xd2\xbf\x40\xe4\xcc\xd2\x00\x88\xc4\x91\x45\xf3\x28\xa1\xc8\xd4\x00\x35\xa9\xc4\x32\x1d\x5c\xb0\x25\xab\x81\xe9\x0d\x49\x68\x4c\x94\x15\x49\x9b\xd6\xe8\x40\x42\x78\x85\x4b\x92\x27\xea\xda\xbd\x17\x45\x6b\xde\x9b\x98\x19\x03\xbe\xc7\xed\x7e\x0f\x19\x91\x11\x49\xe8\x7f\x11\xc2\xf7\x24\xd5\xd6\xbd\x21\x82\xa4\x12\x22\x81\x44\xa1\x04\x02\x0c\xb7\x30\xb4\x92\xdf\xfd\x8a\x91\xd2\x24\xb7\x54\xad\x8d\xcd\x62\xcb\x0c\x6c\x48\x92\xa3\x04\xca\xa8\xa2\x66\x6f\x1c\x06\xcb\x9c\x45\x47\x0e\x9f\xce\xe0\x6c\xe8\xc4\xbd\x93\x6d\xa9\x51\x69\x46\x8a\x62\x43\x84\x41\xc2\x7e\x0f\x82\xb0\x15\x7a\x53\x6e\xe9\x3b\x22\x9d\x92\xaa\x31\xc6\x15\x84\xd7\xf2\x27\x9a\xa0\x59\x6d\x27\x36\x44\x30\x7d\x5e\x78\x7d\x55\x14\xe5\x96\x45\x79\xe2\xb5\xbc\x11\x34\xa5\x8a\x6e\x50\xaf\x0e\xff\xce\x6f\x77\x19\x16\xc5\xd4\x3a\x8e\xa1\x90\x09\xca\xd4\x12\x26\x7f\xf9\xf3\x66\x52\x99\xa6\xe6\xc4\x23\x01\x45\x31\xab\x3d\xce\xb0\x6f\x9f\xbd\x07\x43\x35\x00\x68\x2c\x14\xa8\x72\xc1\xe0\xbb\x43\x3d\x95\x6a\xda\x9f\xa4\x8d\x03\x22\x17\x4e\x60\xc2\x62\x98\x3a\x45\xbd\x11\x82\xec\x66\xd5\xeb\x3f\x49\x56\xbe\x68\x72\x54\x46\x5a\x2c\x46\x14\x17\x33\x98\x72\xa1\xd7\xbc\xcf\x93\x84\xdc\x25\x08\x30\x83\xa2\xf8\xce\x97\xcf\xd3\x33\x54\x8a\x3e\xef\x54\x42\x00\x60\x86\x23\x92\xa2\x65\xf2\x96\xa6\xc8\x73\xe5\x80\x71\x01\x91\x28\xf5\xec\x66\x34\xa1\x22\x28\x46\x60\xfd\xdf\x54\xad\xdd\xa6\xe7\x82\xfd\xb9\x51\xa3\x5e\x43\xee\x68\x42\xd5\x0e\x14\x07\x89\x0a\x08\x28\x77\x32\x67\x40\x40\xe0\x7d\x8e\x52\x8d\x71\x12\x8f\xeb\x69\x49\x43\xff\x0d\xaf\x72\x41\x14\xe5\xec\x9b\x13\xbd\xa4\x13\x69\xb1\xff\x60\x2e\xa4\x1e\xe2\x38\x97\x36\xf1\xbe\x80\xe3\xb8\x94\x0f\x4b\x2e\x4e\xf7\x1c\xc7\xf6\x34\x52\x5f\x4a\x42\xa1\x1b\x7b\x59\xbf\xa9\xcd\x63\x61\xf8\x7f\xe8\x3a\x5f\x2b\xff\x34\x55\x3d\xca\x7f\x1c\x44\x2e\x20\x52\x5f\x4e\xf3\x93\x77\xb7\xb7\x37\x97\xa6\x3a\x7c\x09\x57\xc9\xa5\xe2\x29\x78\x3c\x3c\xc8\x69\xea\xfd\x53\x5b\xe8\xc2\x99\xae\xb3\x43\x3b\xf6\xcd\x6f\xbe\xf9\x4d\x87\x1e\x6a\xd0\x5c\x80\x45\x4d\xed\x38\x83\x80\xd1\x61\x99\x50\x26\x81\x24\x89\x81\x75\xa6\xc7\x51\xa1\x90\x16\xd9\x1a\xed\xdc\xcc\xbc\xb9\xb9\xd6\xa7\x65\x9c\x32\x15\x68\x68\xeb\xc1\xfd\x1e\xd6\x79\x4a\x98\x4f\x1a\x78\x86\xb6\x3a\x02\xb5\xcb\x68\x44\x92\xc4\xf4\xab\x12\x81\x08\x84\xad\xa0\x4a\x21\xd3\x64\x09\x18\x68\x7f\x70\x1e\x72\x36\x0f\xd4\x2e\xc3\x41\x6f\x95\x4a\xe4\x91\x82\x7d\xd0\x6d\xc0\x1e\x69\xf7\x7b\x6d\xd6\x2b\xd4\x46\xc8\x0c\x67\x25\xa0\xee\x12\x1e\xfd\x56\x35\xe9\xad\x15\xbe\xae\xcf\xe6\xf6\xad\x51\x7e\x68\x69\x1f\x89\x04\xb7\xe8\x9a\x29\x14\x4b\x12\x61\x3d\xf4\x51\x09\x24\x69\x0f\x58\xce\x7c\x10\xf4\x3a\xac\x73\x40\x07\x95\x44\xea\x27\xd7\x46\x1b\xd5\xc4\x1f\x90\xc4\x97\x09\x97\x28\x6a\x57\xf2\x2e\x27\x06\x8b\x99\x66\x25\x1c\x54\x81\xbb\x9d\xeb\x03\xf0\x83\xa2\x1f\xcd\x5c\x60\xd7\x61\xaf\xa9\xd9\xd6\x41\x24\x8e\xa5\x81\x5b\x55\x83\xf3\x7e\xf4\x19\x04\x4b\x1b\x6e\x75\xdc\x09\x3f\x60\x84\x74\x83\xa2\x5c\x30\xe4\x10\xb3\xa3\xcc\x3c\xa6\x0f\x68\xb3\x12\x7e\x44\x35\xe6\xac\x59\x1d\xd3\x3a\xa8\x38\x2d\x1e\xa1\xf5\x55\x95\x38\x52\xae\xb6\x0e\xfb\xd4\x34\x04\xc2\x45\x29\x8f\x07\xa6\x12\x88\x95\xc8\x65\x19\xfb\xcc\xb8\x79\x74\xc1\xdb\x05\x10\x8f\xe8\x58\x1c\xbc\x84\xfc\x4d\x4e\x0f\xc5\xef\x93\xb0\xe4\x75\xa1\xcb\x3d\xcf\x86\x5e\xc8\xa8\xc4\xf0\xc6\x9e\xd9\x92\x4f\x51\x85\x75\x19\xf3\x80\xee\x58\x93\xbe\x9c\x3a\xba\xb8\x6e\x69\xa3\x4f\x60\x8f\xc1\x85\xab\x4b\xb4\x44\x1d\x79\xbb\x3b\x0d\xd8\x04\x5b\xc9\xeb\xf7\xe2\xe6\x08\x93\x84\x0e\x25\x7f\xd5\x2b\xfa\xab\x23\xb2\xbf\x3a\x9e\x0d\x0c\x4f\xd3\x4e\x56\x9e\xa6\x12\xf8\xda\x69\xdf\xd1\x6b\x63\xfa\x55\x37\xa8\x0f\x34\x78\x98\xc3\xfa\x35\xf4\xb0\x3c\x76\x88\x82\x56\x71\xfc\xfc\x30\x38\x41\xc6\x3f\x3a\x0a\x7a\xed\xdc\x65\x94\x45\xa7\x4f\x3a\x1f\x77\x45\xa4\xf6\x6c\x41\x15\xde\x72\x57\xe7\x9b\x0e\x00\xa5\x6b\x09\xac\x6d\x6c\x37\x50\x7e\x86\x6a\xb4\xcc\x0f\x89\xe0\x8d\xf3\xa6\x02\x4a\xb1\x6d\x30\x72\xe3\xe7\x20\x70\x05\xf6\x63\x51\xf8\x01\x57\x54\x2a\xb1\x9b\x81\xf9\x58\x65\x1b\x0c\xba\xd4\x6f\x70\xb1\x00\xa1\x61\x5e\xde\x04\x9f\x58\xa2\xcc\x7e\x30\x54\xfe\xb4\x00\x46\x13\xa3\xdf\xca\x0b\x50\x08\xd3\xa7\x81\x56\x22\x08\x94\xf0\xe9\xb3\x39\xbf\xbb\xbb\x71\xd7\x8b\xaf\x4b\x9b\x3b\x70\x18\x7c\x39\x64\xe9\x3f\x3f\xf2\x78\x67\xf6\xcc\xca\x3d\xd5\x2e\x0d\x4b\x1f\x4e\x16\x6e\x6f\x92\x84\x6f\xdf\xa6\x99\xda\xfd\x42\x92\x1c\xdd\x36\xba\x34\x5e\x6a\x86\xde\x7e\xc9\x04\x4a\x69\xfb\xa2\xa6\x28\x96\xb6\x6d\x1e\x9a\x87\x85\xd7\xf2\x5f\x39\x8a\x5d\x89\x49\x3d\x3d\x9f\xc3\xbd\x1e\xb3\x76\x37\x07\x94\xee\x0f\xd0\xde\x5d\xb1\x59\x94\x2a\xba\x17\x9d\x86\x87\x06\xdc\xc7\xf3\xde\x47\x6e\x61\x00\xd6\xb1\xdd\x59\xcb\x93\xdb\xfa\x55\xd0\x4f\xeb\x62\xd1\xc3\x4a\x93\x8e\x6b\xbe\xee\xbb\xae\x1b\x1c\x0d\xad\x94\x9f\xb8\x48\x89\x52\x28\x9c\x8f\xfb\xef\xd3\x1e\x16\x66\xb5\xff\xf7\xac\xa8\xee\x5e\x2e\xcd\x25\x96\x4f\x34\xfc\xa8\x04\x65\xab\xe9\xcc\x35\x88\x75\x9f\xd8\xb0\x56\x17\x8e\x2a\x53\x74\x08\xe5\x4c\x31\x99\x54\x28\xaa\xf4\x50\x6d\xf3\x7d\xaf\x06\xd2\xd4\xbf\x43\xba\x9f\x54\xe4\xce\x7b\x8e\x19\xe5\x7e\x23\x65\x39\xb0\x19\x34\x41\x6f\xb4\xec\x6e\xb1\x88\x5a\xb7\x80\x9f\x11\xb5\xee\xc4\x7d\x4b\xd6\x6a\x6b\xbf\xa8\x63\xd0\x50\x19\xd5\x73\xa3\xb3\xca\x8a\x5d\x88\xf4\x80\x72\x98\xc5\x5a\xd0\x98\x9d\x44\xf9\x74\x80\x8d\x30\x5b\xb7\xe2\xdf\x21\x89\x51\xb4\x54\xbf\x36\x83\x63\x94\xef\x6d\xff\xa6\xfe\x11\x5e\xd3\xd2\xbe\x26\x5d\xe9\xfe\x30\xa2\xfb\x25\x4a\x35\xdd\x1f\xf2\x47\xa7\xa0\x83\xf0\x61\xac\xbe\xe4\x22\xb5\xbf\x83\xe9\xce\x36\x2d\xd3\x57\xcc\x0d\x1a\xbe\xcb\x70\x1d\xca\x6a\xa9\xcb\x8f\x1d\x5d\xf2\xb6\xc2\xcb\x81\x34\xed\x7c\x13\xd4\x02\xf6\x67\xd2\xe1\x5c\xba\x7c\xda\x5c\xda\x47\x6e\x5c\x2e\x6d\x67\xd3\x3e\x6a\xc7\xb3\x69\x33\x9f\x2e\x1f\x93\x4f\x7b\x98\xf0\xfc\xb4\x67\xc5\x23\xf2\xe9\xb8\x8c\xda\x21\x56\x57\x46\x1d\xce\xa9\x95\xaf\xf6\xe3\xbd\xfb\x9c\x13\x52\xea\x49\x49\xb5\x1f\xf5\xfe\x50\xe7\xc0\x89\xb5\x6d\x0f\xad\x56\x30\xb3\x85\xf5\x41\x5d\xeb\x22\x72\x55\x66\x7b\x2b\x6a\x8f\xbb\x5c\xd3\x24\xee\x74\x46\x5d\xb4\x9b\x59\x0f\x6c\x6e\xa0\x0b\x30\x81\x73\x57\xfb\x31\xb2\xdb\xee\x9f\x3e\x4b\x83\x2a\x0d\x78\x2e\xe0\x3f\xe7\xb0\x31\x56\x36\xfd\xc3\x29\x0d\xa9\xd7\x78\x7a\xaa\x9c\x1d\x4d\x30\x0e\x04\x43\x3c\x2e\x80\x64\x19\xb2\x78\x3a\xb0\xc8\x06\xd8\xb6\x72\x2a\x7f\x3a\x9c\x98\x56\x7d\xe6\xa6\xb1\xe6\x88\xe7\x35\xba\xe7\x0e\xb2\xf5\x92\xd9\x60\x94\x1a\x92\xb7\x8a\x31\x03\x9a\xaf\x94\xdd\xb0\xc4\x49\x9a\x1f\x9f\x32\x7e\x5f\xec\x36\x98\xfd\x95\x53\x86\x71\x5f\xa8\x96\x5b\xb2\x0a\xff\xc1\x29\xfb\x71\x67\x8d\x34\x0c\xa1\xc9\x7e\x1f\x5e\xf2\x24\xc1\x48\x51\xce\xec\x8e\xa2\x98\xcc\x0e\x7d\x74\xa8\x3f\x25\xc6\xf7\x47\x14\x8c\x63\x3a\x93\x3e\xf9\x34\x2a\xc3\x70\x7c\xa9\xdb\x8c\x50\x2e\xe0\x35\x4a\x2e\xaf\x2e\x18\x2d\xc1\x88\x3c\xf0\xac\x02\xf4\xb5\x4a\xfd\x02\xd8\x6b\xc2\x7a\x5f\xcc\x51\x9a\xb0\x2c\xf3\xcc\xfc\x5e\x79\x43\x04\x25\x31\x8d\x80\x88\x55\x9e\x22\x53\xf2\x1c\x24\x65\x11\xc2\x16\x21\x97\x18\x83\x8f\x27\x4b\x71\x8b\x10\x11\xe6\xbe\x79\xaf\x11\x96\x54\x48\x05\x54\x61\x0a\xd4\xfe\x4c\xda\x32\x44\x24\x50\xf5\xd7\xfa\x93\xb9\x5e\x21\x81\x2f\xed\xf7\x73\x81\x1b\xca\x73\x69\x49\xda\x0d\x56\x79\xa0\xf8\x0a\xd5\x1a\x85\x35\x40\x82\x6c\x3a\xa0\xd5\x19\xfc\x0d\xbe\x2f\x33\xf9\xe9\xfd\xe1\x00\xe5\x4f\xdf\x7f\x1e\x5d\xaf\xf6\xd8\xed\x48\x97\x35\x08\xbc\x47\xc8\x3d\xaa\x35\x7b\x32\xc9\xc7\xd6\x1f\xed\x9b\x80\x3a\xb8\x34\x0a\x84\x83\x12\xe0\x63\xb4\xc6\x94\xf8\x9f\xfe\xbd\x31\x1b\x69\x61\x6a\x3c\xa4\x1a\x75\x17\x7d\x26\x5f\xcd\xda\x93\xe6\xf2\xaf\x7b\xaa\x55\x12\x1d\xdc\x3a\x3f\xf0\xc2\xaf\xa7\x8d\xaa\xc4\x9e\x3e\x41\xb7\xf4\xbb\x56\xd8\x28\x44\xb4\x2b\x70\xed\x00\x02\xa5\x0f\xf4\x5a\x76\x2e\x64\x78\xc9\xd3\x8c\x4b\xaa\xf0\x17\xfb\x7f\x08\x94\xb3\xb7\x7a\x46\xef\xd2\xc1\xd6\x1d\xec\x36\x31\x9a\x04\x45\xf0\xbf\x00\x00\x00\xff\xff\xdd\xbc\x5c\xcd\xb1\x32\x00\x00")
 
 func templatesClientParameterGotmplBytes() ([]byte, error) {
 	return bindataRead(
@@ -166,8 +166,8 @@ func templatesClientParameterGotmpl() (*asset, error) {
 		return nil, err
 	}
 
-	info := bindataFileInfo{name: "templates/client/parameter.gotmpl", size: 12261, mode: os.FileMode(0644), modTime: time.Unix(1482416923, 0)}
-	a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x90, 0xd8, 0x41, 0xd2, 0x6, 0xe3, 0x24, 0x53, 0x68, 0xa4, 0xc6, 0xcc, 0x6d, 0xa3, 0x61, 0xd3, 0x49, 0x4e, 0xe2, 0x3d, 0xf3, 0x9b, 0x1e, 0x12, 0x19, 0xf, 0xd3, 0xd4, 0x4c, 0x37, 0x6f, 0x72}}
+	info := bindataFileInfo{name: "templates/client/parameter.gotmpl", size: 12977, mode: os.FileMode(0644), modTime: time.Unix(1482416923, 0)}
+	a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x2a, 0xb8, 0xaf, 0x1e, 0x8c, 0x32, 0x2b, 0x0, 0x7b, 0x54, 0x83, 0x6, 0x34, 0x78, 0x77, 0x89, 0xf6, 0xc0, 0x64, 0x30, 0x7f, 0xf6, 0x52, 0xea, 0xc5, 0xe0, 0x35, 0x8b, 0xdd, 0xb9, 0x63, 0x84}}
 	return a, nil
 }
 
diff --git a/generator/templates/client/parameter.gotmpl b/generator/templates/client/parameter.gotmpl
index 4ced460d..8e87f138 100644
--- a/generator/templates/client/parameter.gotmpl
+++ b/generator/templates/client/parameter.gotmpl
@@ -150,77 +150,122 @@ func ({{ .ReceiverName }} *{{ pascalize .Name }}Params) WriteToRequest(r runtime
     return err
   }
   var res []error
-  {{range .Params}}
+  {{ range .Params }}
+    {{- if not (or .IsArray .IsMap .IsBodyParam) }}
+      {{- if and .IsNullable (not .AllowEmptyValue) }}
+  if {{ .ValueExpression }} != nil {
+      {{- end}}
+
+      {{- if .IsQueryParam }}
 
-  {{if not (or .IsArray .IsMap .IsBodyParam) }}
-  {{ if and .IsNullable (not .AllowEmptyValue) }}if {{ .ValueExpression }} != nil { {{ end}}
-  {{ if .IsQueryParam }}
   // query param {{ .Name }}
-  {{ if .IsNullable }}var qr{{ pascalize .Name }} {{ .GoType }}
+        {{- if .IsNullable }}
+  var qr{{ pascalize .Name }} {{ .GoType }}
   if {{ .ValueExpression }} != nil {
     qr{{ pascalize .Name }} = *{{ .ValueExpression }}
-  }{{ else }}qr{{ pascalize .Name }} := {{ .ValueExpression }}{{ end}}
-  q{{ pascalize .Name}} := {{ if .Formatter }}{{ .Formatter }}(qr{{ pascalize .Name }}){{ else }}qr{{ pascalize .Name }}{{ if .IsCustomFormatter }}.String(){{end}}{{end}}{{ if not .AllowEmptyValue }}
-  if q{{ pascalize .Name }} != "" { {{ end }}
+  }
+        {{- else }}
+  qr{{ pascalize .Name }} := {{ .ValueExpression }}
+        {{- end}}
+  q{{ pascalize .Name}} := {{ if .Formatter }}{{ .Formatter }}(qr{{ pascalize .Name }}){{ else }}qr{{ pascalize .Name }}{{ if .IsCustomFormatter }}.String(){{end}}{{end}}
+        {{- if not .AllowEmptyValue }}
+  if q{{ pascalize .Name }} != "" {
+        {{- end }}
   if err := r.SetQueryParam({{ printf "%q" .Name }}, q{{ pascalize .Name }}); err != nil {
     return err
   }
-  {{ if not .AllowEmptyValue }}}{{ end }}
-  {{ else if .IsPathParam }}
+        {{- if not .AllowEmptyValue }}
+  }
+        {{- end }}
+
+      {{- else if .IsPathParam }}
+
   // path param {{ .Name }}
   if err := r.SetPathParam({{ printf "%q" .Name }}, {{ if .Formatter }}{{ .Formatter }}({{ if .IsNullable }}*{{end}}{{ .ValueExpression }}){{ else }}{{ if and (not .IsCustomFormatter) .IsNullable }}*{{end}}{{ .ValueExpression }}{{ if .IsCustomFormatter }}.String(){{end}}{{end}}); err != nil {
     return err
   }
-  {{ else if .IsHeaderParam }}
+
+      {{- else if .IsHeaderParam }}
+
   // header param {{ .Name }}
   if err := r.SetHeaderParam({{ printf "%q" .Name }}, {{ if .Formatter }}{{ .Formatter }}({{ if .IsNullable }}*{{end}}{{ .ValueExpression }}){{ else }}{{ if and (not .IsCustomFormatter) .IsNullable }}*{{end}}{{ .ValueExpression }}{{ if .IsCustomFormatter }}.String(){{end}}{{end}}); err != nil {
     return err
   }
-  {{ else if .IsFormParam }}
-  {{ if .IsFileParam }}
-  {{ if .IsNullable}}
+      {{- else if .IsFormParam }}
+        {{- if .IsFileParam }}
+          {{- if .IsNullable }}
   if {{ .ValueExpression }} != nil {
-  {{end}}
+          {{- end }}
     // form file param {{ .Name }}
     if err := r.SetFileParam({{ printf "%q" .Name }}, {{ .ValueExpression }}); err != nil {
       return err
     }
-  {{ if .IsNullable}}
+          {{- if .IsNullable}}
   }
-  {{ end }}
-  {{ else }}
+          {{- end }}
+        {{- else }}
+
   // form param {{ .Name }}
-  {{ if .IsNullable }}var fr{{ pascalize .Name }} {{ .GoType }}
+          {{- if .IsNullable }}
+  var fr{{ pascalize .Name }} {{ .GoType }}
   if {{ .ValueExpression }} != nil {
     fr{{ pascalize .Name }} = *{{ .ValueExpression }}
-  }{{ else }}fr{{ pascalize .Name }} := {{ .ValueExpression }}{{ end}}
-  f{{ pascalize .Name}} := {{ if .Formatter }}{{ .Formatter }}(fr{{ pascalize .Name }}){{ else }}fr{{ pascalize .Name }}{{ if .IsCustomFormatter }}.String(){{end}}{{end}}{{ if not .AllowEmptyValue }}
-  if f{{ pascalize .Name }} != "" { {{ end }}
+  }
+          {{- else }}
+  fr{{ pascalize .Name }} := {{ .ValueExpression }}
+          {{- end}}
+  f{{ pascalize .Name}} := {{ if .Formatter }}{{ .Formatter }}(fr{{ pascalize .Name }}){{ else }}fr{{ pascalize .Name }}{{ if .IsCustomFormatter }}.String(){{end}}{{end}}
+          {{- if not .AllowEmptyValue }}
+  if f{{ pascalize .Name }} != "" {
+          {{- end }}
   if err := r.SetFormParam({{ printf "%q" .Name }}, f{{ pascalize .Name }}); err != nil {
     return err
   }
-  {{ if not .AllowEmptyValue }}}{{ end }}
-  {{ end }}
-  {{ end }}
-  {{ if and .IsNullable (not .AllowEmptyValue) }}}{{end}}
-  {{else if .IsArray }}
-  {{ if not .IsBodyParam }}{{ if .Child }}{{ if or .Child.Formatter .Child.IsCustomFormatter }}var values{{ pascalize .Name }} []string
+          {{- if not .AllowEmptyValue }}
+  }
+          {{- end }}
+        {{- end }}
+      {{- end }}
+      {{- if and .IsNullable (not .AllowEmptyValue) }}
+  }
+      {{- end }}
+    {{- else if .IsArray }}
+
+      {{- if not .IsBodyParam }}
+
+        {{- if .Child }}
+          {{- if or .Child.Formatter .Child.IsCustomFormatter }}
+
+  var values{{ pascalize .Name }} []string
   for _, v := range {{ if and (not .IsArray) (not .IsMap) (not .IsStream) (.IsNullable) }}*{{end}}{{ .ValueExpression }} {
     values{{ pascalize .Name }} = append(values{{ pascalize .Name }}, {{ .Child.Formatter }}{{ if .Child.Formatter }}({{ end }}v{{ if .Child.IsCustomFormatter }}.String(){{ end }}{{ if .Child.Formatter }}){{ end }})
   }
-  {{ else }}values{{ pascalize .Name }} := {{ if and (not .IsArray) (not .IsStream) (not .IsMap) (.IsNullable) }}*{{end}}{{ .ValueExpression }}{{ end }}
-  {{ else }}values{{ pascalize .Name }} := {{ if and (not .IsArray) (not .IsStream) (not .IsMap) (.IsNullable) }}*{{end}}{{ .ValueExpression }}{{ end }}
+          {{- else }}
+  values{{ pascalize .Name }} := {{ if and (not .IsArray) (not .IsStream) (not .IsMap) (.IsNullable) }}*{{end}}{{ .ValueExpression }}
+          {{- end }}
+        {{- else }}
+  values{{ pascalize .Name }} := {{ if and (not .IsArray) (not .IsStream) (not .IsMap) (.IsNullable) }}*{{end}}{{ .ValueExpression }}
+        {{- end }}
   joined{{ pascalize .Name}} := swag.JoinByFormat(values{{ pascalize .Name }}, "{{.CollectionFormat}}")
-  {{ if .IsQueryParam }}// query array param {{ .Name }}
+
+        {{- if .IsQueryParam }}
+
+  // query array param {{ .Name }}
   if err := r.SetQueryParam({{ printf "%q" .Name }}, joined{{ pascalize .Name }}...); err != nil {
     return err
   }
-  {{ else if and .IsFormParam }}// form array param {{ .Name }}
+
+        {{- else if and .IsFormParam }}
+
+  // form array param {{ .Name }}
   if err := r.SetFormParam({{ printf "%q" .Name }}, joined{{ pascalize .Name }}...); err != nil {
     return err
   }
-  {{ else if and .IsPathParam }}// path array param {{ .Name }}
-  // SetPathParam does not support variadric arguments, since we used JoinByFormat
+
+        {{- else if and .IsPathParam }}
+
+  // path array param {{ .Name }}
+  // SetPathParam does not support variadic arguments, since we used JoinByFormat
   // we can send the first item in the array as it's all the items of the previous
   // array joined together
   if len(joined{{ pascalize .Name }}) > 0 {
@@ -228,19 +273,32 @@ func ({{ .ReceiverName }} *{{ pascalize .Name }}Params) WriteToRequest(r runtime
       return err
     }
   }
-  {{ end }}{{ end }}
 
-  {{ end }}
+        {{- else if .IsHeaderParam }}
+
+  // header array param {{ .Name }}
+  if len(joined{{ pascalize .Name }}) > 0 {
+     if err := r.SetHeaderParam({{ printf "%q" .Name }}, joined{{ pascalize .Name }}[0]); err != nil {
+      return err
+    }
+  }
+        {{- end }}
+      {{- end }}
+    {{- end }}
 
-  {{if .IsBodyParam}}
-  {{ if or .Schema.IsInterface .Schema.IsStream (and .Schema.IsArray .Child) (and .Schema.IsMap .Child) (and .Schema.IsNullable (not .HasDiscriminator)) }} if {{ .ValueExpression }} != nil { {{end}}
+    {{- if .IsBodyParam }}
+      {{- if or .Schema.IsInterface .Schema.IsStream (and .Schema.IsArray .Child) (and .Schema.IsMap .Child) (and .Schema.IsNullable (not .HasDiscriminator)) }}
+  if {{ .ValueExpression }} != nil {
+      {{- end }}
     if err := r.SetBodyParam({{ .ValueExpression }}); err != nil {
       return err
     }
-  {{ if or .Schema.IsInterface .Schema.IsStream (and .Schema.IsArray .Child) (and .Schema.IsMap .Child) (and .Schema.IsNullable (not .HasDiscriminator)) }} } {{end}}
-  {{end}}
+      {{- if or .Schema.IsInterface .Schema.IsStream (and .Schema.IsArray .Child) (and .Schema.IsMap .Child) (and .Schema.IsNullable (not .HasDiscriminator)) }}
+  }
+      {{- end }}
+    {{- end }}
 
-  {{end}}
+  {{- end }}
   if len(res) > 0 {
     return errors.CompositeValidationError(res...)
   }


Test patch:
diff --git a/generator/client_test.go b/generator/client_test.go
index a0327fa4..1e8d26c2 100644
--- a/generator/client_test.go
+++ b/generator/client_test.go
@@ -377,3 +377,51 @@ func TestGenClient_1518(t *testing.T) {
 		}
 	}
 }
+
+func TestGenClient_2471(t *testing.T) {
+	t.Parallel()
+	defer discardOutput()()
+
+	opts := testClientGenOpts()
+	opts.Spec = filepath.Join("..", "fixtures", "bugs", "2471", "fixture-2471.yaml")
+
+	cwd, _ := os.Getwd()
+	tft, _ := ioutil.TempDir(cwd, "generated")
+	opts.Target = tft
+
+	defer func() {
+		_ = os.RemoveAll(tft)
+	}()
+
+	err := GenerateClient("client", []string{}, []string{}, opts)
+	require.NoError(t, err)
+
+	fixtureConfig := map[string][]string{
+		"client/operations/example_post_parameters.go": { // generated file
+			`func (o *ExamplePostParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {`,
+			`	if err := r.SetTimeout(o.timeout); err != nil {`,
+			`	valuesFoo := o.Foo`,
+			`	joinedFoo := swag.JoinByFormat(valuesFoo, "")`,
+			`	if len(joinedFoo) > 0 {`,
+			`		if err := r.SetHeaderParam("Foo", joinedFoo[0]); err != nil {`,
+			`	valuesFooPath := o.FooPath`,
+			`	joinedFooPath := swag.JoinByFormat(valuesFooPath, "")`,
+			`	if len(joinedFooPath) > 0 {`,
+			`		if err := r.SetPathParam("FooPath", joinedFooPath[0]); err != nil {`,
+			`	valuesFooQuery := o.FooQuery`,
+			`	joinedFooQuery := swag.JoinByFormat(valuesFooQuery, "")`,
+			`	if err := r.SetQueryParam("FooQuery", joinedFooQuery...); err != nil {`,
+		},
+	}
+
+	for fileToInspect, expectedCode := range fixtureConfig {
+		code, err := ioutil.ReadFile(filepath.Join(opts.Target, filepath.FromSlash(fileToInspect)))
+		require.NoError(t, err)
+
+		for line, codeLine := range expectedCode {
+			if !assertInCode(t, strings.TrimSpace(codeLine), string(code)) {
+				t.Logf("Code expected did not match in codegenfile %s for expected line %d: %q", fileToInspect, line, expectedCode[line])
+			}
+		}
+	}
+}