From 6a7fcabf830da9dad874d2eb22b03bedb220fdf4 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 03:07:38 +0000 Subject: [PATCH] fix: a list of items of a named type is paged through too A list whose items are of a named list type, as type Templates []Template, gets its iterators as one of []Template does: Notion's templates, plugins and sessions are such lists. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019QCb1AfnATvpBQCH3PrX7Y --- ir/pagination.go | 13 +++++++++++-- ir/pagination_internal_test.go | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/ir/pagination.go b/ir/pagination.go index 5c675685..bfa4e6ba 100644 --- a/ir/pagination.go +++ b/ir/pagination.go @@ -124,7 +124,16 @@ func pagination(op *Operation, byName map[string]*Schema) (*Pagination, error) { } items := fieldOf(list, ext.Items, itemsNames) - if items == nil || !strings.HasPrefix(items.Type, "[]") { + if items == nil { + return nil, fmt.Errorf("%s has no list of items", list.Name) + } + + itemsType := items.Type + if s := byName[itemsType]; s != nil && s.Kind == SchemaKindAlias { + itemsType = s.Type // a named list, as type Templates []Template + } + + if !strings.HasPrefix(itemsType, "[]") { return nil, fmt.Errorf("%s has no list of items", list.Name) } @@ -139,7 +148,7 @@ func pagination(op *Operation, byName map[string]*Schema) (*Pagination, error) { } p := &Pagination{ - CursorType: next.Type, NextField: next.Name, ItemsField: items.Name, ItemType: strings.TrimPrefix(items.Type, "[]"), + CursorType: next.Type, NextField: next.Name, ItemsField: items.Name, ItemType: strings.TrimPrefix(itemsType, "[]"), } if more != nil { p.MoreField = more.Name diff --git a/ir/pagination_internal_test.go b/ir/pagination_internal_test.go index c33ddef0..ccfccd36 100644 --- a/ir/pagination_internal_test.go +++ b/ir/pagination_internal_test.go @@ -81,6 +81,20 @@ func TestPaginate(t *testing.T) { t.Errorf("x-pagination false: got %+v, %v; want none", ops[0].Pagination, err) } + // a named list of items is followed to its items + named := []Schema{ + {Name: "L", Kind: SchemaKindStruct, Fields: []Field{ + {Name: "Things", JSONName: "things", Type: "Things"}, + {Name: "NextCursor", JSONName: "next_cursor", Type: "string"}, + }}, + {Name: "Things", Kind: SchemaKindAlias, Type: "[]Thing"}, + } + + ops = []Operation{listOp("string", paginationExt{set: true, Items: "things"})} + if err := paginate(ops, named); err != nil || ops[0].Pagination == nil || ops[0].Pagination.ItemType != "Thing" { + t.Errorf("a named list: got %+v, %v; want items of Thing", ops[0].Pagination, err) + } + ops = []Operation{listOp("string", paginationExt{}), {Name: "ListThingsAll"}} if err := paginate(ops, listSchemas); err != nil || ops[0].Pagination != nil { t.Errorf("a name taken: got %+v, %v; want none", ops[0].Pagination, err)