Skip to content

Commit b09f939

Browse files
chore(closes OPEN-8576): expose delete project endpoint
1 parent 9c2403a commit b09f939

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
configured_endpoints: 25
2-
openapi_spec_hash: 4eff18b3478c98a9b257ac27fdeb6b49
3-
config_hash: b415187e3925c414fb2597cdd0a11859
1+
configured_endpoints: 26
2+
openapi_spec_hash: 6f6cb98b7755d18274dd51e857508336
3+
config_hash: cc9a32249c08143687799eb8de187d6a

api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Methods:
99

1010
- <code title="post /projects">client.Projects.<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go#ProjectService.New">New</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go">openlayer</a>.<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go#ProjectNewParams">ProjectNewParams</a>) (<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go">openlayer</a>.<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go#ProjectNewResponse">ProjectNewResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
1111
- <code title="get /projects">client.Projects.<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go#ProjectService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, query <a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go">openlayer</a>.<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go#ProjectListParams">ProjectListParams</a>) (<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go">openlayer</a>.<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go#ProjectListResponse">ProjectListResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
12+
- <code title="delete /projects/{projectId}">client.Projects.<a href="https://pkg.go.dev/github.com/openlayer-ai/openlayer-go#ProjectService.Delete">Delete</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, projectID <a href="https://pkg.go.dev/builtin#string">string</a>) <a href="https://pkg.go.dev/builtin#error">error</a></code>
1213

1314
## Commits
1415

project.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ package openlayer
44

55
import (
66
"context"
7+
"errors"
8+
"fmt"
79
"net/http"
810
"net/url"
911
"slices"
@@ -57,6 +59,19 @@ func (r *ProjectService) List(ctx context.Context, query ProjectListParams, opts
5759
return
5860
}
5961

62+
// Delete a project by its ID.
63+
func (r *ProjectService) Delete(ctx context.Context, projectID string, opts ...option.RequestOption) (err error) {
64+
opts = slices.Concat(r.Options, opts)
65+
opts = append([]option.RequestOption{option.WithHeader("Accept", "*/*")}, opts...)
66+
if projectID == "" {
67+
err = errors.New("missing required projectId parameter")
68+
return
69+
}
70+
path := fmt.Sprintf("projects/%s", projectID)
71+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, nil, opts...)
72+
return
73+
}
74+
6075
type ProjectNewResponse struct {
6176
// The project id.
6277
ID string `json:"id,required" format:"uuid"`

project_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,25 @@ func TestProjectListWithOptionalParams(t *testing.T) {
6565
t.Fatalf("err should be nil: %s", err.Error())
6666
}
6767
}
68+
69+
func TestProjectDelete(t *testing.T) {
70+
baseURL := "http://localhost:4010"
71+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
72+
baseURL = envURL
73+
}
74+
if !testutil.CheckTestServer(t, baseURL) {
75+
return
76+
}
77+
client := openlayer.NewClient(
78+
option.WithBaseURL(baseURL),
79+
option.WithAPIKey("My API Key"),
80+
)
81+
err := client.Projects.Delete(context.TODO(), "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
82+
if err != nil {
83+
var apierr *openlayer.Error
84+
if errors.As(err, &apierr) {
85+
t.Log(string(apierr.DumpRequest(true)))
86+
}
87+
t.Fatalf("err should be nil: %s", err.Error())
88+
}
89+
}

0 commit comments

Comments
 (0)