-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcustommetadatafield.go
More file actions
822 lines (737 loc) · 32.2 KB
/
custommetadatafield.go
File metadata and controls
822 lines (737 loc) · 32.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package imagekit
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
"slices"
"github.com/imagekit-developer/imagekit-go/v2/internal/apijson"
"github.com/imagekit-developer/imagekit-go/v2/internal/apiquery"
"github.com/imagekit-developer/imagekit-go/v2/internal/requestconfig"
"github.com/imagekit-developer/imagekit-go/v2/option"
"github.com/imagekit-developer/imagekit-go/v2/packages/param"
"github.com/imagekit-developer/imagekit-go/v2/packages/respjson"
)
// CustomMetadataFieldService contains methods and other services that help with
// interacting with the ImageKit API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewCustomMetadataFieldService] method instead.
type CustomMetadataFieldService struct {
Options []option.RequestOption
}
// NewCustomMetadataFieldService generates a new service that applies the given
// options to each request. These options are applied after the parent client's
// options (if there is one), and before any request-specific options.
func NewCustomMetadataFieldService(opts ...option.RequestOption) (r CustomMetadataFieldService) {
r = CustomMetadataFieldService{}
r.Options = opts
return
}
// This API creates a new custom metadata field. Once a custom metadata field is
// created either through this API or using the dashboard UI, its value can be set
// on the assets. The value of a field for an asset can be set using the media
// library UI or programmatically through upload or update assets API.
func (r *CustomMetadataFieldService) New(ctx context.Context, body CustomMetadataFieldNewParams, opts ...option.RequestOption) (res *CustomMetadataField, err error) {
opts = slices.Concat(r.Options, opts)
path := "v1/customMetadataFields"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// This API updates the label or schema of an existing custom metadata field.
func (r *CustomMetadataFieldService) Update(ctx context.Context, id string, body CustomMetadataFieldUpdateParams, opts ...option.RequestOption) (res *CustomMetadataField, err error) {
opts = slices.Concat(r.Options, opts)
if id == "" {
err = errors.New("missing required id parameter")
return nil, err
}
path := fmt.Sprintf("v1/customMetadataFields/%s", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, body, &res, opts...)
return res, err
}
// This API returns the array of created custom metadata field objects. By default
// the API returns only non deleted field objects, but you can include deleted
// fields in the API response.
//
// You can also filter results by a specific folder path to retrieve custom
// metadata fields applicable at that location. This path-specific filtering is
// useful when using the **Path policy** feature to determine which custom metadata
// fields are selected for a given path.
func (r *CustomMetadataFieldService) List(ctx context.Context, query CustomMetadataFieldListParams, opts ...option.RequestOption) (res *[]CustomMetadataField, err error) {
opts = slices.Concat(r.Options, opts)
path := "v1/customMetadataFields"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return res, err
}
// This API deletes a custom metadata field. Even after deleting a custom metadata
// field, you cannot create any new custom metadata field with the same name.
func (r *CustomMetadataFieldService) Delete(ctx context.Context, id string, opts ...option.RequestOption) (res *CustomMetadataFieldDeleteResponse, err error) {
opts = slices.Concat(r.Options, opts)
if id == "" {
err = errors.New("missing required id parameter")
return nil, err
}
path := fmt.Sprintf("v1/customMetadataFields/%s", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return res, err
}
// Object containing details of a custom metadata field.
type CustomMetadataField struct {
// Unique identifier for the custom metadata field. Use this to update the field.
ID string `json:"id" api:"required"`
// Human readable name of the custom metadata field. This name is displayed as form
// field label to the users while setting field value on the asset in the media
// library UI.
Label string `json:"label" api:"required"`
// API name of the custom metadata field. This becomes the key while setting
// `customMetadata` (key-value object) for an asset using upload or update API.
Name string `json:"name" api:"required"`
// An object that describes the rules for the custom metadata field value.
Schema CustomMetadataFieldSchema `json:"schema" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Label respjson.Field
Name respjson.Field
Schema respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r CustomMetadataField) RawJSON() string { return r.JSON.raw }
func (r *CustomMetadataField) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// An object that describes the rules for the custom metadata field value.
type CustomMetadataFieldSchema struct {
// Type of the custom metadata field.
//
// Any of "Text", "Textarea", "Number", "Date", "Boolean", "SingleSelect",
// "MultiSelect".
Type string `json:"type" api:"required"`
// The default value for this custom metadata field. Data type of default value
// depends on the field type.
DefaultValue CustomMetadataFieldSchemaDefaultValueUnion `json:"defaultValue"`
// Specifies if the this custom metadata field is required or not.
IsValueRequired bool `json:"isValueRequired"`
// Maximum length of string. Only set if `type` is set to `Text` or `Textarea`.
MaxLength float64 `json:"maxLength"`
// Maximum value of the field. Only set if field type is `Date` or `Number`. For
// `Date` type field, the value will be in ISO8601 string format. For `Number` type
// field, it will be a numeric value.
MaxValue CustomMetadataFieldSchemaMaxValueUnion `json:"maxValue"`
// Minimum length of string. Only set if `type` is set to `Text` or `Textarea`.
MinLength float64 `json:"minLength"`
// Minimum value of the field. Only set if field type is `Date` or `Number`. For
// `Date` type field, the value will be in ISO8601 string format. For `Number` type
// field, it will be a numeric value.
MinValue CustomMetadataFieldSchemaMinValueUnion `json:"minValue"`
// An array of allowed values when field type is `SingleSelect` or `MultiSelect`.
SelectOptions []CustomMetadataFieldSchemaSelectOptionUnion `json:"selectOptions"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Type respjson.Field
DefaultValue respjson.Field
IsValueRequired respjson.Field
MaxLength respjson.Field
MaxValue respjson.Field
MinLength respjson.Field
MinValue respjson.Field
SelectOptions respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r CustomMetadataFieldSchema) RawJSON() string { return r.JSON.raw }
func (r *CustomMetadataFieldSchema) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// CustomMetadataFieldSchemaDefaultValueUnion contains all possible properties and
// values from [string], [float64], [bool],
// [[]CustomMetadataFieldSchemaDefaultValueMixedItemUnion].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfString OfFloat OfBool OfMixed]
type CustomMetadataFieldSchemaDefaultValueUnion struct {
// This field will be present if the value is a [string] instead of an object.
OfString string `json:",inline"`
// This field will be present if the value is a [float64] instead of an object.
OfFloat float64 `json:",inline"`
// This field will be present if the value is a [bool] instead of an object.
OfBool bool `json:",inline"`
// This field will be present if the value is a
// [[]CustomMetadataFieldSchemaDefaultValueMixedItemUnion] instead of an object.
OfMixed []CustomMetadataFieldSchemaDefaultValueMixedItemUnion `json:",inline"`
JSON struct {
OfString respjson.Field
OfFloat respjson.Field
OfBool respjson.Field
OfMixed respjson.Field
raw string
} `json:"-"`
}
func (u CustomMetadataFieldSchemaDefaultValueUnion) AsString() (v string) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u CustomMetadataFieldSchemaDefaultValueUnion) AsFloat() (v float64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u CustomMetadataFieldSchemaDefaultValueUnion) AsBool() (v bool) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u CustomMetadataFieldSchemaDefaultValueUnion) AsMixed() (v []CustomMetadataFieldSchemaDefaultValueMixedItemUnion) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u CustomMetadataFieldSchemaDefaultValueUnion) RawJSON() string { return u.JSON.raw }
func (r *CustomMetadataFieldSchemaDefaultValueUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// CustomMetadataFieldSchemaDefaultValueMixedItemUnion contains all possible
// properties and values from [string], [float64], [bool].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfString OfFloat OfBool]
type CustomMetadataFieldSchemaDefaultValueMixedItemUnion struct {
// This field will be present if the value is a [string] instead of an object.
OfString string `json:",inline"`
// This field will be present if the value is a [float64] instead of an object.
OfFloat float64 `json:",inline"`
// This field will be present if the value is a [bool] instead of an object.
OfBool bool `json:",inline"`
JSON struct {
OfString respjson.Field
OfFloat respjson.Field
OfBool respjson.Field
raw string
} `json:"-"`
}
func (u CustomMetadataFieldSchemaDefaultValueMixedItemUnion) AsString() (v string) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u CustomMetadataFieldSchemaDefaultValueMixedItemUnion) AsFloat() (v float64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u CustomMetadataFieldSchemaDefaultValueMixedItemUnion) AsBool() (v bool) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u CustomMetadataFieldSchemaDefaultValueMixedItemUnion) RawJSON() string { return u.JSON.raw }
func (r *CustomMetadataFieldSchemaDefaultValueMixedItemUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// CustomMetadataFieldSchemaMaxValueUnion contains all possible properties and
// values from [string], [float64].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfString OfFloat]
type CustomMetadataFieldSchemaMaxValueUnion struct {
// This field will be present if the value is a [string] instead of an object.
OfString string `json:",inline"`
// This field will be present if the value is a [float64] instead of an object.
OfFloat float64 `json:",inline"`
JSON struct {
OfString respjson.Field
OfFloat respjson.Field
raw string
} `json:"-"`
}
func (u CustomMetadataFieldSchemaMaxValueUnion) AsString() (v string) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u CustomMetadataFieldSchemaMaxValueUnion) AsFloat() (v float64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u CustomMetadataFieldSchemaMaxValueUnion) RawJSON() string { return u.JSON.raw }
func (r *CustomMetadataFieldSchemaMaxValueUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// CustomMetadataFieldSchemaMinValueUnion contains all possible properties and
// values from [string], [float64].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfString OfFloat]
type CustomMetadataFieldSchemaMinValueUnion struct {
// This field will be present if the value is a [string] instead of an object.
OfString string `json:",inline"`
// This field will be present if the value is a [float64] instead of an object.
OfFloat float64 `json:",inline"`
JSON struct {
OfString respjson.Field
OfFloat respjson.Field
raw string
} `json:"-"`
}
func (u CustomMetadataFieldSchemaMinValueUnion) AsString() (v string) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u CustomMetadataFieldSchemaMinValueUnion) AsFloat() (v float64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u CustomMetadataFieldSchemaMinValueUnion) RawJSON() string { return u.JSON.raw }
func (r *CustomMetadataFieldSchemaMinValueUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// CustomMetadataFieldSchemaSelectOptionUnion contains all possible properties and
// values from [string], [float64], [bool].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfString OfFloat OfBool]
type CustomMetadataFieldSchemaSelectOptionUnion struct {
// This field will be present if the value is a [string] instead of an object.
OfString string `json:",inline"`
// This field will be present if the value is a [float64] instead of an object.
OfFloat float64 `json:",inline"`
// This field will be present if the value is a [bool] instead of an object.
OfBool bool `json:",inline"`
JSON struct {
OfString respjson.Field
OfFloat respjson.Field
OfBool respjson.Field
raw string
} `json:"-"`
}
func (u CustomMetadataFieldSchemaSelectOptionUnion) AsString() (v string) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u CustomMetadataFieldSchemaSelectOptionUnion) AsFloat() (v float64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u CustomMetadataFieldSchemaSelectOptionUnion) AsBool() (v bool) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u CustomMetadataFieldSchemaSelectOptionUnion) RawJSON() string { return u.JSON.raw }
func (r *CustomMetadataFieldSchemaSelectOptionUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type CustomMetadataFieldDeleteResponse struct {
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r CustomMetadataFieldDeleteResponse) RawJSON() string { return r.JSON.raw }
func (r *CustomMetadataFieldDeleteResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type CustomMetadataFieldNewParams struct {
// Human readable name of the custom metadata field. This should be unique across
// all non deleted custom metadata fields. This name is displayed as form field
// label to the users while setting field value on an asset in the media library
// UI.
Label string `json:"label" api:"required"`
// API name of the custom metadata field. This should be unique across all
// (including deleted) custom metadata fields.
Name string `json:"name" api:"required"`
Schema CustomMetadataFieldNewParamsSchema `json:"schema,omitzero" api:"required"`
paramObj
}
func (r CustomMetadataFieldNewParams) MarshalJSON() (data []byte, err error) {
type shadow CustomMetadataFieldNewParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *CustomMetadataFieldNewParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The property Type is required.
type CustomMetadataFieldNewParamsSchema struct {
// Type of the custom metadata field.
//
// Any of "Text", "Textarea", "Number", "Date", "Boolean", "SingleSelect",
// "MultiSelect".
Type string `json:"type,omitzero" api:"required"`
// Sets this custom metadata field as required. Setting custom metadata fields on
// an asset will throw error if the value for all required fields are not present
// in upload or update asset API request body.
IsValueRequired param.Opt[bool] `json:"isValueRequired,omitzero"`
// Maximum length of string. Only set this property if `type` is set to `Text` or
// `Textarea`.
MaxLength param.Opt[float64] `json:"maxLength,omitzero"`
// Minimum length of string. Only set this property if `type` is set to `Text` or
// `Textarea`.
MinLength param.Opt[float64] `json:"minLength,omitzero"`
// The default value for this custom metadata field. This property is only required
// if `isValueRequired` property is set to `true`. The value should match the
// `type` of custom metadata field.
DefaultValue CustomMetadataFieldNewParamsSchemaDefaultValueUnion `json:"defaultValue,omitzero"`
// Maximum value of the field. Only set this property if field type is `Date` or
// `Number`. For `Date` type field, set the minimum date in ISO8601 string format.
// For `Number` type field, set the minimum numeric value.
MaxValue CustomMetadataFieldNewParamsSchemaMaxValueUnion `json:"maxValue,omitzero"`
// Minimum value of the field. Only set this property if field type is `Date` or
// `Number`. For `Date` type field, set the minimum date in ISO8601 string format.
// For `Number` type field, set the minimum numeric value.
MinValue CustomMetadataFieldNewParamsSchemaMinValueUnion `json:"minValue,omitzero"`
// An array of allowed values. This property is only required if `type` property is
// set to `SingleSelect` or `MultiSelect`.
SelectOptions []CustomMetadataFieldNewParamsSchemaSelectOptionUnion `json:"selectOptions,omitzero"`
paramObj
}
func (r CustomMetadataFieldNewParamsSchema) MarshalJSON() (data []byte, err error) {
type shadow CustomMetadataFieldNewParamsSchema
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *CustomMetadataFieldNewParamsSchema) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
func init() {
apijson.RegisterFieldValidator[CustomMetadataFieldNewParamsSchema](
"type", "Text", "Textarea", "Number", "Date", "Boolean", "SingleSelect", "MultiSelect",
)
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type CustomMetadataFieldNewParamsSchemaDefaultValueUnion struct {
OfString param.Opt[string] `json:",omitzero,inline"`
OfFloat param.Opt[float64] `json:",omitzero,inline"`
OfBool param.Opt[bool] `json:",omitzero,inline"`
OfMixed []CustomMetadataFieldNewParamsSchemaDefaultValueMixedItemUnion `json:",omitzero,inline"`
paramUnion
}
func (u CustomMetadataFieldNewParamsSchemaDefaultValueUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion(u, u.OfString, u.OfFloat, u.OfBool, u.OfMixed)
}
func (u *CustomMetadataFieldNewParamsSchemaDefaultValueUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
func (u *CustomMetadataFieldNewParamsSchemaDefaultValueUnion) asAny() any {
if !param.IsOmitted(u.OfString) {
return &u.OfString.Value
} else if !param.IsOmitted(u.OfFloat) {
return &u.OfFloat.Value
} else if !param.IsOmitted(u.OfBool) {
return &u.OfBool.Value
} else if !param.IsOmitted(u.OfMixed) {
return &u.OfMixed
}
return nil
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type CustomMetadataFieldNewParamsSchemaDefaultValueMixedItemUnion struct {
OfString param.Opt[string] `json:",omitzero,inline"`
OfFloat param.Opt[float64] `json:",omitzero,inline"`
OfBool param.Opt[bool] `json:",omitzero,inline"`
paramUnion
}
func (u CustomMetadataFieldNewParamsSchemaDefaultValueMixedItemUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion(u, u.OfString, u.OfFloat, u.OfBool)
}
func (u *CustomMetadataFieldNewParamsSchemaDefaultValueMixedItemUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
func (u *CustomMetadataFieldNewParamsSchemaDefaultValueMixedItemUnion) asAny() any {
if !param.IsOmitted(u.OfString) {
return &u.OfString.Value
} else if !param.IsOmitted(u.OfFloat) {
return &u.OfFloat.Value
} else if !param.IsOmitted(u.OfBool) {
return &u.OfBool.Value
}
return nil
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type CustomMetadataFieldNewParamsSchemaMaxValueUnion struct {
OfString param.Opt[string] `json:",omitzero,inline"`
OfFloat param.Opt[float64] `json:",omitzero,inline"`
paramUnion
}
func (u CustomMetadataFieldNewParamsSchemaMaxValueUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion(u, u.OfString, u.OfFloat)
}
func (u *CustomMetadataFieldNewParamsSchemaMaxValueUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
func (u *CustomMetadataFieldNewParamsSchemaMaxValueUnion) asAny() any {
if !param.IsOmitted(u.OfString) {
return &u.OfString.Value
} else if !param.IsOmitted(u.OfFloat) {
return &u.OfFloat.Value
}
return nil
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type CustomMetadataFieldNewParamsSchemaMinValueUnion struct {
OfString param.Opt[string] `json:",omitzero,inline"`
OfFloat param.Opt[float64] `json:",omitzero,inline"`
paramUnion
}
func (u CustomMetadataFieldNewParamsSchemaMinValueUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion(u, u.OfString, u.OfFloat)
}
func (u *CustomMetadataFieldNewParamsSchemaMinValueUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
func (u *CustomMetadataFieldNewParamsSchemaMinValueUnion) asAny() any {
if !param.IsOmitted(u.OfString) {
return &u.OfString.Value
} else if !param.IsOmitted(u.OfFloat) {
return &u.OfFloat.Value
}
return nil
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type CustomMetadataFieldNewParamsSchemaSelectOptionUnion struct {
OfString param.Opt[string] `json:",omitzero,inline"`
OfFloat param.Opt[float64] `json:",omitzero,inline"`
OfBool param.Opt[bool] `json:",omitzero,inline"`
paramUnion
}
func (u CustomMetadataFieldNewParamsSchemaSelectOptionUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion(u, u.OfString, u.OfFloat, u.OfBool)
}
func (u *CustomMetadataFieldNewParamsSchemaSelectOptionUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
func (u *CustomMetadataFieldNewParamsSchemaSelectOptionUnion) asAny() any {
if !param.IsOmitted(u.OfString) {
return &u.OfString.Value
} else if !param.IsOmitted(u.OfFloat) {
return &u.OfFloat.Value
} else if !param.IsOmitted(u.OfBool) {
return &u.OfBool.Value
}
return nil
}
type CustomMetadataFieldUpdateParams struct {
// Human readable name of the custom metadata field. This should be unique across
// all non deleted custom metadata fields. This name is displayed as form field
// label to the users while setting field value on an asset in the media library
// UI. This parameter is required if `schema` is not provided.
Label param.Opt[string] `json:"label,omitzero"`
// An object that describes the rules for the custom metadata key. This parameter
// is required if `label` is not provided. Note: `type` cannot be updated and will
// be ignored if sent with the `schema`. The schema will be validated as per the
// existing `type`.
Schema CustomMetadataFieldUpdateParamsSchema `json:"schema,omitzero"`
paramObj
}
func (r CustomMetadataFieldUpdateParams) MarshalJSON() (data []byte, err error) {
type shadow CustomMetadataFieldUpdateParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *CustomMetadataFieldUpdateParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// An object that describes the rules for the custom metadata key. This parameter
// is required if `label` is not provided. Note: `type` cannot be updated and will
// be ignored if sent with the `schema`. The schema will be validated as per the
// existing `type`.
type CustomMetadataFieldUpdateParamsSchema struct {
// Sets this custom metadata field as required. Setting custom metadata fields on
// an asset will throw error if the value for all required fields are not present
// in upload or update asset API request body.
IsValueRequired param.Opt[bool] `json:"isValueRequired,omitzero"`
// Maximum length of string. Only set this property if `type` is set to `Text` or
// `Textarea`.
MaxLength param.Opt[float64] `json:"maxLength,omitzero"`
// Minimum length of string. Only set this property if `type` is set to `Text` or
// `Textarea`.
MinLength param.Opt[float64] `json:"minLength,omitzero"`
// The default value for this custom metadata field. This property is only required
// if `isValueRequired` property is set to `true`. The value should match the
// `type` of custom metadata field.
DefaultValue CustomMetadataFieldUpdateParamsSchemaDefaultValueUnion `json:"defaultValue,omitzero"`
// Maximum value of the field. Only set this property if field type is `Date` or
// `Number`. For `Date` type field, set the minimum date in ISO8601 string format.
// For `Number` type field, set the minimum numeric value.
MaxValue CustomMetadataFieldUpdateParamsSchemaMaxValueUnion `json:"maxValue,omitzero"`
// Minimum value of the field. Only set this property if field type is `Date` or
// `Number`. For `Date` type field, set the minimum date in ISO8601 string format.
// For `Number` type field, set the minimum numeric value.
MinValue CustomMetadataFieldUpdateParamsSchemaMinValueUnion `json:"minValue,omitzero"`
// An array of allowed values. This property is only required if `type` property is
// set to `SingleSelect` or `MultiSelect`.
SelectOptions []CustomMetadataFieldUpdateParamsSchemaSelectOptionUnion `json:"selectOptions,omitzero"`
paramObj
}
func (r CustomMetadataFieldUpdateParamsSchema) MarshalJSON() (data []byte, err error) {
type shadow CustomMetadataFieldUpdateParamsSchema
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *CustomMetadataFieldUpdateParamsSchema) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type CustomMetadataFieldUpdateParamsSchemaDefaultValueUnion struct {
OfString param.Opt[string] `json:",omitzero,inline"`
OfFloat param.Opt[float64] `json:",omitzero,inline"`
OfBool param.Opt[bool] `json:",omitzero,inline"`
OfMixed []CustomMetadataFieldUpdateParamsSchemaDefaultValueMixedItemUnion `json:",omitzero,inline"`
paramUnion
}
func (u CustomMetadataFieldUpdateParamsSchemaDefaultValueUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion(u, u.OfString, u.OfFloat, u.OfBool, u.OfMixed)
}
func (u *CustomMetadataFieldUpdateParamsSchemaDefaultValueUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
func (u *CustomMetadataFieldUpdateParamsSchemaDefaultValueUnion) asAny() any {
if !param.IsOmitted(u.OfString) {
return &u.OfString.Value
} else if !param.IsOmitted(u.OfFloat) {
return &u.OfFloat.Value
} else if !param.IsOmitted(u.OfBool) {
return &u.OfBool.Value
} else if !param.IsOmitted(u.OfMixed) {
return &u.OfMixed
}
return nil
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type CustomMetadataFieldUpdateParamsSchemaDefaultValueMixedItemUnion struct {
OfString param.Opt[string] `json:",omitzero,inline"`
OfFloat param.Opt[float64] `json:",omitzero,inline"`
OfBool param.Opt[bool] `json:",omitzero,inline"`
paramUnion
}
func (u CustomMetadataFieldUpdateParamsSchemaDefaultValueMixedItemUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion(u, u.OfString, u.OfFloat, u.OfBool)
}
func (u *CustomMetadataFieldUpdateParamsSchemaDefaultValueMixedItemUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
func (u *CustomMetadataFieldUpdateParamsSchemaDefaultValueMixedItemUnion) asAny() any {
if !param.IsOmitted(u.OfString) {
return &u.OfString.Value
} else if !param.IsOmitted(u.OfFloat) {
return &u.OfFloat.Value
} else if !param.IsOmitted(u.OfBool) {
return &u.OfBool.Value
}
return nil
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type CustomMetadataFieldUpdateParamsSchemaMaxValueUnion struct {
OfString param.Opt[string] `json:",omitzero,inline"`
OfFloat param.Opt[float64] `json:",omitzero,inline"`
paramUnion
}
func (u CustomMetadataFieldUpdateParamsSchemaMaxValueUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion(u, u.OfString, u.OfFloat)
}
func (u *CustomMetadataFieldUpdateParamsSchemaMaxValueUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
func (u *CustomMetadataFieldUpdateParamsSchemaMaxValueUnion) asAny() any {
if !param.IsOmitted(u.OfString) {
return &u.OfString.Value
} else if !param.IsOmitted(u.OfFloat) {
return &u.OfFloat.Value
}
return nil
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type CustomMetadataFieldUpdateParamsSchemaMinValueUnion struct {
OfString param.Opt[string] `json:",omitzero,inline"`
OfFloat param.Opt[float64] `json:",omitzero,inline"`
paramUnion
}
func (u CustomMetadataFieldUpdateParamsSchemaMinValueUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion(u, u.OfString, u.OfFloat)
}
func (u *CustomMetadataFieldUpdateParamsSchemaMinValueUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
func (u *CustomMetadataFieldUpdateParamsSchemaMinValueUnion) asAny() any {
if !param.IsOmitted(u.OfString) {
return &u.OfString.Value
} else if !param.IsOmitted(u.OfFloat) {
return &u.OfFloat.Value
}
return nil
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type CustomMetadataFieldUpdateParamsSchemaSelectOptionUnion struct {
OfString param.Opt[string] `json:",omitzero,inline"`
OfFloat param.Opt[float64] `json:",omitzero,inline"`
OfBool param.Opt[bool] `json:",omitzero,inline"`
paramUnion
}
func (u CustomMetadataFieldUpdateParamsSchemaSelectOptionUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion(u, u.OfString, u.OfFloat, u.OfBool)
}
func (u *CustomMetadataFieldUpdateParamsSchemaSelectOptionUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
func (u *CustomMetadataFieldUpdateParamsSchemaSelectOptionUnion) asAny() any {
if !param.IsOmitted(u.OfString) {
return &u.OfString.Value
} else if !param.IsOmitted(u.OfFloat) {
return &u.OfFloat.Value
} else if !param.IsOmitted(u.OfBool) {
return &u.OfBool.Value
}
return nil
}
type CustomMetadataFieldListParams struct {
// The folder path (e.g., `/path/to/folder`) for which to retrieve applicable
// custom metadata fields. Useful for determining path-specific field selections
// when the [Path policy](https://imagekit.io/docs/dam/path-policy) feature is in
// use.
FolderPath param.Opt[string] `query:"folderPath,omitzero" json:"-"`
// Set it to `true` to include deleted field objects in the API response.
IncludeDeleted param.Opt[bool] `query:"includeDeleted,omitzero" json:"-"`
paramObj
}
// URLQuery serializes [CustomMetadataFieldListParams]'s query parameters as
// `url.Values`.
func (r CustomMetadataFieldListParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}