From 3ac9bf65c680b0281423ea4ac79e2bddd1994dfe Mon Sep 17 00:00:00 2001 From: Ivy Wong <57681886+iwong-isp@users.noreply.github.com> Date: Wed, 21 Sep 2022 14:43:24 -0700 Subject: [PATCH] fix: auto-mark patch deprecated --- patch.go | 3 ++- patch_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/patch.go b/patch.go index e8c88be3..35b41407 100644 --- a/patch.go +++ b/patch.go @@ -168,7 +168,8 @@ func generatePatch(resource *Resource, get *Operation, put *Operation) { model: jsonPatchType, }, }, - responses: responses, + responses: responses, + deprecated: put.deprecated, }) // Manually register the handler with the router. This bypasses the normal diff --git a/patch_test.go b/patch_test.go index c7c3edc6..73ff60e5 100644 --- a/patch_test.go +++ b/patch_test.go @@ -200,3 +200,30 @@ func TestPatchPutNoBody(t *testing.T) { app.ServeHTTP(w, req) assert.Equal(t, http.StatusMethodNotAllowed, w.Code, w.Body.String()) } + +func TestDeprecatedPatch(t *testing.T) { + app := newTestRouter() + things := app.Resource("/things/{thing-id}") + + things.Get("get-thing", "docs", + NewResponse(http.StatusOK, "OK").Model(&ThingModel{}), + ).Run(func(ctx Context, input struct { + ThingIDParam + }) { + ctx.WriteModel(http.StatusOK, &ThingModel{}) + }) + + put := things.Put("put-thing", "docs", + NewResponse(http.StatusOK, "OK").Model(&ThingModel{}), + ) + put.Deprecated() + put.Run(func(ctx Context, input struct { + ThingIDParam + Body ThingModel + }) { + ctx.WriteModel(http.StatusOK, &ThingModel{}) + }) + + app.setupDocs() + assert.Contains(t, app.OpenAPI().Search("paths", "/things/{thing-id}", "patch").String(), "deprecated") +}