Skip to content

Commit 8b5aea9

Browse files
feat(api): extract UpdateFileDetailsRequest to model
1 parent 3d7c221 commit 8b5aea9

4 files changed

Lines changed: 172 additions & 148 deletions

File tree

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 42
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/imagekit-inc%2Fimagekit-bc7c0d27962b30c19c778656988e154b54696819389289f34420a5e5fdfbd3b8.yml
33
openapi_spec_hash: 1bfde02a63416c036e9545927f727459
4-
config_hash: a652d68098d82eaf611a49507fb4b831
4+
config_hash: b415c06a3b29485af4601beb94ae1aeb

api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Methods:
1818

1919
# Files
2020

21+
Params Types:
22+
23+
- <a href="https://pkg.go.dev/github.com/imagekit-developer/imagekit-go">imagekit</a>.<a href="https://pkg.go.dev/github.com/imagekit-developer/imagekit-go#UpdateFileDetailsRequestUnionParam">UpdateFileDetailsRequestUnionParam</a>
24+
2125
Response Types:
2226

2327
- <a href="https://pkg.go.dev/github.com/imagekit-developer/imagekit-go">imagekit</a>.<a href="https://pkg.go.dev/github.com/imagekit-developer/imagekit-go#File">File</a>

file.go

Lines changed: 132 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package imagekit
55
import (
66
"bytes"
77
"context"
8+
"encoding/json"
89
"errors"
910
"fmt"
1011
"io"
@@ -14,6 +15,7 @@ import (
1415

1516
"github.com/imagekit-developer/imagekit-go/internal/apiform"
1617
"github.com/imagekit-developer/imagekit-go/internal/apijson"
18+
shimjson "github.com/imagekit-developer/imagekit-go/internal/encoding/json"
1719
"github.com/imagekit-developer/imagekit-go/internal/requestconfig"
1820
"github.com/imagekit-developer/imagekit-go/option"
1921
"github.com/imagekit-developer/imagekit-go/packages/param"
@@ -605,6 +607,132 @@ func (r *MetadataExifThumbnail) UnmarshalJSON(data []byte) error {
605607
return apijson.UnmarshalRoot(data, r)
606608
}
607609

610+
// Only one field can be non-zero.
611+
//
612+
// Use [param.IsOmitted] to confirm if a field is set.
613+
type UpdateFileDetailsRequestUnionParam struct {
614+
OfUpdateFileDetails *UpdateFileDetailsRequestUpdateFileDetailsParam `json:",omitzero,inline"`
615+
OfChangePublicationStatus *UpdateFileDetailsRequestChangePublicationStatusParam `json:",omitzero,inline"`
616+
paramUnion
617+
}
618+
619+
func (u UpdateFileDetailsRequestUnionParam) MarshalJSON() ([]byte, error) {
620+
return param.MarshalUnion(u, u.OfUpdateFileDetails, u.OfChangePublicationStatus)
621+
}
622+
func (u *UpdateFileDetailsRequestUnionParam) UnmarshalJSON(data []byte) error {
623+
return apijson.UnmarshalRoot(data, u)
624+
}
625+
626+
func (u *UpdateFileDetailsRequestUnionParam) asAny() any {
627+
if !param.IsOmitted(u.OfUpdateFileDetails) {
628+
return u.OfUpdateFileDetails
629+
} else if !param.IsOmitted(u.OfChangePublicationStatus) {
630+
return u.OfChangePublicationStatus
631+
}
632+
return nil
633+
}
634+
635+
type UpdateFileDetailsRequestUpdateFileDetailsParam struct {
636+
// Define an important area in the image in the format `x,y,width,height` e.g.
637+
// `10,10,100,100`. Send `null` to unset this value.
638+
CustomCoordinates param.Opt[string] `json:"customCoordinates,omitzero"`
639+
// Optional text to describe the contents of the file.
640+
Description param.Opt[string] `json:"description,omitzero"`
641+
// The final status of extensions after they have completed execution will be
642+
// delivered to this endpoint as a POST request.
643+
// [Learn more](/docs/api-reference/digital-asset-management-dam/managing-assets/update-file-details#webhook-payload-structure)
644+
// about the webhook payload structure.
645+
WebhookURL param.Opt[string] `json:"webhookUrl,omitzero" format:"uri"`
646+
// An array of tags associated with the file, such as `["tag1", "tag2"]`. Send
647+
// `null` to unset all tags associated with the file.
648+
Tags []string `json:"tags,omitzero"`
649+
// A key-value data to be associated with the asset. To unset a key, send `null`
650+
// value for that key. Before setting any custom metadata on an asset you have to
651+
// create the field using custom metadata fields API.
652+
CustomMetadata map[string]any `json:"customMetadata,omitzero"`
653+
// Array of extensions to be applied to the asset. Each extension can be configured
654+
// with specific parameters based on the extension type.
655+
Extensions shared.ExtensionsParam `json:"extensions,omitzero"`
656+
// An array of AITags associated with the file that you want to remove, e.g.
657+
// `["car", "vehicle", "motorsports"]`.
658+
//
659+
// If you want to remove all AITags associated with the file, send a string -
660+
// "all".
661+
//
662+
// Note: The remove operation for `AITags` executes before any of the `extensions`
663+
// are processed.
664+
RemoveAITags UpdateFileDetailsRequestUpdateFileDetailsRemoveAITagsUnionParam `json:"removeAITags,omitzero"`
665+
paramObj
666+
}
667+
668+
func (r UpdateFileDetailsRequestUpdateFileDetailsParam) MarshalJSON() (data []byte, err error) {
669+
type shadow UpdateFileDetailsRequestUpdateFileDetailsParam
670+
return param.MarshalObject(r, (*shadow)(&r))
671+
}
672+
func (r *UpdateFileDetailsRequestUpdateFileDetailsParam) UnmarshalJSON(data []byte) error {
673+
return apijson.UnmarshalRoot(data, r)
674+
}
675+
676+
// Only one field can be non-zero.
677+
//
678+
// Use [param.IsOmitted] to confirm if a field is set.
679+
type UpdateFileDetailsRequestUpdateFileDetailsRemoveAITagsUnionParam struct {
680+
OfStringArray []string `json:",omitzero,inline"`
681+
// Construct this variant with constant.ValueOf[constant.All]()
682+
OfAll constant.All `json:",omitzero,inline"`
683+
paramUnion
684+
}
685+
686+
func (u UpdateFileDetailsRequestUpdateFileDetailsRemoveAITagsUnionParam) MarshalJSON() ([]byte, error) {
687+
return param.MarshalUnion(u, u.OfStringArray, u.OfAll)
688+
}
689+
func (u *UpdateFileDetailsRequestUpdateFileDetailsRemoveAITagsUnionParam) UnmarshalJSON(data []byte) error {
690+
return apijson.UnmarshalRoot(data, u)
691+
}
692+
693+
func (u *UpdateFileDetailsRequestUpdateFileDetailsRemoveAITagsUnionParam) asAny() any {
694+
if !param.IsOmitted(u.OfStringArray) {
695+
return &u.OfStringArray
696+
} else if !param.IsOmitted(u.OfAll) {
697+
return &u.OfAll
698+
}
699+
return nil
700+
}
701+
702+
type UpdateFileDetailsRequestChangePublicationStatusParam struct {
703+
// Configure the publication status of a file and its versions.
704+
Publish UpdateFileDetailsRequestChangePublicationStatusPublishParam `json:"publish,omitzero"`
705+
paramObj
706+
}
707+
708+
func (r UpdateFileDetailsRequestChangePublicationStatusParam) MarshalJSON() (data []byte, err error) {
709+
type shadow UpdateFileDetailsRequestChangePublicationStatusParam
710+
return param.MarshalObject(r, (*shadow)(&r))
711+
}
712+
func (r *UpdateFileDetailsRequestChangePublicationStatusParam) UnmarshalJSON(data []byte) error {
713+
return apijson.UnmarshalRoot(data, r)
714+
}
715+
716+
// Configure the publication status of a file and its versions.
717+
//
718+
// The property IsPublished is required.
719+
type UpdateFileDetailsRequestChangePublicationStatusPublishParam struct {
720+
// Set to `true` to publish the file. Set to `false` to unpublish the file.
721+
IsPublished bool `json:"isPublished,required"`
722+
// Set to `true` to publish/unpublish all versions of the file. Set to `false` to
723+
// publish/unpublish only the current version of the file.
724+
IncludeFileVersions param.Opt[bool] `json:"includeFileVersions,omitzero"`
725+
paramObj
726+
}
727+
728+
func (r UpdateFileDetailsRequestChangePublicationStatusPublishParam) MarshalJSON() (data []byte, err error) {
729+
type shadow UpdateFileDetailsRequestChangePublicationStatusPublishParam
730+
return param.MarshalObject(r, (*shadow)(&r))
731+
}
732+
func (r *UpdateFileDetailsRequestChangePublicationStatusPublishParam) UnmarshalJSON(data []byte) error {
733+
return apijson.UnmarshalRoot(data, r)
734+
}
735+
608736
// Object containing details of a file or file version.
609737
type FileUpdateResponse struct {
610738
ExtensionStatus FileUpdateResponseExtensionStatus `json:"extensionStatus"`
@@ -891,125 +1019,15 @@ func (r *FileUploadResponseVersionInfo) UnmarshalJSON(data []byte) error {
8911019
}
8921020

8931021
type FileUpdateParams struct {
894-
895-
//
896-
// Request body variants
897-
//
898-
899-
// This field is a request body variant, only one variant field can be set.
900-
OfUpdateFileDetails *FileUpdateParamsBodyUpdateFileDetails `json:",inline"`
901-
// This field is a request body variant, only one variant field can be set.
902-
OfChangePublicationStatus *FileUpdateParamsBodyChangePublicationStatus `json:",inline"`
903-
1022+
UpdateFileDetailsRequest UpdateFileDetailsRequestUnionParam
9041023
paramObj
9051024
}
9061025

907-
func (u FileUpdateParams) MarshalJSON() ([]byte, error) {
908-
return param.MarshalUnion(u, u.OfUpdateFileDetails, u.OfChangePublicationStatus)
1026+
func (r FileUpdateParams) MarshalJSON() (data []byte, err error) {
1027+
return shimjson.Marshal(r.UpdateFileDetailsRequest)
9091028
}
9101029
func (r *FileUpdateParams) UnmarshalJSON(data []byte) error {
911-
return apijson.UnmarshalRoot(data, r)
912-
}
913-
914-
type FileUpdateParamsBodyUpdateFileDetails struct {
915-
// Define an important area in the image in the format `x,y,width,height` e.g.
916-
// `10,10,100,100`. Send `null` to unset this value.
917-
CustomCoordinates param.Opt[string] `json:"customCoordinates,omitzero"`
918-
// Optional text to describe the contents of the file.
919-
Description param.Opt[string] `json:"description,omitzero"`
920-
// The final status of extensions after they have completed execution will be
921-
// delivered to this endpoint as a POST request.
922-
// [Learn more](/docs/api-reference/digital-asset-management-dam/managing-assets/update-file-details#webhook-payload-structure)
923-
// about the webhook payload structure.
924-
WebhookURL param.Opt[string] `json:"webhookUrl,omitzero" format:"uri"`
925-
// An array of tags associated with the file, such as `["tag1", "tag2"]`. Send
926-
// `null` to unset all tags associated with the file.
927-
Tags []string `json:"tags,omitzero"`
928-
// A key-value data to be associated with the asset. To unset a key, send `null`
929-
// value for that key. Before setting any custom metadata on an asset you have to
930-
// create the field using custom metadata fields API.
931-
CustomMetadata map[string]any `json:"customMetadata,omitzero"`
932-
// Array of extensions to be applied to the asset. Each extension can be configured
933-
// with specific parameters based on the extension type.
934-
Extensions shared.ExtensionsParam `json:"extensions,omitzero"`
935-
// An array of AITags associated with the file that you want to remove, e.g.
936-
// `["car", "vehicle", "motorsports"]`.
937-
//
938-
// If you want to remove all AITags associated with the file, send a string -
939-
// "all".
940-
//
941-
// Note: The remove operation for `AITags` executes before any of the `extensions`
942-
// are processed.
943-
RemoveAITags FileUpdateParamsBodyUpdateFileDetailsRemoveAITagsUnion `json:"removeAITags,omitzero"`
944-
paramObj
945-
}
946-
947-
func (r FileUpdateParamsBodyUpdateFileDetails) MarshalJSON() (data []byte, err error) {
948-
type shadow FileUpdateParamsBodyUpdateFileDetails
949-
return param.MarshalObject(r, (*shadow)(&r))
950-
}
951-
func (r *FileUpdateParamsBodyUpdateFileDetails) UnmarshalJSON(data []byte) error {
952-
return apijson.UnmarshalRoot(data, r)
953-
}
954-
955-
// Only one field can be non-zero.
956-
//
957-
// Use [param.IsOmitted] to confirm if a field is set.
958-
type FileUpdateParamsBodyUpdateFileDetailsRemoveAITagsUnion struct {
959-
OfStringArray []string `json:",omitzero,inline"`
960-
// Construct this variant with constant.ValueOf[constant.All]()
961-
OfAll constant.All `json:",omitzero,inline"`
962-
paramUnion
963-
}
964-
965-
func (u FileUpdateParamsBodyUpdateFileDetailsRemoveAITagsUnion) MarshalJSON() ([]byte, error) {
966-
return param.MarshalUnion(u, u.OfStringArray, u.OfAll)
967-
}
968-
func (u *FileUpdateParamsBodyUpdateFileDetailsRemoveAITagsUnion) UnmarshalJSON(data []byte) error {
969-
return apijson.UnmarshalRoot(data, u)
970-
}
971-
972-
func (u *FileUpdateParamsBodyUpdateFileDetailsRemoveAITagsUnion) asAny() any {
973-
if !param.IsOmitted(u.OfStringArray) {
974-
return &u.OfStringArray
975-
} else if !param.IsOmitted(u.OfAll) {
976-
return &u.OfAll
977-
}
978-
return nil
979-
}
980-
981-
type FileUpdateParamsBodyChangePublicationStatus struct {
982-
// Configure the publication status of a file and its versions.
983-
Publish FileUpdateParamsBodyChangePublicationStatusPublish `json:"publish,omitzero"`
984-
paramObj
985-
}
986-
987-
func (r FileUpdateParamsBodyChangePublicationStatus) MarshalJSON() (data []byte, err error) {
988-
type shadow FileUpdateParamsBodyChangePublicationStatus
989-
return param.MarshalObject(r, (*shadow)(&r))
990-
}
991-
func (r *FileUpdateParamsBodyChangePublicationStatus) UnmarshalJSON(data []byte) error {
992-
return apijson.UnmarshalRoot(data, r)
993-
}
994-
995-
// Configure the publication status of a file and its versions.
996-
//
997-
// The property IsPublished is required.
998-
type FileUpdateParamsBodyChangePublicationStatusPublish struct {
999-
// Set to `true` to publish the file. Set to `false` to unpublish the file.
1000-
IsPublished bool `json:"isPublished,required"`
1001-
// Set to `true` to publish/unpublish all versions of the file. Set to `false` to
1002-
// publish/unpublish only the current version of the file.
1003-
IncludeFileVersions param.Opt[bool] `json:"includeFileVersions,omitzero"`
1004-
paramObj
1005-
}
1006-
1007-
func (r FileUpdateParamsBodyChangePublicationStatusPublish) MarshalJSON() (data []byte, err error) {
1008-
type shadow FileUpdateParamsBodyChangePublicationStatusPublish
1009-
return param.MarshalObject(r, (*shadow)(&r))
1010-
}
1011-
func (r *FileUpdateParamsBodyChangePublicationStatusPublish) UnmarshalJSON(data []byte) error {
1012-
return apijson.UnmarshalRoot(data, r)
1030+
return json.Unmarshal(data, &r.UpdateFileDetailsRequest)
10131031
}
10141032

10151033
type FileCopyParams struct {

file_test.go

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,42 +34,44 @@ func TestFileUpdateWithOptionalParams(t *testing.T) {
3434
context.TODO(),
3535
"fileId",
3636
imagekit.FileUpdateParams{
37-
OfUpdateFileDetails: &imagekit.FileUpdateParamsBodyUpdateFileDetails{
38-
CustomCoordinates: imagekit.String("10,10,100,100"),
39-
CustomMetadata: map[string]any{
40-
"brand": "bar",
41-
"color": "bar",
42-
},
43-
Description: imagekit.String("description"),
44-
Extensions: shared.ExtensionsParam{shared.ExtensionUnionParam{
45-
OfRemoveBg: &shared.ExtensionRemoveBgParam{
46-
Options: shared.ExtensionRemoveBgOptionsParam{
47-
AddShadow: imagekit.Bool(true),
48-
BgColor: imagekit.String("bg_color"),
49-
BgImageURL: imagekit.String("bg_image_url"),
50-
Semitransparency: imagekit.Bool(true),
51-
},
52-
},
53-
}, shared.ExtensionUnionParam{
54-
OfAutoTagging: &shared.ExtensionAutoTaggingParam{
55-
MaxTags: 10,
56-
MinConfidence: 80,
57-
Name: "google-auto-tagging",
37+
UpdateFileDetailsRequest: imagekit.UpdateFileDetailsRequestUnionParam{
38+
OfUpdateFileDetails: &imagekit.UpdateFileDetailsRequestUpdateFileDetailsParam{
39+
CustomCoordinates: imagekit.String("10,10,100,100"),
40+
CustomMetadata: map[string]any{
41+
"brand": "bar",
42+
"color": "bar",
5843
},
59-
}, shared.ExtensionUnionParam{
60-
OfAutoTagging: &shared.ExtensionAutoTaggingParam{
61-
MaxTags: 10,
62-
MinConfidence: 80,
63-
Name: "aws-auto-tagging",
44+
Description: imagekit.String("description"),
45+
Extensions: shared.ExtensionsParam{shared.ExtensionUnionParam{
46+
OfRemoveBg: &shared.ExtensionRemoveBgParam{
47+
Options: shared.ExtensionRemoveBgOptionsParam{
48+
AddShadow: imagekit.Bool(true),
49+
BgColor: imagekit.String("bg_color"),
50+
BgImageURL: imagekit.String("bg_image_url"),
51+
Semitransparency: imagekit.Bool(true),
52+
},
53+
},
54+
}, shared.ExtensionUnionParam{
55+
OfAutoTagging: &shared.ExtensionAutoTaggingParam{
56+
MaxTags: 10,
57+
MinConfidence: 80,
58+
Name: "google-auto-tagging",
59+
},
60+
}, shared.ExtensionUnionParam{
61+
OfAutoTagging: &shared.ExtensionAutoTaggingParam{
62+
MaxTags: 10,
63+
MinConfidence: 80,
64+
Name: "aws-auto-tagging",
65+
},
66+
}, shared.ExtensionUnionParam{
67+
OfAIAutoDescription: &shared.ExtensionAIAutoDescriptionParam{},
68+
}},
69+
RemoveAITags: imagekit.UpdateFileDetailsRequestUpdateFileDetailsRemoveAITagsUnionParam{
70+
OfStringArray: []string{"car", "vehicle", "motorsports"},
6471
},
65-
}, shared.ExtensionUnionParam{
66-
OfAIAutoDescription: &shared.ExtensionAIAutoDescriptionParam{},
67-
}},
68-
RemoveAITags: imagekit.FileUpdateParamsBodyUpdateFileDetailsRemoveAITagsUnion{
69-
OfStringArray: []string{"car", "vehicle", "motorsports"},
72+
Tags: []string{"tag1", "tag2"},
73+
WebhookURL: imagekit.String("https://webhook.site/0d6b6c7a-8e5a-4b3a-8b7c-0d6b6c7a8e5a"),
7074
},
71-
Tags: []string{"tag1", "tag2"},
72-
WebhookURL: imagekit.String("https://webhook.site/0d6b6c7a-8e5a-4b3a-8b7c-0d6b6c7a8e5a"),
7375
},
7476
},
7577
)

0 commit comments

Comments
 (0)