Skip to content

Commit 05ebfae

Browse files
Apply suggestions from code review
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 871dcea commit 05ebfae

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

internal/api/client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ func (c *Client) Run(ctx context.Context, model string, args []string, opts RunO
207207
if err := schema.ValidateAllOf(reqSchema, payload); err != nil {
208208
return nil, err
209209
}
210+
if dm := schema.ResolveDeliveryMethod(opts.DeliveryMethod, payload, reqSchema); dm != "" {
211+
payload[fieldDeliveryMethod] = dm
212+
}
210213
if err := schema.ValidateEnums(reqSchema, payload); err != nil {
211214
return nil, err
212215
}

internal/schema/schema.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,13 +499,14 @@ func validateEnumsInValue(prop Node, val any, path string) error {
499499
//
500500
// Returns nil when the node has no string enum constraint.
501501
func stringEnumValues(prop Node) []string {
502-
var vals []string
503502
if len(prop.Const) > 0 {
504503
var s string
505504
if err := json.Unmarshal(prop.Const, &s); err == nil {
506505
return []string{s}
507506
}
508507
}
508+
509+
var vals []string
509510
for i := range prop.OneOf {
510511
if len(prop.OneOf[i].Const) == 0 {
511512
continue
@@ -515,13 +516,29 @@ func stringEnumValues(prop Node) []string {
515516
vals = append(vals, s)
516517
}
517518
}
518-
for _, raw := range prop.Enum {
519-
var s string
520-
if err := json.Unmarshal(raw, &s); err == nil {
521-
vals = append(vals, s)
519+
if len(vals) == 0 {
520+
for _, raw := range prop.Enum {
521+
var s string
522+
if err := json.Unmarshal(raw, &s); err == nil {
523+
vals = append(vals, s)
524+
}
522525
}
523526
}
524-
return vals
527+
if len(vals) == 0 {
528+
return nil
529+
}
530+
531+
// De-dupe while preserving schema order.
532+
seen := make(map[string]struct{}, len(vals))
533+
out := make([]string, 0, len(vals))
534+
for _, s := range vals {
535+
if _, ok := seen[s]; ok {
536+
continue
537+
}
538+
seen[s] = struct{}{}
539+
out = append(out, s)
540+
}
541+
return out
525542
}
526543

527544
func checkDependentRequired(depReq map[string][]string, payload map[string]any) error {

0 commit comments

Comments
 (0)