0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-06-06 12:03:00 +02:00

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 <appleboy.tw@gmail.com>
Signed-off-by: appleboy <appleboy.tw@gmail.com>
Co-authored-by: delvh <dev.lh@web.de>
This commit is contained in:
Bo-Yi Wu 2025-05-27 00:12:49 +08:00 committed by GitHub
parent 9b295e984a
commit 11ee7ff3bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 37 additions and 42 deletions

View File

@ -384,13 +384,13 @@ func (Action) CreateVariable(ctx *context.APIContext) {
// "$ref": "#/definitions/CreateVariableOption" // "$ref": "#/definitions/CreateVariableOption"
// responses: // responses:
// "201": // "201":
// description: response when creating an org-level variable // description: successfully created the org-level variable
// "204":
// description: response when creating an org-level variable
// "400": // "400":
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
// "404": // "409":
// "$ref": "#/responses/notFound" // description: variable name already exists.
// "500":
// "$ref": "#/responses/error"
opt := web.GetForm(ctx).(*api.CreateVariableOption) opt := web.GetForm(ctx).(*api.CreateVariableOption)
@ -419,7 +419,7 @@ func (Action) CreateVariable(ctx *context.APIContext) {
return return
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusCreated)
} }
// UpdateVariable update an org-level variable // UpdateVariable update an org-level variable

View File

@ -339,12 +339,12 @@ func (Action) CreateVariable(ctx *context.APIContext) {
// responses: // responses:
// "201": // "201":
// description: response when creating a repo-level variable // description: response when creating a repo-level variable
// "204":
// description: response when creating a repo-level variable
// "400": // "400":
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
// "404": // "409":
// "$ref": "#/responses/notFound" // description: variable name already exists.
// "500":
// "$ref": "#/responses/error"
opt := web.GetForm(ctx).(*api.CreateVariableOption) opt := web.GetForm(ctx).(*api.CreateVariableOption)
@ -373,7 +373,7 @@ func (Action) CreateVariable(ctx *context.APIContext) {
return return
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusCreated)
} }
// UpdateVariable update a repo-level variable // UpdateVariable update a repo-level variable

View File

@ -127,13 +127,11 @@ func CreateVariable(ctx *context.APIContext) {
// "$ref": "#/definitions/CreateVariableOption" // "$ref": "#/definitions/CreateVariableOption"
// responses: // responses:
// "201": // "201":
// description: response when creating a variable // description: successfully created the user-level variable
// "204":
// description: response when creating a variable
// "400": // "400":
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
// "404": // "409":
// "$ref": "#/responses/notFound" // description: variable name already exists.
opt := web.GetForm(ctx).(*api.CreateVariableOption) opt := web.GetForm(ctx).(*api.CreateVariableOption)
@ -162,7 +160,7 @@ func CreateVariable(ctx *context.APIContext) {
return return
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusCreated)
} }
// UpdateVariable update a user-level variable which is created by current doer // UpdateVariable update a user-level variable which is created by current doer

View File

@ -2259,16 +2259,16 @@
], ],
"responses": { "responses": {
"201": { "201": {
"description": "response when creating an org-level variable" "description": "successfully created the org-level variable"
},
"204": {
"description": "response when creating an org-level variable"
}, },
"400": { "400": {
"$ref": "#/responses/error" "$ref": "#/responses/error"
}, },
"404": { "409": {
"$ref": "#/responses/notFound" "description": "variable name already exists."
},
"500": {
"$ref": "#/responses/error"
} }
} }
}, },
@ -5263,14 +5263,14 @@
"201": { "201": {
"description": "response when creating a repo-level variable" "description": "response when creating a repo-level variable"
}, },
"204": {
"description": "response when creating a repo-level variable"
},
"400": { "400": {
"$ref": "#/responses/error" "$ref": "#/responses/error"
}, },
"404": { "409": {
"$ref": "#/responses/notFound" "description": "variable name already exists."
},
"500": {
"$ref": "#/responses/error"
} }
} }
}, },
@ -17863,16 +17863,13 @@
], ],
"responses": { "responses": {
"201": { "201": {
"description": "response when creating a variable" "description": "successfully created the user-level variable"
},
"204": {
"description": "response when creating a variable"
}, },
"400": { "400": {
"$ref": "#/responses/error" "$ref": "#/responses/error"
}, },
"404": { "409": {
"$ref": "#/responses/notFound" "description": "variable name already exists."
} }
} }
}, },

View File

@ -35,11 +35,11 @@ func TestAPIRepoVariables(t *testing.T) {
}, },
{ {
Name: "_", Name: "_",
ExpectedStatus: http.StatusNoContent, ExpectedStatus: http.StatusCreated,
}, },
{ {
Name: "TEST_VAR", Name: "TEST_VAR",
ExpectedStatus: http.StatusNoContent, ExpectedStatus: http.StatusCreated,
}, },
{ {
Name: "test_var", Name: "test_var",
@ -81,7 +81,7 @@ func TestAPIRepoVariables(t *testing.T) {
req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{ req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{
Value: "initial_val", Value: "initial_val",
}).AddTokenAuth(token) }).AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusCreated)
cases := []struct { cases := []struct {
Name string Name string
@ -138,7 +138,7 @@ func TestAPIRepoVariables(t *testing.T) {
req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{ req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{
Value: "initial_val", Value: "initial_val",
}).AddTokenAuth(token) }).AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusCreated)
req = NewRequest(t, "DELETE", url).AddTokenAuth(token) req = NewRequest(t, "DELETE", url).AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)

View File

@ -29,11 +29,11 @@ func TestAPIUserVariables(t *testing.T) {
}, },
{ {
Name: "_", Name: "_",
ExpectedStatus: http.StatusNoContent, ExpectedStatus: http.StatusCreated,
}, },
{ {
Name: "TEST_VAR", Name: "TEST_VAR",
ExpectedStatus: http.StatusNoContent, ExpectedStatus: http.StatusCreated,
}, },
{ {
Name: "test_var", Name: "test_var",
@ -75,7 +75,7 @@ func TestAPIUserVariables(t *testing.T) {
req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{ req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{
Value: "initial_val", Value: "initial_val",
}).AddTokenAuth(token) }).AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusCreated)
cases := []struct { cases := []struct {
Name string Name string
@ -132,7 +132,7 @@ func TestAPIUserVariables(t *testing.T) {
req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{ req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{
Value: "initial_val", Value: "initial_val",
}).AddTokenAuth(token) }).AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusCreated)
req = NewRequest(t, "DELETE", url).AddTokenAuth(token) req = NewRequest(t, "DELETE", url).AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)