Skip to content

Commit 11ee7ff

Browse files
appleboydelvh
andauthored
fix: return 201 Created for CreateVariable API responses (#34517)
- Change CreateVariable API response status from 204 No Content to 201 Created - Update related integration tests to expect 201 Created instead of 204 No Content ## ⚠️ BREAKING ⚠️ Change the response status code of the Create Variable API under both Org and Repo levels to `201` instead of 204. API SDK: https://gitea.com/gitea/go-sdk/pulls/713 --------- Signed-off-by: Bo-Yi Wu <[email protected]> Signed-off-by: appleboy <[email protected]> Co-authored-by: delvh <[email protected]>
1 parent 9b295e9 commit 11ee7ff

File tree

6 files changed

+37
-42
lines changed

6 files changed

+37
-42
lines changed

routers/api/v1/org/action.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,13 @@ func (Action) CreateVariable(ctx *context.APIContext) {
384384
// "$ref": "#/definitions/CreateVariableOption"
385385
// responses:
386386
// "201":
387-
// description: response when creating an org-level variable
388-
// "204":
389-
// description: response when creating an org-level variable
387+
// description: successfully created the org-level variable
390388
// "400":
391389
// "$ref": "#/responses/error"
392-
// "404":
393-
// "$ref": "#/responses/notFound"
390+
// "409":
391+
// description: variable name already exists.
392+
// "500":
393+
// "$ref": "#/responses/error"
394394

395395
opt := web.GetForm(ctx).(*api.CreateVariableOption)
396396

@@ -419,7 +419,7 @@ func (Action) CreateVariable(ctx *context.APIContext) {
419419
return
420420
}
421421

422-
ctx.Status(http.StatusNoContent)
422+
ctx.Status(http.StatusCreated)
423423
}
424424

425425
// UpdateVariable update an org-level variable

routers/api/v1/repo/action.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,12 @@ func (Action) CreateVariable(ctx *context.APIContext) {
339339
// responses:
340340
// "201":
341341
// description: response when creating a repo-level variable
342-
// "204":
343-
// description: response when creating a repo-level variable
344342
// "400":
345343
// "$ref": "#/responses/error"
346-
// "404":
347-
// "$ref": "#/responses/notFound"
344+
// "409":
345+
// description: variable name already exists.
346+
// "500":
347+
// "$ref": "#/responses/error"
348348

349349
opt := web.GetForm(ctx).(*api.CreateVariableOption)
350350

@@ -373,7 +373,7 @@ func (Action) CreateVariable(ctx *context.APIContext) {
373373
return
374374
}
375375

376-
ctx.Status(http.StatusNoContent)
376+
ctx.Status(http.StatusCreated)
377377
}
378378

379379
// UpdateVariable update a repo-level variable

routers/api/v1/user/action.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,11 @@ func CreateVariable(ctx *context.APIContext) {
127127
// "$ref": "#/definitions/CreateVariableOption"
128128
// responses:
129129
// "201":
130-
// description: response when creating a variable
131-
// "204":
132-
// description: response when creating a variable
130+
// description: successfully created the user-level variable
133131
// "400":
134132
// "$ref": "#/responses/error"
135-
// "404":
136-
// "$ref": "#/responses/notFound"
133+
// "409":
134+
// description: variable name already exists.
137135

138136
opt := web.GetForm(ctx).(*api.CreateVariableOption)
139137

@@ -162,7 +160,7 @@ func CreateVariable(ctx *context.APIContext) {
162160
return
163161
}
164162

165-
ctx.Status(http.StatusNoContent)
163+
ctx.Status(http.StatusCreated)
166164
}
167165

168166
// UpdateVariable update a user-level variable which is created by current doer

templates/swagger/v1_json.tmpl

Lines changed: 14 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/api_repo_variables_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ func TestAPIRepoVariables(t *testing.T) {
3535
},
3636
{
3737
Name: "_",
38-
ExpectedStatus: http.StatusNoContent,
38+
ExpectedStatus: http.StatusCreated,
3939
},
4040
{
4141
Name: "TEST_VAR",
42-
ExpectedStatus: http.StatusNoContent,
42+
ExpectedStatus: http.StatusCreated,
4343
},
4444
{
4545
Name: "test_var",
@@ -81,7 +81,7 @@ func TestAPIRepoVariables(t *testing.T) {
8181
req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{
8282
Value: "initial_val",
8383
}).AddTokenAuth(token)
84-
MakeRequest(t, req, http.StatusNoContent)
84+
MakeRequest(t, req, http.StatusCreated)
8585

8686
cases := []struct {
8787
Name string
@@ -138,7 +138,7 @@ func TestAPIRepoVariables(t *testing.T) {
138138
req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{
139139
Value: "initial_val",
140140
}).AddTokenAuth(token)
141-
MakeRequest(t, req, http.StatusNoContent)
141+
MakeRequest(t, req, http.StatusCreated)
142142

143143
req = NewRequest(t, "DELETE", url).AddTokenAuth(token)
144144
MakeRequest(t, req, http.StatusNoContent)

tests/integration/api_user_variables_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ func TestAPIUserVariables(t *testing.T) {
2929
},
3030
{
3131
Name: "_",
32-
ExpectedStatus: http.StatusNoContent,
32+
ExpectedStatus: http.StatusCreated,
3333
},
3434
{
3535
Name: "TEST_VAR",
36-
ExpectedStatus: http.StatusNoContent,
36+
ExpectedStatus: http.StatusCreated,
3737
},
3838
{
3939
Name: "test_var",
@@ -75,7 +75,7 @@ func TestAPIUserVariables(t *testing.T) {
7575
req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{
7676
Value: "initial_val",
7777
}).AddTokenAuth(token)
78-
MakeRequest(t, req, http.StatusNoContent)
78+
MakeRequest(t, req, http.StatusCreated)
7979

8080
cases := []struct {
8181
Name string
@@ -132,7 +132,7 @@ func TestAPIUserVariables(t *testing.T) {
132132
req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{
133133
Value: "initial_val",
134134
}).AddTokenAuth(token)
135-
MakeRequest(t, req, http.StatusNoContent)
135+
MakeRequest(t, req, http.StatusCreated)
136136

137137
req = NewRequest(t, "DELETE", url).AddTokenAuth(token)
138138
MakeRequest(t, req, http.StatusNoContent)

0 commit comments

Comments
 (0)