Repository: go-openapi/runtime
Pull request #173 (2020-01-28 17:00:12)

Bugfix: Enforce Accept header validation
Validation of the `Accept` header was only being enforced when the
incoming request includes a body.

Removes the check for the request having a body enforces the `Accept`
header is valid.

Removes the default response format of `*/*` when no body is included
in the request.

Also includes basic lint fixes by using `gofmt`, `goimports`.

resolves: #172


Patch:
diff --git a/client/auth_info.go b/client/auth_info.go
index 9e18222..bbe1479 100644
--- a/client/auth_info.go
+++ b/client/auth_info.go
@@ -17,8 +17,9 @@ package client
 import (
 	"encoding/base64"
 
-	"github.com/go-openapi/runtime"
 	"github.com/go-openapi/strfmt"
+
+	"github.com/go-openapi/runtime"
 )
 
 // PassThroughAuth never manipulates the request
diff --git a/client/request.go b/client/request.go
index 9138edc..b7ea8b8 100644
--- a/client/request.go
+++ b/client/request.go
@@ -29,8 +29,9 @@ import (
 	"strings"
 	"time"
 
-	"github.com/go-openapi/runtime"
 	"github.com/go-openapi/strfmt"
+
+	"github.com/go-openapi/runtime"
 )
 
 // NewRequest creates a new swagger http client request
@@ -181,7 +182,6 @@ func (r *request) buildHTTP(mediaType, basePath string, producers map[string]run
 					}
 				}
 			}
-
 		}()
 
 		goto DoneChoosingBodySource
@@ -216,7 +216,6 @@ DoneChoosingBodySource:
 	}
 
 	if auth != nil {
-
 		// If we're not using r.buf as our http.Request's body,
 		// either the payload is an io.Reader or io.ReadCloser,
 		// or we're doing a multipart form/file.
@@ -238,10 +237,8 @@ DoneChoosingBodySource:
 		//
 		var copyErr error
 		if buf, ok := body.(*bytes.Buffer); body != nil && (!ok || buf != r.buf) {
-
 			var copied bool
 			r.getBody = func(r *request) []byte {
-
 				if copied {
 					return getRequestBuffer(r)
 				}
@@ -274,7 +271,6 @@ DoneChoosingBodySource:
 		if authErr != nil {
 			return nil, authErr
 		}
-
 	}
 
 	// create http request
diff --git a/client/runtime.go b/client/runtime.go
index a34c976..00ce53d 100644
--- a/client/runtime.go
+++ b/client/runtime.go
@@ -31,10 +31,11 @@ import (
 	"sync"
 	"time"
 
+	"github.com/go-openapi/strfmt"
+
 	"github.com/go-openapi/runtime"
 	"github.com/go-openapi/runtime/logger"
 	"github.com/go-openapi/runtime/middleware"
-	"github.com/go-openapi/strfmt"
 )
 
 // TLSClientOptions to configure client authentication with mutual TLS
diff --git a/client_request.go b/client_request.go
index 904196a..6215e0a 100644
--- a/client_request.go
+++ b/client_request.go
@@ -41,7 +41,7 @@ type ClientRequestWriter interface {
 // add information to a swagger client request
 type ClientRequest interface {
 	SetHeaderParam(string, ...string) error
-	
+
 	GetHeaderParams() http.Header
 
 	SetQueryParam(string, ...string) error
diff --git a/fixtures/bugs/172/swagger.yml b/fixtures/bugs/172/swagger.yml
new file mode 100755
index 0000000..641532d
--- /dev/null
+++ b/fixtures/bugs/172/swagger.yml
@@ -0,0 +1,99 @@
+swagger: '2.0'
+info:
+  version: 1.0.0
+  title: 'Test'
+schemes:
+  - http
+produces:
+  - application/vnd.cia.v1+json
+
+paths:
+  /pets:
+    get:
+      description: Returns all pets from the system that the user has access to
+      operationId: findPets
+      parameters:
+        - name: tags
+          in: query
+          description: tags to filter by
+          required: false
+          type: array
+          items:
+            type: string
+          collectionFormat: csv
+        - name: limit
+          in: query
+          description: maximum number of results to return
+          required: false
+          type: integer
+          format: int32
+      responses:
+        '200':
+          description: pet response
+          schema:
+            type: array
+            items:
+              $ref: '#/definitions/pet'
+        default:
+          description: unexpected error
+          schema:
+            $ref: '#/definitions/errorModel'
+
+    post:
+      description: Creates a new pet in the store.  Duplicates are allowed
+      operationId: addPet
+      consumes:
+        - application/vnd.cia.v1+json
+      parameters:
+        - name: pet
+          in: body
+          description: Pet to add to the store
+          required: true
+          schema:
+            $ref: '#/definitions/newPet'
+      responses:
+        '200':
+          description: pet response
+          schema:
+            $ref: '#/definitions/pet'
+        default:
+          description: unexpected error
+          schema:
+            $ref: '#/definitions/errorModel'
+
+definitions:
+  pet:
+    required:
+      - id
+      - name
+    properties:
+      id:
+        type: integer
+        format: int64
+      name:
+        type: string
+      tag:
+        type: string
+
+  newPet:
+    allOf:
+      - $ref: '#/definitions/pet'
+      - required:
+          - name
+        properties:
+          id:
+            type: integer
+            format: int64
+          name:
+            type: string
+
+  errorModel:
+    required:
+      - code
+      - message
+    properties:
+      code:
+        type: integer
+        format: int32
+      message:
+        type: string
diff --git a/middleware/context.go b/middleware/context.go
index 9175df2..0ff9e39 100644
--- a/middleware/context.go
+++ b/middleware/context.go
@@ -21,16 +21,16 @@ import (
 	"strings"
 	"sync"
 
-	"github.com/go-openapi/runtime/security"
-
 	"github.com/go-openapi/analysis"
 	"github.com/go-openapi/errors"
 	"github.com/go-openapi/loads"
+	"github.com/go-openapi/spec"
+	"github.com/go-openapi/strfmt"
+
 	"github.com/go-openapi/runtime"
 	"github.com/go-openapi/runtime/logger"
 	"github.com/go-openapi/runtime/middleware/untyped"
-	"github.com/go-openapi/spec"
-	"github.com/go-openapi/strfmt"
+	"github.com/go-openapi/runtime/security"
 )
 
 // Debug when true turns on verbose logging
@@ -280,8 +280,8 @@ func (c *Context) RequiredProduces() []string {
 // if the request is not valid an error will be returned
 func (c *Context) BindValidRequest(request *http.Request, route *MatchedRoute, binder RequestBinder) error {
 	var res []error
+	var requestContentType string
 
-	requestContentType := "*/*"
 	// check and validate content type, select consumer
 	if runtime.HasBody(request) {
 		ct, _, err := runtime.ContentType(request.Header)
@@ -304,7 +304,7 @@ func (c *Context) BindValidRequest(request *http.Request, route *MatchedRoute, b
 	}
 
 	// check and validate the response format
-	if len(res) == 0 && runtime.HasBody(request) {
+	if len(res) == 0 {
 		if str := NegotiateContentType(request, route.Produces, requestContentType); str == "" {
 			res = append(res, errors.InvalidResponseFormat(request.Header.Get(runtime.HeaderAccept), route.Produces))
 		}
diff --git a/middleware/denco/LICENSE b/middleware/denco/LICENSE
old mode 100755
new mode 100644
diff --git a/middleware/denco/README.md b/middleware/denco/README.md
old mode 100755
new mode 100644
diff --git a/middleware/denco/router.go b/middleware/denco/router.go
old mode 100755
new mode 100644
index edb4c57..ecacc31
--- a/middleware/denco/router.go
+++ b/middleware/denco/router.go
@@ -425,7 +425,7 @@ type record struct {
 func makeRecords(srcs []Record) (statics, params []*record) {
 	termChar := string(TerminationCharacter)
 	paramPrefix := string(SeparatorCharacter) + string(ParamCharacter)
-	wildcardPrefix :=  string(SeparatorCharacter) + string(WildcardCharacter)
+	wildcardPrefix := string(SeparatorCharacter) + string(WildcardCharacter)
 	for _, r := range srcs {
 		if strings.Contains(r.Key, paramPrefix) || strings.Contains(r.Key, wildcardPrefix) {
 			r.Key += termChar
diff --git a/middleware/parameter.go b/middleware/parameter.go
index 8975b6e..2088605 100644
--- a/middleware/parameter.go
+++ b/middleware/parameter.go
@@ -24,11 +24,12 @@ import (
 	"strconv"
 
 	"github.com/go-openapi/errors"
-	"github.com/go-openapi/runtime"
 	"github.com/go-openapi/spec"
 	"github.com/go-openapi/strfmt"
 	"github.com/go-openapi/swag"
 	"github.com/go-openapi/validate"
+
+	"github.com/go-openapi/runtime"
 )
 
 const defaultMaxMemory = 32 << 20
diff --git a/middleware/request.go b/middleware/request.go
index ee725f5..4e1c0ab 100644
--- a/middleware/request.go
+++ b/middleware/request.go
@@ -19,9 +19,10 @@ import (
 	"reflect"
 
 	"github.com/go-openapi/errors"
-	"github.com/go-openapi/runtime"
 	"github.com/go-openapi/spec"
 	"github.com/go-openapi/strfmt"
+
+	"github.com/go-openapi/runtime"
 )
 
 // RequestBinder binds and validates the data from a http request
@@ -71,7 +72,6 @@ func (o *untypedRequestBinder) Bind(request *http.Request, routeParams RoutePara
 				}
 			}
 			target = reflect.Indirect(reflect.New(tpe))
-
 		}
 
 		if !target.IsValid() {
diff --git a/middleware/router.go b/middleware/router.go
index 539d847..6d797e8 100644
--- a/middleware/router.go
+++ b/middleware/router.go
@@ -26,10 +26,11 @@ import (
 	"github.com/go-openapi/analysis"
 	"github.com/go-openapi/errors"
 	"github.com/go-openapi/loads"
-	"github.com/go-openapi/runtime"
-	"github.com/go-openapi/runtime/middleware/denco"
 	"github.com/go-openapi/spec"
 	"github.com/go-openapi/strfmt"
+
+	"github.com/go-openapi/runtime"
+	"github.com/go-openapi/runtime/middleware/denco"
 )
 
 // RouteParam is a object to capture route params in a framework agnostic way.
diff --git a/middleware/untyped/api.go b/middleware/untyped/api.go
index 8226b1e..39a85f7 100644
--- a/middleware/untyped/api.go
+++ b/middleware/untyped/api.go
@@ -23,9 +23,10 @@ import (
 	"github.com/go-openapi/analysis"
 	"github.com/go-openapi/errors"
 	"github.com/go-openapi/loads"
-	"github.com/go-openapi/runtime"
 	"github.com/go-openapi/spec"
 	"github.com/go-openapi/strfmt"
+
+	"github.com/go-openapi/runtime"
 )
 
 // NewAPI creates the default untyped API
@@ -244,7 +245,6 @@ func (d *API) validate() error {
 }
 
 func (d *API) verify(name string, registrations []string, expectations []string) error {
-
 	sort.Strings(registrations)
 	sort.Strings(expectations)
 
diff --git a/middleware/validation.go b/middleware/validation.go
index bb8df3c..9505c66 100644
--- a/middleware/validation.go
+++ b/middleware/validation.go
@@ -20,8 +20,9 @@ import (
 	"strings"
 
 	"github.com/go-openapi/errors"
-	"github.com/go-openapi/runtime"
 	"github.com/go-openapi/swag"
+
+	"github.com/go-openapi/runtime"
 )
 
 type validation struct {
@@ -115,7 +116,7 @@ func (v *validation) contentType() {
 }
 
 func (v *validation) responseFormat() {
-	if str, rCtx := v.context.ResponseFormat(v.request, v.route.Produces); str == "" && runtime.HasBody(v.request) {
+	if str, rCtx := v.context.ResponseFormat(v.request, v.route.Produces); str == "" {
 		v.request = rCtx
 		v.result = append(v.result, errors.InvalidResponseFormat(v.request.Header.Get(runtime.HeaderAccept), v.route.Produces))
 	}
diff --git a/security/authenticator.go b/security/authenticator.go
index 5d058b8..476d26c 100644
--- a/security/authenticator.go
+++ b/security/authenticator.go
@@ -20,6 +20,7 @@ import (
 	"strings"
 
 	"github.com/go-openapi/errors"
+
 	"github.com/go-openapi/runtime"
 )
 


Test patch:
diff --git a/client/request_test.go b/client/request_test.go
index c1db584..9979fd8 100644
--- a/client/request_test.go
+++ b/client/request_test.go
@@ -31,10 +31,11 @@ import (
 	"strings"
 	"testing"
 
-	"github.com/go-openapi/runtime"
 	"github.com/go-openapi/strfmt"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
+
+	"github.com/go-openapi/runtime"
 )
 
 var testProducers = map[string]runtime.Producer{
@@ -530,7 +531,6 @@ func (t *testRoundTripper) RoundTrip(req *http.Request) (resp *http.Response, er
 }
 
 func TestGetBodyCallsBeforeRoundTrip(t *testing.T) {
-
 	server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
 		rw.WriteHeader(http.StatusCreated)
 		_, err := rw.Write([]byte("test result"))
diff --git a/client/response_test.go b/client/response_test.go
index 6b63426..5dc5db8 100644
--- a/client/response_test.go
+++ b/client/response_test.go
@@ -20,8 +20,9 @@ import (
 	"net/http"
 	"testing"
 
-	"github.com/go-openapi/runtime"
 	"github.com/stretchr/testify/assert"
+
+	"github.com/go-openapi/runtime"
 )
 
 func TestResponse(t *testing.T) {
diff --git a/client/runtime_test.go b/client/runtime_test.go
index 64f5441..498459e 100644
--- a/client/runtime_test.go
+++ b/client/runtime_test.go
@@ -32,10 +32,11 @@ import (
 	"crypto/x509"
 	"encoding/pem"
 
-	"github.com/go-openapi/runtime"
 	"github.com/go-openapi/strfmt"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
+
+	"github.com/go-openapi/runtime"
 )
 
 // task This describes a task. Tasks require a content property to be set.
@@ -68,7 +69,6 @@ func TestRuntime_TLSAuthConfig(t *testing.T) {
 }
 
 func TestRuntime_TLSAuthConfigWithRSAKey(t *testing.T) {
-
 	keyPem, err := ioutil.ReadFile("../fixtures/certs/myclient.key")
 	require.NoError(t, err)
 
@@ -99,7 +99,6 @@ func TestRuntime_TLSAuthConfigWithRSAKey(t *testing.T) {
 }
 
 func TestRuntime_TLSAuthConfigWithECKey(t *testing.T) {
-
 	keyPem, err := ioutil.ReadFile("../fixtures/certs/myclient-ecc.key")
 	require.NoError(t, err)
 
@@ -131,7 +130,6 @@ func TestRuntime_TLSAuthConfigWithECKey(t *testing.T) {
 }
 
 func TestRuntime_TLSAuthConfigWithLoadedCA(t *testing.T) {
-
 	certPem, err := ioutil.ReadFile("../fixtures/certs/myCA.crt")
 	require.NoError(t, err)
 
@@ -153,7 +151,6 @@ func TestRuntime_TLSAuthConfigWithLoadedCA(t *testing.T) {
 }
 
 func TestRuntime_TLSAuthConfigWithLoadedCAPool(t *testing.T) {
-
 	certPem, err := ioutil.ReadFile("../fixtures/certs/myCA.crt")
 	require.NoError(t, err)
 
@@ -182,7 +179,6 @@ func TestRuntime_TLSAuthConfigWithLoadedCAPool(t *testing.T) {
 }
 
 func TestRuntime_TLSAuthConfigWithLoadedCAPoolAndLoadedCA(t *testing.T) {
-
 	certPem, err := ioutil.ReadFile("../fixtures/certs/myCA.crt")
 	require.NoError(t, err)
 
diff --git a/client_request_test.go b/client_request_test.go
index 6fce381..7daaa12 100644
--- a/client_request_test.go
+++ b/client_request_test.go
@@ -75,7 +75,6 @@ func (t *trw) GetHeaderParams() http.Header {
 }
 
 func TestRequestWriterFunc(t *testing.T) {
-
 	hand := ClientRequestWriterFunc(func(r ClientRequest, reg strfmt.Registry) error {
 		_ = r.SetHeaderParam("blah", "blah blah")
 		_ = r.SetBodyParam(struct{ Name string }{"Adriana"})
diff --git a/csv_test.go b/csv_test.go
index cfc4a93..e87b791 100644
--- a/csv_test.go
+++ b/csv_test.go
@@ -16,10 +16,11 @@ package runtime
 
 import (
 	"bytes"
-	"github.com/stretchr/testify/assert"
 	"io"
 	"net/http/httptest"
 	"testing"
+
+	"github.com/stretchr/testify/assert"
 )
 
 const consProdCSV = `name,country,age
diff --git a/flagext/byte_size_test.go b/flagext/byte_size_test.go
index 4e569e5..698fc0e 100644
--- a/flagext/byte_size_test.go
+++ b/flagext/byte_size_test.go
@@ -1,7 +1,10 @@
 package flagext
 
-import "testing"
-import "github.com/stretchr/testify/assert"
+import (
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+)
 
 func TestMarshalBytesize(t *testing.T) {
 	v, err := ByteSize(1024).MarshalFlag()
diff --git a/headers_test.go b/headers_test.go
index c9e3343..f012dba 100644
--- a/headers_test.go
+++ b/headers_test.go
@@ -57,5 +57,4 @@ func TestParseContentType(t *testing.T) {
 		assert.Equal(t, v.mt, ct, "input: %q", v.hdr)
 		assert.Equal(t, v.cs, cs, "input: %q", v.hdr)
 	}
-
 }
diff --git a/internal/testing/petstore/api.go b/internal/testing/petstore/api.go
index 2a066ce..91641f7 100644
--- a/internal/testing/petstore/api.go
+++ b/internal/testing/petstore/api.go
@@ -23,12 +23,13 @@ import (
 
 	"github.com/go-openapi/errors"
 	"github.com/go-openapi/loads"
+	"github.com/stretchr/testify/assert"
+
 	"github.com/go-openapi/runtime"
 	testingutil "github.com/go-openapi/runtime/internal/testing"
 	"github.com/go-openapi/runtime/middleware/untyped"
 	"github.com/go-openapi/runtime/security"
 	"github.com/go-openapi/runtime/yamlpc"
-	"github.com/stretchr/testify/assert"
 )
 
 // NewAPI registers a stub api for the pet store
diff --git a/internal/testing/simplepetstore/api.go b/internal/testing/simplepetstore/api.go
index 1505420..0ba667b 100644
--- a/internal/testing/simplepetstore/api.go
+++ b/internal/testing/simplepetstore/api.go
@@ -22,6 +22,7 @@ import (
 
 	"github.com/go-openapi/errors"
 	"github.com/go-openapi/loads"
+
 	"github.com/go-openapi/runtime"
 	"github.com/go-openapi/runtime/middleware"
 	"github.com/go-openapi/runtime/middleware/untyped"
diff --git a/internal/testing/simplepetstore/api_test.go b/internal/testing/simplepetstore/api_test.go
index 6681863..a62706e 100644
--- a/internal/testing/simplepetstore/api_test.go
+++ b/internal/testing/simplepetstore/api_test.go
@@ -19,8 +19,9 @@ import (
 	"net/http/httptest"
 	"testing"
 
-	"github.com/go-openapi/runtime"
 	"github.com/stretchr/testify/assert"
+
+	"github.com/go-openapi/runtime"
 )
 
 func TestSimplePetstoreSpec(t *testing.T) {
diff --git a/middleware/body_test.go b/middleware/body_test.go
index 7e8ad0f..de128b7 100644
--- a/middleware/body_test.go
+++ b/middleware/body_test.go
@@ -6,9 +6,10 @@ import (
 	"path"
 	"testing"
 
+	"github.com/stretchr/testify/assert"
+
 	"github.com/go-openapi/runtime"
 	"github.com/go-openapi/runtime/internal/testing/petstore"
-	"github.com/stretchr/testify/assert"
 )
 
 type eofReader struct {
diff --git a/middleware/context_test.go b/middleware/context_test.go
index e236ece..3d5d0e2 100644
--- a/middleware/context_test.go
+++ b/middleware/context_test.go
@@ -18,16 +18,26 @@ import (
 	"errors"
 	"net/http"
 	"net/http/httptest"
+	"strings"
 	"testing"
 
+	apierrors "github.com/go-openapi/errors"
 	"github.com/go-openapi/loads"
 	"github.com/go-openapi/loads/fmts"
+	"github.com/stretchr/testify/assert"
+
 	"github.com/go-openapi/runtime"
 	"github.com/go-openapi/runtime/internal/testing/petstore"
 	"github.com/go-openapi/runtime/middleware/untyped"
-	"github.com/stretchr/testify/assert"
 )
 
+type stubBindRequester struct {
+}
+
+func (s *stubBindRequester) BindRequest(*http.Request, *MatchedRoute) error {
+	return nil
+}
+
 type stubOperationHandler struct {
 }
 
@@ -43,6 +53,20 @@ func init() {
 	loads.AddLoader(fmts.YAMLMatcher, fmts.YAMLDoc)
 }
 
+func assertApiError(t *testing.T, wantCode int, err error) {
+	t.Helper()
+
+	assert.NotNil(t, err)
+
+	ce, ok := err.(*apierrors.CompositeError)
+	assert.True(t, ok)
+	assert.NotEmpty(t, ce.Errors)
+
+	ae, ok := ce.Errors[0].(apierrors.Error)
+	assert.True(t, ok)
+	assert.Equal(t, wantCode, int(ae.Code()))
+}
+
 func TestContentType_Issue264(t *testing.T) {
 	swspec, err := loads.Spec("../fixtures/bugs/264/swagger.yml")
 	if assert.NoError(t, err) {
@@ -59,6 +83,23 @@ func TestContentType_Issue264(t *testing.T) {
 	}
 }
 
+func TestContentType_Issue172(t *testing.T) {
+	swspec, err := loads.Spec("../fixtures/bugs/172/swagger.yml")
+	if assert.NoError(t, err) {
+		api := untyped.NewAPI(swspec)
+		api.RegisterConsumer("application/vnd.cia.v1+json", runtime.JSONConsumer())
+		api.RegisterProducer("application/vnd.cia.v1+json", runtime.JSONProducer())
+		api.RegisterOperation("get", "/pets", new(stubOperationHandler))
+
+		handler := Serve(swspec, api)
+		request, _ := http.NewRequest("GET", "/pets", nil)
+		request.Header.Add("Accept", "application/json")
+		recorder := httptest.NewRecorder()
+		handler.ServeHTTP(recorder, request)
+		assert.Equal(t, http.StatusNotAcceptable, recorder.Code)
+	}
+}
+
 func TestServe(t *testing.T) {
 	spec, api := petstore.NewAPI(t)
 	handler := Serve(spec, api)
@@ -175,6 +216,34 @@ func TestContextNegotiateContentType(t *testing.T) {
 	assert.Equal(t, ri.Produces[0], res)
 }
 
+func TestContextBindValidRequest(t *testing.T) {
+	spec, api := petstore.NewAPI(t)
+	ctx := NewContext(spec, api, nil)
+	ctx.router = DefaultRouter(spec, ctx.api)
+
+	// invalid content-type value
+	request, _ := http.NewRequest("POST", "/api/pets", strings.NewReader(`{"name":"dog"}`))
+	request.Header.Add("content-type", "/json")
+
+	ri, request, _ := ctx.RouteInfo(request)
+	assertApiError(t, 400, ctx.BindValidRequest(request, ri, new(stubBindRequester)))
+
+	// unsupported content-type value
+	request, _ = http.NewRequest("POST", "/api/pets", strings.NewReader(`{"name":"dog"}`))
+	request.Header.Add("content-type", "text/html")
+
+	ri, request, _ = ctx.RouteInfo(request)
+	assertApiError(t, http.StatusUnsupportedMediaType, ctx.BindValidRequest(request, ri, new(stubBindRequester)))
+
+	// unacceptable accept value
+	request, _ = http.NewRequest("POST", "/api/pets", nil)
+	request.Header.Add("Accept", "application/vnd.cia.v1+json")
+	request.Header.Add("content-type", "application/json")
+
+	ri, request, _ = ctx.RouteInfo(request)
+	assertApiError(t, http.StatusNotAcceptable, ctx.BindValidRequest(request, ri, new(stubBindRequester)))
+}
+
 func TestContextBindAndValidate(t *testing.T) {
 	spec, api := petstore.NewAPI(t)
 	ctx := NewContext(spec, api, nil)
@@ -259,7 +328,6 @@ func TestContextRender(t *testing.T) {
 	ri, request, _ = ctx.RouteInfo(request)
 	ctx.Respond(recorder, request, ri.Produces, ri, nil)
 	assert.Equal(t, 204, recorder.Code)
-
 }
 
 func TestContextValidResponseFormat(t *testing.T) {
diff --git a/middleware/denco/router_bench_test.go b/middleware/denco/router_bench_test.go
old mode 100755
new mode 100644
diff --git a/middleware/denco/router_test.go b/middleware/denco/router_test.go
old mode 100755
new mode 100644
diff --git a/middleware/denco/server.go b/middleware/denco/server.go
old mode 100755
new mode 100644
diff --git a/middleware/denco/server_test.go b/middleware/denco/server_test.go
old mode 100755
new mode 100644
diff --git a/middleware/denco/util.go b/middleware/denco/util.go
old mode 100755
new mode 100644
diff --git a/middleware/denco/util_test.go b/middleware/denco/util_test.go
old mode 100755
new mode 100644
diff --git a/middleware/negotiate_test.go b/middleware/negotiate_test.go
index ca8d70a..d7addee 100644
--- a/middleware/negotiate_test.go
+++ b/middleware/negotiate_test.go
@@ -61,6 +61,7 @@ var negotiateContentTypeTests = []struct {
 	{"application/vnd.google.protobuf;proto=io.prometheus.client.MetricFamily;encoding=delimited;q=0.7,text/plain;version=0.0.4;q=0.3", []string{"text/plain"}, "", "text/plain"},
 	{"application/json", []string{"application/json; charset=utf-8", "image/png"}, "", "application/json; charset=utf-8"},
 	{"application/json; charset=utf-8", []string{"application/json; charset=utf-8", "image/png"}, "", "application/json; charset=utf-8"},
+	{"application/json", []string{"application/vnd.cia.v1+json"}, "", ""},
 }
 
 func TestNegotiateContentType(t *testing.T) {
diff --git a/middleware/operation_test.go b/middleware/operation_test.go
index 90ea061..c687373 100644
--- a/middleware/operation_test.go
+++ b/middleware/operation_test.go
@@ -20,9 +20,10 @@ import (
 	"testing"
 
 	"github.com/go-openapi/errors"
+	"github.com/stretchr/testify/assert"
+
 	"github.com/go-openapi/runtime"
 	"github.com/go-openapi/runtime/internal/testing/petstore"
-	"github.com/stretchr/testify/assert"
 )
 
 func TestOperationExecutor(t *testing.T) {
diff --git a/middleware/parameter_test.go b/middleware/parameter_test.go
index d0524ab..30a2f09 100644
--- a/middleware/parameter_test.go
+++ b/middleware/parameter_test.go
@@ -22,10 +22,11 @@ import (
 	"testing"
 
 	"github.com/go-openapi/errors"
-	"github.com/go-openapi/runtime"
 	"github.com/go-openapi/spec"
 	"github.com/go-openapi/strfmt"
 	"github.com/stretchr/testify/assert"
+
+	"github.com/go-openapi/runtime"
 )
 
 // type email struct {
@@ -69,7 +70,6 @@ func requiredError(param *spec.Parameter) *errors.Validation {
 }
 
 func validateRequiredTest(t *testing.T, param *spec.Parameter, value reflect.Value) {
-
 	binder := np(param)
 	err := binder.bindValue([]string{}, true, value)
 	assert.Error(t, err)
diff --git a/middleware/request_test.go b/middleware/request_test.go
index 69ac165..69d00f4 100644
--- a/middleware/request_test.go
+++ b/middleware/request_test.go
@@ -27,10 +27,11 @@ import (
 
 	"github.com/stretchr/testify/require"
 
-	"github.com/go-openapi/runtime"
 	"github.com/go-openapi/spec"
 	"github.com/go-openapi/strfmt"
 	"github.com/stretchr/testify/assert"
+
+	"github.com/go-openapi/runtime"
 )
 
 type stubConsumer struct {
@@ -219,7 +220,6 @@ func TestRequestBindingDefaultValue(t *testing.T) {
 }
 
 func TestRequestBindingForInvalid(t *testing.T) {
-
 	invalidParam := spec.QueryParam("some")
 
 	op1 := map[string]spec.Parameter{"Some": *invalidParam}
@@ -279,7 +279,6 @@ func TestRequestBindingForInvalid(t *testing.T) {
 }
 
 func TestRequestBindingForValid(t *testing.T) {
-
 	for _, fmt := range []string{"csv", "pipes", "tsv", "ssv", "multi"} {
 		op1 := parametersForJSONRequestParams(fmt)
 
@@ -470,5 +469,4 @@ func TestBindingFileUpload(t *testing.T) {
 
 	data = fileRequest{}
 	assert.Error(t, binder.Bind(req, nil, runtime.JSONConsumer(), &data))
-
 }
diff --git a/middleware/route_authenticator_test.go b/middleware/route_authenticator_test.go
index 4172154..ab2c41f 100644
--- a/middleware/route_authenticator_test.go
+++ b/middleware/route_authenticator_test.go
@@ -5,8 +5,9 @@ import (
 	"net/http"
 	"testing"
 
-	"github.com/go-openapi/runtime"
 	"github.com/stretchr/testify/require"
+
+	"github.com/go-openapi/runtime"
 )
 
 type countAuthenticator struct {
@@ -202,7 +203,7 @@ func TestAuthenticateOptional(t *testing.T) {
 	ra2 := RouteAuthenticator{
 		allowAnonymous: true,
 		Schemes:        []string{""},
-		Scopes:         map[string][]string{"": []string{}},
+		Scopes:         map[string][]string{"": {}},
 	}
 
 	ra3 := RouteAuthenticator{
diff --git a/middleware/router_test.go b/middleware/router_test.go
index 3368780..eb78623 100644
--- a/middleware/router_test.go
+++ b/middleware/router_test.go
@@ -23,9 +23,10 @@ import (
 
 	"github.com/go-openapi/analysis"
 	"github.com/go-openapi/loads"
+	"github.com/stretchr/testify/assert"
+
 	"github.com/go-openapi/runtime/internal/testing/petstore"
 	"github.com/go-openapi/runtime/middleware/untyped"
-	"github.com/stretchr/testify/assert"
 )
 
 func terminator(rw http.ResponseWriter, r *http.Request) {
@@ -90,7 +91,6 @@ func TestRouterMiddleware(t *testing.T) {
 
 	mw.ServeHTTP(recorder, request)
 	assert.Equal(t, http.StatusNotFound, recorder.Code)
-
 }
 
 func TestRouterBuilder(t *testing.T) {
diff --git a/middleware/security_test.go b/middleware/security_test.go
index 8697ebc..3218e12 100644
--- a/middleware/security_test.go
+++ b/middleware/security_test.go
@@ -19,8 +19,9 @@ import (
 	"net/http/httptest"
 	"testing"
 
-	"github.com/go-openapi/runtime/internal/testing/petstore"
 	"github.com/stretchr/testify/assert"
+
+	"github.com/go-openapi/runtime/internal/testing/petstore"
 )
 
 func TestSecurityMiddleware(t *testing.T) {
@@ -55,5 +56,4 @@ func TestSecurityMiddleware(t *testing.T) {
 
 	mw.ServeHTTP(recorder, request)
 	assert.Equal(t, 200, recorder.Code)
-
 }
diff --git a/middleware/spec_test.go b/middleware/spec_test.go
index 822a7a6..3dfc489 100644
--- a/middleware/spec_test.go
+++ b/middleware/spec_test.go
@@ -19,9 +19,10 @@ import (
 	"net/http/httptest"
 	"testing"
 
+	"github.com/stretchr/testify/assert"
+
 	"github.com/go-openapi/runtime"
 	"github.com/go-openapi/runtime/internal/testing/petstore"
-	"github.com/stretchr/testify/assert"
 )
 
 func TestServeSpecMiddleware(t *testing.T) {
@@ -52,5 +53,4 @@ func TestServeSpecMiddleware(t *testing.T) {
 	recorder = httptest.NewRecorder()
 	handler.ServeHTTP(recorder, request)
 	assert.Equal(t, 200, recorder.Code)
-
 }
diff --git a/middleware/string_conversion_test.go b/middleware/string_conversion_test.go
index c0ee016..18c3a99 100644
--- a/middleware/string_conversion_test.go
+++ b/middleware/string_conversion_test.go
@@ -102,7 +102,6 @@ func IntParamTest(t *testing.T, pName string, val reflect.Value, defVal, expecte
 }
 
 func TestParamBinding(t *testing.T) {
-
 	actual := new(SomeOperationParams)
 	val := reflect.ValueOf(actual).Elem()
 	pName := "Name"
@@ -247,7 +246,6 @@ func TestParamBinding(t *testing.T) {
 }
 
 func TestSliceConversion(t *testing.T) {
-
 	actual := new(SomeOperationParams)
 	val := reflect.ValueOf(actual).Elem()
 
diff --git a/middleware/untyped/api_test.go b/middleware/untyped/api_test.go
index 5d93adb..7ec5076 100644
--- a/middleware/untyped/api_test.go
+++ b/middleware/untyped/api_test.go
@@ -23,9 +23,10 @@ import (
 	"github.com/go-openapi/analysis"
 	"github.com/go-openapi/errors"
 	"github.com/go-openapi/loads"
-	"github.com/go-openapi/runtime"
 	swaggerspec "github.com/go-openapi/spec"
 	"github.com/stretchr/testify/assert"
+
+	"github.com/go-openapi/runtime"
 )
 
 func stubAutenticator() runtime.Authenticator {
diff --git a/middleware/untyped_request_test.go b/middleware/untyped_request_test.go
index 5c226f6..61d8583 100644
--- a/middleware/untyped_request_test.go
+++ b/middleware/untyped_request_test.go
@@ -26,9 +26,10 @@ import (
 	"testing"
 	"time"
 
-	"github.com/go-openapi/runtime"
 	"github.com/go-openapi/strfmt"
 	"github.com/stretchr/testify/assert"
+
+	"github.com/go-openapi/runtime"
 )
 
 func TestUntypedFormPost(t *testing.T) {
@@ -113,7 +114,6 @@ func TestUntypedFileUpload(t *testing.T) {
 }
 
 func TestUntypedBindingTypesForValid(t *testing.T) {
-
 	op2 := parametersForAllTypes("")
 	binder := newUntypedRequestBinder(op2, nil, strfmt.Default)
 
@@ -160,5 +160,4 @@ func TestUntypedBindingTypesForValid(t *testing.T) {
 	assert.Equal(t, score, data["score"])
 	pb, _ := base64.URLEncoding.DecodeString(picture)
 	assert.EqualValues(t, pb, data["picture"].(strfmt.Base64))
-
 }
diff --git a/middleware/validation_test.go b/middleware/validation_test.go
index c7f469a..e7997b6 100644
--- a/middleware/validation_test.go
+++ b/middleware/validation_test.go
@@ -22,13 +22,13 @@ import (
 	"testing"
 
 	"github.com/go-openapi/errors"
+	"github.com/stretchr/testify/assert"
+
 	"github.com/go-openapi/runtime"
 	"github.com/go-openapi/runtime/internal/testing/petstore"
-	"github.com/stretchr/testify/assert"
 )
 
 func newTestValidation(ctx *Context, next http.Handler) http.Handler {
-
 	return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
 		matched, rCtx, _ := ctx.RouteInfo(r)
 		if rCtx != nil {
@@ -97,7 +97,7 @@ func TestContentTypeValidation(t *testing.T) {
 	request.Header.Add("content-type", "text/html")
 
 	mw.ServeHTTP(recorder, request)
-	assert.Equal(t, 422, recorder.Code)
+	assert.Equal(t, 406, recorder.Code)
 	assert.Equal(t, "application/json", recorder.Header().Get("content-type"))
 }
 
diff --git a/request_test.go b/request_test.go
index d73454b..2737300 100644
--- a/request_test.go
+++ b/request_test.go
@@ -190,5 +190,4 @@ func (v tv) GetOK(key string) (value []string, hasKey bool, hasValue bool) {
 	}
 	hasValue = true
 	return
-
 }