Skip to content
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

feat(api): OpenAPI spec update via Stainless API #1690

Merged
merged 1 commit into from
Apr 8, 2024
Merged
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
53 changes: 13 additions & 40 deletions images/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewV1Service(opts ...option.RequestOption) (r *V1Service) {
func (r *V1Service) New(ctx context.Context, params V1NewParams, opts ...option.RequestOption) (res *Image, err error) {
opts = append(r.Options[:], opts...)
var env V1NewResponseEnvelope
path := fmt.Sprintf("accounts/%s/images/v1", params.getAccountID())
path := fmt.Sprintf("accounts/%s/images/v1", params.AccountID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &env, opts...)
if err != nil {
return
Expand Down Expand Up @@ -254,52 +254,25 @@ func (r V1ListResponseSuccess) IsKnown() bool {
return false
}

// This interface is a union satisfied by one of the following:
// [V1NewParamsImagesImageUploadViaFile], [V1NewParamsImagesImageUploadViaURL].
type V1NewParams interface {
ImplementsV1NewParams()

getAccountID() param.Field[string]
}

type V1NewParamsImagesImageUploadViaFile struct {
type V1NewParams struct {
// Account identifier tag.
AccountID param.Field[string] `path:"account_id,required"`
// An image binary data.
File param.Field[interface{}] `json:"file,required"`
}

func (r V1NewParamsImagesImageUploadViaFile) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

func (r V1NewParamsImagesImageUploadViaFile) getAccountID() param.Field[string] {
return r.AccountID
}

func (V1NewParamsImagesImageUploadViaFile) ImplementsV1NewParams() {

}

type V1NewParamsImagesImageUploadViaURL struct {
// Account identifier tag.
AccountID param.Field[string] `path:"account_id,required"`
// A URL to fetch an image from origin.
URL param.Field[string] `json:"url,required"`
// An image binary data. Only needed when type is uploading a file.
File param.Field[interface{}] `json:"file"`
// User modifiable key-value store. Can use used for keeping references to another
// system of record for managing images.
Metadata param.Field[interface{}] `json:"metadata"`
// Indicates whether the image requires a signature token for the access.
RequireSignedURLs param.Field[bool] `json:"requireSignedURLs"`
// A URL to fetch an image from origin. Only needed when type is uploading from a
// URL.
URL param.Field[string] `json:"url"`
}

func (r V1NewParamsImagesImageUploadViaURL) MarshalJSON() (data []byte, err error) {
func (r V1NewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

func (r V1NewParamsImagesImageUploadViaURL) getAccountID() param.Field[string] {
return r.AccountID
}

func (V1NewParamsImagesImageUploadViaURL) ImplementsV1NewParams() {

}

type V1NewResponseEnvelope struct {
Errors []shared.UnnamedSchemaRef3248f24329456e19dfa042fff9986f72 `json:"errors,required"`
Messages []shared.UnnamedSchemaRef3248f24329456e19dfa042fff9986f72 `json:"messages,required"`
Expand Down
11 changes: 7 additions & 4 deletions images/v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/cloudflare/cloudflare-go/v2/option"
)

func TestV1New(t *testing.T) {
func TestV1NewWithOptionalParams(t *testing.T) {
t.Skip("skipped: tests are disabled for the time being")
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
Expand All @@ -28,9 +28,12 @@ func TestV1New(t *testing.T) {
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("[email protected]"),
)
_, err := client.Images.V1.New(context.TODO(), images.V1NewParamsImagesImageUploadViaFile{
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
File: cloudflare.F[any](map[string]interface{}{}),
_, err := client.Images.V1.New(context.TODO(), images.V1NewParams{
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
File: cloudflare.F[any](map[string]interface{}{}),
Metadata: cloudflare.F[any](map[string]interface{}{}),
RequireSignedURLs: cloudflare.F(true),
URL: cloudflare.F("https://example.com/path/to/logo.png"),
})
if err != nil {
var apierr *cloudflare.Error
Expand Down