Skip to content

Commit 00b281c

Browse files
committedJan 30, 2025
feat(api): api update (#3860)
1 parent 106c449 commit 00b281c

File tree

3 files changed

+9
-37
lines changed

3 files changed

+9
-37
lines changed
 

‎.stats.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 1508
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-82a521194000c6d0b051c53d886330d610a9966c8f1f00c1ae82a7889328ff40.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-93781888ccca411928a3826373dfd7531806fd2eb4c35de249b142676f00b56f.yml

‎vectorize/index.go

+6-32
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@
33
package vectorize
44

55
import (
6-
"bytes"
76
"context"
87
"errors"
98
"fmt"
10-
"io"
11-
"mime/multipart"
129
"net/http"
1310
"net/url"
1411
"time"
1512

16-
"github.com/cloudflare/cloudflare-go/v4/internal/apiform"
1713
"github.com/cloudflare/cloudflare-go/v4/internal/apijson"
1814
"github.com/cloudflare/cloudflare-go/v4/internal/apiquery"
1915
"github.com/cloudflare/cloudflare-go/v4/internal/param"
@@ -911,24 +907,13 @@ type IndexInsertParams struct {
911907
// Identifier
912908
AccountID param.Field[string] `path:"account_id,required"`
913909
// ndjson file containing vectors to insert.
914-
Body io.Reader `json:"body,required" format:"binary"`
910+
Body string `json:"body,required"`
915911
// Behavior for ndjson parse failures.
916912
UnparsableBehavior param.Field[IndexInsertParamsUnparsableBehavior] `query:"unparsable-behavior"`
917913
}
918914

919-
func (r IndexInsertParams) MarshalMultipart() (data []byte, contentType string, err error) {
920-
buf := bytes.NewBuffer(nil)
921-
writer := multipart.NewWriter(buf)
922-
err = apiform.MarshalRoot(r, writer)
923-
if err != nil {
924-
writer.Close()
925-
return nil, "", err
926-
}
927-
err = writer.Close()
928-
if err != nil {
929-
return nil, "", err
930-
}
931-
return buf.Bytes(), writer.FormDataContentType(), nil
915+
func (r IndexInsertParams) MarshalJSON() (data []byte, err error) {
916+
return apijson.MarshalRoot(r.Body)
932917
}
933918

934919
// URLQuery serializes [IndexInsertParams]'s query parameters as `url.Values`.
@@ -1083,24 +1068,13 @@ type IndexUpsertParams struct {
10831068
// Identifier
10841069
AccountID param.Field[string] `path:"account_id,required"`
10851070
// ndjson file containing vectors to upsert.
1086-
Body io.Reader `json:"body,required" format:"binary"`
1071+
Body string `json:"body,required"`
10871072
// Behavior for ndjson parse failures.
10881073
UnparsableBehavior param.Field[IndexUpsertParamsUnparsableBehavior] `query:"unparsable-behavior"`
10891074
}
10901075

1091-
func (r IndexUpsertParams) MarshalMultipart() (data []byte, contentType string, err error) {
1092-
buf := bytes.NewBuffer(nil)
1093-
writer := multipart.NewWriter(buf)
1094-
err = apiform.MarshalRoot(r, writer)
1095-
if err != nil {
1096-
writer.Close()
1097-
return nil, "", err
1098-
}
1099-
err = writer.Close()
1100-
if err != nil {
1101-
return nil, "", err
1102-
}
1103-
return buf.Bytes(), writer.FormDataContentType(), nil
1076+
func (r IndexUpsertParams) MarshalJSON() (data []byte, err error) {
1077+
return apijson.MarshalRoot(r.Body)
11041078
}
11051079

11061080
// URLQuery serializes [IndexUpsertParams]'s query parameters as `url.Values`.

‎vectorize/index_test.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
package vectorize_test
44

55
import (
6-
"bytes"
76
"context"
87
"errors"
9-
"io"
108
"os"
119
"testing"
1210

@@ -238,7 +236,7 @@ func TestIndexInsertWithOptionalParams(t *testing.T) {
238236
"example-index",
239237
vectorize.IndexInsertParams{
240238
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
241-
Body: io.Reader(bytes.NewBuffer([]byte("some file contents"))),
239+
Body: "@/path/to/vectors.ndjson",
242240
UnparsableBehavior: cloudflare.F(vectorize.IndexInsertParamsUnparsableBehaviorError),
243241
},
244242
)
@@ -309,7 +307,7 @@ func TestIndexUpsertWithOptionalParams(t *testing.T) {
309307
"example-index",
310308
vectorize.IndexUpsertParams{
311309
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
312-
Body: io.Reader(bytes.NewBuffer([]byte("some file contents"))),
310+
Body: "@/path/to/vectors.ndjson",
313311
UnparsableBehavior: cloudflare.F(vectorize.IndexUpsertParamsUnparsableBehaviorError),
314312
},
315313
)

0 commit comments

Comments
 (0)
Please sign in to comment.