Skip to content

fix: return 201 Created for CreateVariable API responses #34517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions routers/api/v1/org/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,11 @@ func (Action) CreateVariable(ctx *context.APIContext) {
// "$ref": "#/definitions/CreateVariableOption"
// responses:
// "201":
// description: response when creating an org-level variable
// "204":
// description: response when creating an org-level variable
// description: response when creating a repo-level variable
// "400":
// "$ref": "#/responses/error"
// "404":
// "$ref": "#/responses/notFound"
// "409":
// description: variable name already exists.

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

Expand Down Expand Up @@ -419,7 +417,7 @@ func (Action) CreateVariable(ctx *context.APIContext) {
return
}

ctx.Status(http.StatusNoContent)
ctx.Status(http.StatusCreated)
}

// UpdateVariable update an org-level variable
Expand Down
8 changes: 3 additions & 5 deletions routers/api/v1/repo/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,10 @@ func (Action) CreateVariable(ctx *context.APIContext) {
// responses:
// "201":
// description: response when creating a repo-level variable
// "204":
// description: response when creating a repo-level variable
// "400":
// "$ref": "#/responses/error"
// "404":
// "$ref": "#/responses/notFound"
// "409":
// description: variable name already exists.

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

Expand Down Expand Up @@ -373,7 +371,7 @@ func (Action) CreateVariable(ctx *context.APIContext) {
return
}

ctx.Status(http.StatusNoContent)
ctx.Status(http.StatusCreated)
}

// UpdateVariable update a repo-level variable
Expand Down
10 changes: 4 additions & 6 deletions routers/api/v1/user/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,11 @@ func CreateVariable(ctx *context.APIContext) {
// "$ref": "#/definitions/CreateVariableOption"
// responses:
// "201":
// description: response when creating a variable
// "204":
// description: response when creating a variable
// description: response when creating a repo-level variable
// "400":
// "$ref": "#/responses/error"
// "404":
// "$ref": "#/responses/notFound"
// "409":
// description: variable name already exists.

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

Expand Down Expand Up @@ -162,7 +160,7 @@ func CreateVariable(ctx *context.APIContext) {
return
}

ctx.Status(http.StatusNoContent)
ctx.Status(http.StatusCreated)
}

// UpdateVariable update a user-level variable which is created by current doer
Expand Down
25 changes: 8 additions & 17 deletions templates/swagger/v1_json.tmpl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions tests/integration/api_repo_variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ func TestAPIRepoVariables(t *testing.T) {
},
{
Name: "_",
ExpectedStatus: http.StatusNoContent,
ExpectedStatus: http.StatusCreated,
},
{
Name: "TEST_VAR",
ExpectedStatus: http.StatusNoContent,
ExpectedStatus: http.StatusCreated,
},
{
Name: "test_var",
Expand Down Expand Up @@ -81,7 +81,7 @@ func TestAPIRepoVariables(t *testing.T) {
req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{
Value: "initial_val",
}).AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent)
MakeRequest(t, req, http.StatusCreated)

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

req = NewRequest(t, "DELETE", url).AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent)
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/api_user_variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ func TestAPIUserVariables(t *testing.T) {
},
{
Name: "_",
ExpectedStatus: http.StatusNoContent,
ExpectedStatus: http.StatusCreated,
},
{
Name: "TEST_VAR",
ExpectedStatus: http.StatusNoContent,
ExpectedStatus: http.StatusCreated,
},
{
Name: "test_var",
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestAPIUserVariables(t *testing.T) {
req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{
Value: "initial_val",
}).AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent)
MakeRequest(t, req, http.StatusCreated)

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

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