Skip to content

Commit

Permalink
feat(api): OpenAPI spec update via Stainless API (#2031)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed May 15, 2024
1 parent d91654b commit 8811cb4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 1286
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-5a44a591dcd3f86f8878df473e944d1aa38570cfd6fe4d3b0d2129daa5d94fb0.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-99bd90b0a0f2472ad98f07bb87bf426278428a9891436afd8b355c8f57df5122.yml
3 changes: 2 additions & 1 deletion internal/requestconfig/requestconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@ func (cfg *RequestConfig) Execute() (err error) {
}

// If we are not json, return plaintext
isJSON := strings.Contains(res.Header.Get("content-type"), "application/json")
contentType := res.Header.Get("content-type")
isJSON := strings.Contains(contentType, "application/json") || strings.Contains(contentType, "application/vnd.api+json")
if !isJSON {
switch dst := cfg.ResponseBodyInto.(type) {
case *string:
Expand Down
40 changes: 34 additions & 6 deletions vectorize/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
package vectorize

import (
"bytes"
"context"
"fmt"
"io"
"mime/multipart"
"net/http"
"reflect"

"github.com/cloudflare/cloudflare-go/v2/internal/apiform"
"github.com/cloudflare/cloudflare-go/v2/internal/apijson"
"github.com/cloudflare/cloudflare-go/v2/internal/pagination"
"github.com/cloudflare/cloudflare-go/v2/internal/param"
Expand Down Expand Up @@ -825,11 +829,23 @@ func (r IndexGetByIDsResponseEnvelopeSuccess) IsKnown() bool {
type IndexInsertParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
Body interface{} `json:"body,required"`
// ndjson file containing vectors to insert.
Body io.Reader `json:"body,required" format:"binary"`
}

func (r IndexInsertParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r.Body)
func (r IndexInsertParams) MarshalMultipart() (data []byte, contentType string, err error) {
buf := bytes.NewBuffer(nil)
writer := multipart.NewWriter(buf)
err = apiform.MarshalRoot(r, writer)
if err != nil {
writer.Close()
return nil, "", err
}
err = writer.Close()
if err != nil {
return nil, "", err
}
return buf.Bytes(), writer.FormDataContentType(), nil
}

type IndexInsertResponseEnvelope struct {
Expand Down Expand Up @@ -940,11 +956,23 @@ func (r IndexQueryResponseEnvelopeSuccess) IsKnown() bool {
type IndexUpsertParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
Body interface{} `json:"body,required"`
// ndjson file containing vectors to upsert.
Body io.Reader `json:"body,required" format:"binary"`
}

func (r IndexUpsertParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r.Body)
func (r IndexUpsertParams) MarshalMultipart() (data []byte, contentType string, err error) {
buf := bytes.NewBuffer(nil)
writer := multipart.NewWriter(buf)
err = apiform.MarshalRoot(r, writer)
if err != nil {
writer.Close()
return nil, "", err
}
err = writer.Close()
if err != nil {
return nil, "", err
}
return buf.Bytes(), writer.FormDataContentType(), nil
}

type IndexUpsertResponseEnvelope struct {
Expand Down
6 changes: 4 additions & 2 deletions vectorize/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
package vectorize_test

import (
"bytes"
"context"
"errors"
"io"
"os"
"testing"

Expand Down Expand Up @@ -237,7 +239,7 @@ func TestIndexInsert(t *testing.T) {
"example-index",
vectorize.IndexInsertParams{
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
Body: map[string]interface{}{},
Body: io.Reader(bytes.NewBuffer([]byte("some file contents"))),
},
)
if err != nil {
Expand Down Expand Up @@ -307,7 +309,7 @@ func TestIndexUpsert(t *testing.T) {
"example-index",
vectorize.IndexUpsertParams{
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
Body: map[string]interface{}{},
Body: io.Reader(bytes.NewBuffer([]byte("some file contents"))),
},
)
if err != nil {
Expand Down

0 comments on commit 8811cb4

Please sign in to comment.