From f36b5a7fc457d867e2562431b320d71684b2a545 Mon Sep 17 00:00:00 2001 From: Jamie Tanna Date: Sat, 12 Nov 2022 20:59:04 +0000 Subject: [PATCH] Revert "Lint: apply common initialisms" This reverts commit 3cdeb318b27ef13492efd06788246e809c923c9d. --- .../echo/server/server_test.go | 10 +++++----- .../petstore-expanded/chi/petstore_test.go | 4 ++-- .../petstore-expanded/echo/petstore_test.go | 16 ++++++++-------- .../petstore-expanded/gin/petstore_test.go | 4 ++-- .../petstore-expanded/gorilla/petstore_test.go | 4 ++-- .../petstore-expanded/strict/petstore_test.go | 4 ++-- internal/test/components/components_test.go | 18 +++++++++--------- internal/test/issues/issue-312/issue_test.go | 4 ++-- internal/test/strict-server/strict_test.go | 10 +++++----- pkg/chi-middleware/oapi_validate_test.go | 4 ++-- pkg/gin-middleware/oapi_validate_test.go | 4 ++-- pkg/middleware/oapi_validate_test.go | 4 ++-- pkg/testutil/request_helpers.go | 14 +++++++------- 13 files changed, 50 insertions(+), 50 deletions(-) diff --git a/examples/authenticated-api/echo/server/server_test.go b/examples/authenticated-api/echo/server/server_test.go index 1eede0aee..21366f54b 100644 --- a/examples/authenticated-api/echo/server/server_test.go +++ b/examples/authenticated-api/echo/server/server_test.go @@ -40,15 +40,15 @@ func TestAPI(t *testing.T) { // Using the writer JWT should allow us to insert a thing. response = testutil.NewRequest().Post("/things"). WithJWSAuth(string(writerJWT)). - WithAcceptJSON(). - WithJSONBody(api.Thing{Name: "Thing 1"}).Go(t, e) + WithAcceptJson(). + WithJsonBody(api.Thing{Name: "Thing 1"}).Go(t, e) require.Equal(t, http.StatusCreated, response.Code()) // Using the reader JWT should forbid inserting a thing. response = testutil.NewRequest().Post("/things"). WithJWSAuth(string(readerJWT)). - WithAcceptJSON(). - WithJSONBody(api.Thing{Name: "Thing 2"}).Go(t, e) + WithAcceptJson(). + WithJsonBody(api.Thing{Name: "Thing 2"}).Go(t, e) require.Equal(t, http.StatusForbidden, response.Code()) // Both JWT's should allow reading the list of things. @@ -56,7 +56,7 @@ func TestAPI(t *testing.T) { for _, jwt := range jwts { response := testutil.NewRequest().Get("/things"). WithJWSAuth(jwt). - WithAcceptJSON().Go(t, e) + WithAcceptJson().Go(t, e) assert.Equal(t, http.StatusOK, response.Code()) } } diff --git a/examples/petstore-expanded/chi/petstore_test.go b/examples/petstore-expanded/chi/petstore_test.go index feedfb55d..5e36439c3 100644 --- a/examples/petstore-expanded/chi/petstore_test.go +++ b/examples/petstore-expanded/chi/petstore_test.go @@ -16,7 +16,7 @@ import ( ) func doGet(t *testing.T, mux *chi.Mux, url string) *httptest.ResponseRecorder { - response := testutil.NewRequest().Get(url).WithAcceptJSON().GoWithHTTPHandler(t, mux) + response := testutil.NewRequest().Get(url).WithAcceptJson().GoWithHTTPHandler(t, mux) return response.Recorder } @@ -48,7 +48,7 @@ func TestPetStore(t *testing.T) { Tag: &tag, } - rr := testutil.NewRequest().Post("/pets").WithJSONBody(newPet).GoWithHTTPHandler(t, r).Recorder + rr := testutil.NewRequest().Post("/pets").WithJsonBody(newPet).GoWithHTTPHandler(t, r).Recorder assert.Equal(t, http.StatusCreated, rr.Code) var resultPet api.Pet diff --git a/examples/petstore-expanded/echo/petstore_test.go b/examples/petstore-expanded/echo/petstore_test.go index 8570cded3..36f5f426c 100644 --- a/examples/petstore-expanded/echo/petstore_test.go +++ b/examples/petstore-expanded/echo/petstore_test.go @@ -64,7 +64,7 @@ func TestPetStore(t *testing.T) { Name: "Spot", Tag: &tag, } - result := testutil.NewRequest().Post("/pets").WithJSONBody(newPet).Go(t, e) + result := testutil.NewRequest().Post("/pets").WithJsonBody(newPet).Go(t, e) // We expect 201 code on successful pet insertion assert.Equal(t, http.StatusCreated, result.Code()) @@ -80,14 +80,14 @@ func TestPetStore(t *testing.T) { petId := resultPet.Id // Test the getter function. - result = testutil.NewRequest().Get(fmt.Sprintf("/pets/%d", petId)).WithAcceptJSON().Go(t, e) + result = testutil.NewRequest().Get(fmt.Sprintf("/pets/%d", petId)).WithAcceptJson().Go(t, e) var resultPet2 models.Pet err = result.UnmarshalBodyToObject(&resultPet2) assert.NoError(t, err, "error getting pet") assert.Equal(t, resultPet, resultPet2) // We should get a 404 on invalid ID - result = testutil.NewRequest().Get("/pets/27179095781").WithAcceptJSON().Go(t, e) + result = testutil.NewRequest().Get("/pets/27179095781").WithAcceptJson().Go(t, e) assert.Equal(t, http.StatusNotFound, result.Code()) var petError models.Error err = result.UnmarshalBodyToObject(&petError) @@ -100,7 +100,7 @@ func TestPetStore(t *testing.T) { Name: "Fido", Tag: &tag, } - result = testutil.NewRequest().Post("/pets").WithJSONBody(newPet).Go(t, e) + result = testutil.NewRequest().Post("/pets").WithJsonBody(newPet).Go(t, e) // We expect 201 code on successful pet insertion assert.Equal(t, http.StatusCreated, result.Code()) // We should have gotten a response from the server with the new pet. Make @@ -110,7 +110,7 @@ func TestPetStore(t *testing.T) { petId2 := resultPet.Id // Now, list all pets, we should have two - result = testutil.NewRequest().Get("/pets").WithAcceptJSON().Go(t, e) + result = testutil.NewRequest().Get("/pets").WithAcceptJson().Go(t, e) assert.Equal(t, http.StatusOK, result.Code()) var petList []models.Pet err = result.UnmarshalBodyToObject(&petList) @@ -119,7 +119,7 @@ func TestPetStore(t *testing.T) { // Filter pets by tag, we should have 1 petList = nil - result = testutil.NewRequest().Get("/pets?tags=TagOfFido").WithAcceptJSON().Go(t, e) + result = testutil.NewRequest().Get("/pets?tags=TagOfFido").WithAcceptJson().Go(t, e) assert.Equal(t, http.StatusOK, result.Code()) err = result.UnmarshalBodyToObject(&petList) assert.NoError(t, err, "error getting response", err) @@ -127,7 +127,7 @@ func TestPetStore(t *testing.T) { // Filter pets by non existent tag, we should have 0 petList = nil - result = testutil.NewRequest().Get("/pets?tags=NotExists").WithAcceptJSON().Go(t, e) + result = testutil.NewRequest().Get("/pets?tags=NotExists").WithAcceptJson().Go(t, e) assert.Equal(t, http.StatusOK, result.Code()) err = result.UnmarshalBodyToObject(&petList) assert.NoError(t, err, "error getting response", err) @@ -148,7 +148,7 @@ func TestPetStore(t *testing.T) { // Should have no pets left. petList = nil - result = testutil.NewRequest().Get("/pets").WithAcceptJSON().Go(t, e) + result = testutil.NewRequest().Get("/pets").WithAcceptJson().Go(t, e) assert.Equal(t, http.StatusOK, result.Code()) err = result.UnmarshalBodyToObject(&petList) assert.NoError(t, err, "error getting response", err) diff --git a/examples/petstore-expanded/gin/petstore_test.go b/examples/petstore-expanded/gin/petstore_test.go index 7975f148b..ccb38de06 100644 --- a/examples/petstore-expanded/gin/petstore_test.go +++ b/examples/petstore-expanded/gin/petstore_test.go @@ -13,7 +13,7 @@ import ( ) func doGet(t *testing.T, handler http.Handler, url string) *httptest.ResponseRecorder { - response := testutil.NewRequest().Get(url).WithAcceptJSON().GoWithHTTPHandler(t, handler) + response := testutil.NewRequest().Get(url).WithAcceptJson().GoWithHTTPHandler(t, handler) return response.Recorder } @@ -30,7 +30,7 @@ func TestPetStore(t *testing.T) { Tag: &tag, } - rr := testutil.NewRequest().Post("/pets").WithJSONBody(newPet).GoWithHTTPHandler(t, r).Recorder + rr := testutil.NewRequest().Post("/pets").WithJsonBody(newPet).GoWithHTTPHandler(t, r).Recorder assert.Equal(t, http.StatusCreated, rr.Code) var resultPet api.Pet diff --git a/examples/petstore-expanded/gorilla/petstore_test.go b/examples/petstore-expanded/gorilla/petstore_test.go index 0a1624390..c60afbc07 100644 --- a/examples/petstore-expanded/gorilla/petstore_test.go +++ b/examples/petstore-expanded/gorilla/petstore_test.go @@ -16,7 +16,7 @@ import ( ) func doGet(t *testing.T, mux *mux.Router, url string) *httptest.ResponseRecorder { - response := testutil.NewRequest().Get(url).WithAcceptJSON().GoWithHTTPHandler(t, mux) + response := testutil.NewRequest().Get(url).WithAcceptJson().GoWithHTTPHandler(t, mux) return response.Recorder } @@ -48,7 +48,7 @@ func TestPetStore(t *testing.T) { Tag: &tag, } - rr := testutil.NewRequest().Post("/pets").WithJSONBody(newPet).GoWithHTTPHandler(t, r).Recorder + rr := testutil.NewRequest().Post("/pets").WithJsonBody(newPet).GoWithHTTPHandler(t, r).Recorder assert.Equal(t, http.StatusCreated, rr.Code) var resultPet api.Pet diff --git a/examples/petstore-expanded/strict/petstore_test.go b/examples/petstore-expanded/strict/petstore_test.go index 6b3888fd5..34891e0d3 100644 --- a/examples/petstore-expanded/strict/petstore_test.go +++ b/examples/petstore-expanded/strict/petstore_test.go @@ -16,7 +16,7 @@ import ( ) func doGet(t *testing.T, mux *chi.Mux, url string) *httptest.ResponseRecorder { - response := testutil.NewRequest().Get(url).WithAcceptJSON().GoWithHTTPHandler(t, mux) + response := testutil.NewRequest().Get(url).WithAcceptJson().GoWithHTTPHandler(t, mux) return response.Recorder } @@ -48,7 +48,7 @@ func TestPetStore(t *testing.T) { Tag: &tag, } - rr := testutil.NewRequest().Post("/pets").WithJSONBody(newPet).GoWithHTTPHandler(t, r).Recorder + rr := testutil.NewRequest().Post("/pets").WithJsonBody(newPet).GoWithHTTPHandler(t, r).Recorder assert.Equal(t, http.StatusOK, rr.Code) var resultPet api.Pet diff --git a/internal/test/components/components_test.go b/internal/test/components/components_test.go index 4e8f9c408..0c3bdd8e3 100644 --- a/internal/test/components/components_test.go +++ b/internal/test/components/components_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/assert" ) -func assertJSONEqual(t *testing.T, j1 []byte, j2 []byte) { +func assertJsonEqual(t *testing.T, j1 []byte, j2 []byte) { var v1, v2 interface{} err := json.Unmarshal(j1, &v1) @@ -29,7 +29,7 @@ func TestRawJSON(t *testing.T) { buf2, err := json.Marshal(dst) assert.NoError(t, err) - assertJSONEqual(t, []byte(buf), buf2) + assertJsonEqual(t, []byte(buf), buf2) } @@ -99,19 +99,19 @@ func TestOneOf(t *testing.T) { assert.NoError(t, err) marshaled, err := json.Marshal(dst) assert.NoError(t, err) - assertJSONEqual(t, []byte(variant1), marshaled) + assertJsonEqual(t, []byte(variant1), marshaled) err = dst.FromOneOfVariant2([]int{1, 2, 3}) assert.NoError(t, err) marshaled, err = json.Marshal(dst) assert.NoError(t, err) - assertJSONEqual(t, []byte(variant2), marshaled) + assertJsonEqual(t, []byte(variant2), marshaled) err = dst.FromOneOfVariant3(true) assert.NoError(t, err) marshaled, err = json.Marshal(dst) assert.NoError(t, err) - assertJSONEqual(t, []byte(variant3), marshaled) + assertJsonEqual(t, []byte(variant3), marshaled) } func TestOneOfWithDiscriminator(t *testing.T) { @@ -142,13 +142,13 @@ func TestOneOfWithDiscriminator(t *testing.T) { assert.NoError(t, err) marshaled, err := json.Marshal(dst) assert.NoError(t, err) - assertJSONEqual(t, []byte(variant4), marshaled) + assertJsonEqual(t, []byte(variant4), marshaled) err = dst.FromOneOfVariant5(OneOfVariant5{Id: 123}) assert.NoError(t, err) marshaled, err = json.Marshal(dst) assert.NoError(t, err) - assertJSONEqual(t, []byte(variant5), marshaled) + assertJsonEqual(t, []byte(variant5), marshaled) } func TestOneOfWithFixedProperties(t *testing.T) { @@ -178,13 +178,13 @@ func TestOneOfWithFixedProperties(t *testing.T) { assert.NoError(t, err) marshaled, err := json.Marshal(dst) assert.NoError(t, err) - assertJSONEqual(t, []byte(variant1), marshaled) + assertJsonEqual(t, []byte(variant1), marshaled) err = dst.FromOneOfVariant6(OneOfVariant6{[]int{1, 2, 3}}) assert.NoError(t, err) marshaled, err = json.Marshal(dst) assert.NoError(t, err) - assertJSONEqual(t, []byte(variant6), marshaled) + assertJsonEqual(t, []byte(variant6), marshaled) } func TestAnyOf(t *testing.T) { diff --git a/internal/test/issues/issue-312/issue_test.go b/internal/test/issues/issue-312/issue_test.go index 2036ed14f..23a14649d 100644 --- a/internal/test/issues/issue-312/issue_test.go +++ b/internal/test/issues/issue-312/issue_test.go @@ -112,9 +112,9 @@ type MockClient struct { validatePets func(ctx echo.Context) error } -func (m *MockClient) GetPet(ctx echo.Context, petID string) error { +func (m *MockClient) GetPet(ctx echo.Context, petId string) error { if m.getPet != nil { - return m.getPet(ctx, petID) + return m.getPet(ctx, petId) } return ctx.NoContent(http.StatusNotImplemented) } diff --git a/internal/test/strict-server/strict_test.go b/internal/test/strict-server/strict_test.go index 4526692bf..76f236730 100644 --- a/internal/test/strict-server/strict_test.go +++ b/internal/test/strict-server/strict_test.go @@ -11,7 +11,7 @@ import ( "strings" "testing" - api "github.com/deepmap/oapi-codegen/internal/test/strict-server/chi" + "github.com/deepmap/oapi-codegen/internal/test/strict-server/chi" api3 "github.com/deepmap/oapi-codegen/internal/test/strict-server/client" api4 "github.com/deepmap/oapi-codegen/internal/test/strict-server/echo" api2 "github.com/deepmap/oapi-codegen/internal/test/strict-server/gin" @@ -52,7 +52,7 @@ func testImpl(t *testing.T, handler http.Handler) { t.Run("JSONExample", func(t *testing.T) { value := "123" requestBody := api3.Example{Value: &value} - rr := testutil.NewRequest().Post("/json").WithJSONBody(requestBody).GoWithHTTPHandler(t, handler).Recorder + rr := testutil.NewRequest().Post("/json").WithJsonBody(requestBody).GoWithHTTPHandler(t, handler).Recorder assert.Equal(t, http.StatusOK, rr.Code) assert.True(t, strings.HasPrefix(rr.Header().Get("Content-Type"), "application/json")) var responseBody api3.Example @@ -116,7 +116,7 @@ func testImpl(t *testing.T, handler http.Handler) { t.Run("MultipleRequestAndResponseTypesJSON", func(t *testing.T) { value := "123" requestBody := api3.Example{Value: &value} - rr := testutil.NewRequest().Post("/multiple").WithJSONBody(requestBody).GoWithHTTPHandler(t, handler).Recorder + rr := testutil.NewRequest().Post("/multiple").WithJsonBody(requestBody).GoWithHTTPHandler(t, handler).Recorder assert.Equal(t, http.StatusOK, rr.Code) assert.True(t, strings.HasPrefix(rr.Header().Get("Content-Type"), "application/json")) var responseBody api3.Example @@ -182,7 +182,7 @@ func testImpl(t *testing.T, handler http.Handler) { header2 := "890" value := "asdf" requestBody := api3.Example{Value: &value} - rr := testutil.NewRequest().Post("/with-headers").WithHeader("header1", header1).WithHeader("header2", header2).WithJSONBody(requestBody).GoWithHTTPHandler(t, handler).Recorder + rr := testutil.NewRequest().Post("/with-headers").WithHeader("header1", header1).WithHeader("header2", header2).WithJsonBody(requestBody).GoWithHTTPHandler(t, handler).Recorder assert.Equal(t, http.StatusOK, rr.Code) assert.True(t, strings.HasPrefix(rr.Header().Get("Content-Type"), "application/json")) var responseBody api3.Example @@ -203,7 +203,7 @@ func testImpl(t *testing.T, handler http.Handler) { t.Run("ReusableResponses", func(t *testing.T) { value := "jkl;" requestBody := api3.Example{Value: &value} - rr := testutil.NewRequest().Post("/reusable-responses").WithJSONBody(requestBody).GoWithHTTPHandler(t, handler).Recorder + rr := testutil.NewRequest().Post("/reusable-responses").WithJsonBody(requestBody).GoWithHTTPHandler(t, handler).Recorder assert.Equal(t, http.StatusOK, rr.Code) assert.True(t, strings.HasPrefix(rr.Header().Get("Content-Type"), "application/json")) var responseBody api3.Example diff --git a/pkg/chi-middleware/oapi_validate_test.go b/pkg/chi-middleware/oapi_validate_test.go index 3445a1f3b..d10df5cbc 100644 --- a/pkg/chi-middleware/oapi_validate_test.go +++ b/pkg/chi-middleware/oapi_validate_test.go @@ -27,7 +27,7 @@ func doGet(t *testing.T, mux *chi.Mux, rawURL string) *httptest.ResponseRecorder t.Fatalf("Invalid url: %s", rawURL) } - response := testutil.NewRequest().Get(u.RequestURI()).WithHost(u.Host).WithAcceptJSON().GoWithHTTPHandler(t, mux) + response := testutil.NewRequest().Get(u.RequestURI()).WithHost(u.Host).WithAcceptJson().GoWithHTTPHandler(t, mux) return response.Recorder } @@ -37,7 +37,7 @@ func doPost(t *testing.T, mux *chi.Mux, rawURL string, jsonBody interface{}) *ht t.Fatalf("Invalid url: %s", rawURL) } - response := testutil.NewRequest().Post(u.RequestURI()).WithHost(u.Host).WithJSONBody(jsonBody).GoWithHTTPHandler(t, mux) + response := testutil.NewRequest().Post(u.RequestURI()).WithHost(u.Host).WithJsonBody(jsonBody).GoWithHTTPHandler(t, mux) return response.Recorder } diff --git a/pkg/gin-middleware/oapi_validate_test.go b/pkg/gin-middleware/oapi_validate_test.go index 76c865110..30ad57fc2 100644 --- a/pkg/gin-middleware/oapi_validate_test.go +++ b/pkg/gin-middleware/oapi_validate_test.go @@ -42,7 +42,7 @@ func doGet(t *testing.T, handler http.Handler, rawURL string) *httptest.Response t.Fatalf("Invalid url: %s", rawURL) } - response := testutil.NewRequest().Get(u.RequestURI()).WithHost(u.Host).WithAcceptJSON().GoWithHTTPHandler(t, handler) + response := testutil.NewRequest().Get(u.RequestURI()).WithHost(u.Host).WithAcceptJson().GoWithHTTPHandler(t, handler) return response.Recorder } @@ -52,7 +52,7 @@ func doPost(t *testing.T, handler http.Handler, rawURL string, jsonBody interfac t.Fatalf("Invalid url: %s", rawURL) } - response := testutil.NewRequest().Post(u.RequestURI()).WithHost(u.Host).WithJSONBody(jsonBody).GoWithHTTPHandler(t, handler) + response := testutil.NewRequest().Post(u.RequestURI()).WithHost(u.Host).WithJsonBody(jsonBody).GoWithHTTPHandler(t, handler) return response.Recorder } diff --git a/pkg/middleware/oapi_validate_test.go b/pkg/middleware/oapi_validate_test.go index e21fdddc3..8eb53094a 100644 --- a/pkg/middleware/oapi_validate_test.go +++ b/pkg/middleware/oapi_validate_test.go @@ -42,7 +42,7 @@ func doGet(t *testing.T, e *echo.Echo, rawURL string) *httptest.ResponseRecorder t.Fatalf("Invalid url: %s", rawURL) } - response := testutil.NewRequest().Get(u.RequestURI()).WithHost(u.Host).WithAcceptJSON().GoWithHTTPHandler(t, e) + response := testutil.NewRequest().Get(u.RequestURI()).WithHost(u.Host).WithAcceptJson().GoWithHTTPHandler(t, e) return response.Recorder } @@ -52,7 +52,7 @@ func doPost(t *testing.T, e *echo.Echo, rawURL string, jsonBody interface{}) *ht t.Fatalf("Invalid url: %s", rawURL) } - response := testutil.NewRequest().Post(u.RequestURI()).WithHost(u.Host).WithJSONBody(jsonBody).GoWithHTTPHandler(t, e) + response := testutil.NewRequest().Post(u.RequestURI()).WithHost(u.Host).WithJsonBody(jsonBody).GoWithHTTPHandler(t, e) return response.Recorder } diff --git a/pkg/testutil/request_helpers.go b/pkg/testutil/request_helpers.go index 633da5922..e0f8c08d2 100644 --- a/pkg/testutil/request_helpers.go +++ b/pkg/testutil/request_helpers.go @@ -98,7 +98,7 @@ func (r *RequestBuilder) WithContentType(value string) *RequestBuilder { return r.WithHeader("Content-Type", value) } -func (r *RequestBuilder) WithJSONContentType() *RequestBuilder { +func (r *RequestBuilder) WithJsonContentType() *RequestBuilder { return r.WithContentType("application/json") } @@ -106,7 +106,7 @@ func (r *RequestBuilder) WithAccept(value string) *RequestBuilder { return r.WithHeader("Accept", value) } -func (r *RequestBuilder) WithAcceptJSON() *RequestBuilder { +func (r *RequestBuilder) WithAcceptJson() *RequestBuilder { return r.WithAccept("application/json") } @@ -117,15 +117,15 @@ func (r *RequestBuilder) WithBody(body []byte) *RequestBuilder { return r } -// WithJSONBody takes an object as input, marshals it to JSON, and sends it +// WithJsonBody takes an object as input, marshals it to JSON, and sends it // as the body with Content-Type: application/json -func (r *RequestBuilder) WithJSONBody(obj interface{}) *RequestBuilder { +func (r *RequestBuilder) WithJsonBody(obj interface{}) *RequestBuilder { var err error r.Body, err = json.Marshal(obj) if err != nil { r.Error = fmt.Errorf("failed to marshal json object: %s", err) } - return r.WithJSONContentType() + return r.WithJsonContentType() } // WithCookie sets a cookie @@ -206,9 +206,9 @@ func (c *CompletedRequest) UnmarshalBodyToObject(obj interface{}) error { return handler(ctype, c.Recorder.Body, obj, c.Strict) } -// UnmarshalJSONToObject assumes that the response contains JSON and unmarshals it +// UnmarshalJsonToObject assumes that the response contains JSON and unmarshals it // into the specified object. -func (c *CompletedRequest) UnmarshalJSONToObject(obj interface{}) error { +func (c *CompletedRequest) UnmarshalJsonToObject(obj interface{}) error { return json.Unmarshal(c.Recorder.Body.Bytes(), obj) }