Skip to content

Commit 244e253

Browse files
committed
Address code review comments
1 parent fc3bf89 commit 244e253

4 files changed

Lines changed: 34 additions & 6 deletions

File tree

changes/20250622163602.feature

Lines changed: 0 additions & 1 deletion
This file was deleted.

changes/20250622195717.feature

Lines changed: 0 additions & 1 deletion
This file was deleted.

generator/codegen/collection_extensions.go

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ type CollectionParams = struct {
4242
NotificationFeedCollections
4343
}
4444

45+
type collectionOptions struct {
46+
noPagination bool
47+
}
48+
49+
type CollectionOption interface {
50+
apply(*collectionOptions)
51+
}
52+
53+
type noPaginationOption bool
54+
55+
func (n noPaginationOption) apply(opts *collectionOptions) {
56+
opts.noPagination = bool(n)
57+
}
58+
59+
func WithNoPagination(n bool) CollectionOption {
60+
return noPaginationOption(n)
61+
}
62+
4563
const (
4664
// Messages are a special case as they are a feed rather than a normal collection
4765
notificationFeedRef = "NotificationFeed"
@@ -208,13 +226,21 @@ func getCollectionSchema(swagger *openapi3.T, appJSON *openapi3.MediaType, endpo
208226
return
209227
}
210228

211-
func newCollection(collectionRef, itemRef string, noPagination bool) Collection {
229+
func newCollection(collectionRef, itemRef string, opts ...CollectionOption) Collection {
230+
options := collectionOptions{
231+
noPagination: false,
232+
}
233+
234+
for _, opt := range opts {
235+
opt.apply(&options)
236+
}
237+
212238
return Collection{
213239
CollectionRef: collectionRef,
214240
ItemRef: trimRefPrefix(itemRef),
215241
ModelRef: fmt.Sprintf("%sModel", strings.TrimSuffix(collectionRef, "Collection")),
216242
IteratorRef: fmt.Sprintf("%sIterator", strings.TrimSuffix(collectionRef, "Collection")),
217-
NoPagination: noPagination,
243+
NoPagination: options.noPagination,
218244
}
219245
}
220246

@@ -321,7 +347,11 @@ func GetCollections(swagger *openapi3.T) (collections CollectionParams, err erro
321347
return
322348
}
323349

324-
collectionSet.Add(newCollection(collectionRef, itemRef, isNoPaginationCollection))
350+
if isNoPaginationCollection {
351+
collectionSet.Add(newCollection(collectionRef, itemRef, WithNoPagination(true)))
352+
} else {
353+
collectionSet.Add(newCollection(collectionRef, itemRef))
354+
}
325355
}
326356

327357
if isMessagesCollection := strings.HasSuffix(endpoint, "messages"); isMessagesCollection {

generator/codegen/templates/entities.go.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func (o *{{ .CollectionRef }}) GetItemCount() (count int64, err error) {
140140
func New{{ .CollectionRef }}Collection() IStaticPage {
141141
return New{{ .CollectionRef }}WithDefaults()
142142
}
143-
{{ end }} {{/* end if not .NoPagination */}}
143+
{{ end }}
144144
{{ end }}
145145
{{ range .Params.JobItems -}}
146146
// ============================================================================================

0 commit comments

Comments
 (0)