Skip to content

Commit a5abf15

Browse files
olupclaude
andcommitted
feat(openapi): add ordering and pagination to RPC findMany endpoints
Add orderBy, cursor, take, and skip parameters to findMany operations in the RPC-style OpenAPI generator. This brings parity with the REST API generator and enables clients to: - Sort results using orderBy (single or multiple fields) - Paginate using take/skip (offset-based) - Use cursor-based pagination Also added runtime tests to verify the functionality works correctly. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 692b714 commit a5abf15

File tree

8 files changed

+279
-7
lines changed

8 files changed

+279
-7
lines changed

packages/plugins/openapi/src/rpc-generator.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ export class RPCOpenAPIGenerator extends OpenAPIGeneratorBase {
154154
// analyze access policies to determine default security
155155
const { create, read, update, delete: del } = analyzePolicies(zmodel);
156156

157+
// OrderByWithRelationInput's name is different when "fullTextSearch" is enabled
158+
const orderByWithRelationInput = this.inputObjectTypes
159+
.map((o) => upperCaseFirst(o.name))
160+
.includes(`${modelName}OrderByWithRelationInput`)
161+
? `${modelName}OrderByWithRelationInput`
162+
: `${modelName}OrderByWithRelationAndSearchRelevanceInput`;
163+
157164
if (ops['createOne']) {
158165
definitions.push({
159166
method: 'post',
@@ -269,6 +276,13 @@ export class RPCOpenAPIGenerator extends OpenAPIGeneratorBase {
269276
select: this.omittableRef(`${modelName}Select`),
270277
include: hasRelation ? this.omittableRef(`${modelName}Include`) : undefined,
271278
where: this.omittableRef(`${modelName}WhereInput`),
279+
orderBy: this.oneOf(
280+
this.omittableRef(orderByWithRelationInput),
281+
this.array(this.omittableRef(orderByWithRelationInput))
282+
),
283+
cursor: this.omittableRef(`${modelName}WhereUniqueInput`),
284+
take: { type: 'integer' },
285+
skip: { type: 'integer' },
272286
meta: this.ref('_Meta'),
273287
},
274288
},
@@ -422,13 +436,6 @@ export class RPCOpenAPIGenerator extends OpenAPIGeneratorBase {
422436
security: read === true ? [] : undefined,
423437
});
424438

425-
// OrderByWithRelationInput's name is different when "fullTextSearch" is enabled
426-
const orderByWithRelationInput = this.inputObjectTypes
427-
.map((o) => upperCaseFirst(o.name))
428-
.includes(`${modelName}OrderByWithRelationInput`)
429-
? `${modelName}OrderByWithRelationInput`
430-
: `${modelName}OrderByWithRelationAndSearchRelevanceInput`;
431-
432439
if (ops['aggregate']) {
433440
definitions.push({
434441
method: 'get',

packages/plugins/openapi/tests/baseline/rpc-3.0.0-omit.baseline.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,18 @@ components:
572572
$ref: '#/components/schemas/_AnyObject'
573573
meta:
574574
$ref: '#/components/schemas/_Meta'
575+
orderBy:
576+
oneOf:
577+
- $ref: '#/components/schemas/_AnyObject'
578+
- type: array
579+
items:
580+
$ref: '#/components/schemas/_AnyObject'
581+
cursor:
582+
$ref: '#/components/schemas/_AnyObject'
583+
take:
584+
type: integer
585+
skip:
586+
type: integer
575587
UserUpdateArgs:
576588
type: object
577589
required:
@@ -760,6 +772,18 @@ components:
760772
$ref: '#/components/schemas/_AnyObject'
761773
meta:
762774
$ref: '#/components/schemas/_Meta'
775+
orderBy:
776+
oneOf:
777+
- $ref: '#/components/schemas/_AnyObject'
778+
- type: array
779+
items:
780+
$ref: '#/components/schemas/_AnyObject'
781+
cursor:
782+
$ref: '#/components/schemas/_AnyObject'
783+
take:
784+
type: integer
785+
skip:
786+
type: integer
763787
ProfileUpdateArgs:
764788
type: object
765789
required:

packages/plugins/openapi/tests/baseline/rpc-3.0.0.baseline.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3318,6 +3318,18 @@ components:
33183318
$ref: '#/components/schemas/UserWhereInput'
33193319
meta:
33203320
$ref: '#/components/schemas/_Meta'
3321+
orderBy:
3322+
oneOf:
3323+
- $ref: '#/components/schemas/UserOrderByWithRelationInput'
3324+
- type: array
3325+
items:
3326+
$ref: '#/components/schemas/UserOrderByWithRelationInput'
3327+
cursor:
3328+
$ref: '#/components/schemas/UserWhereUniqueInput'
3329+
take:
3330+
type: integer
3331+
skip:
3332+
type: integer
33213333
UserUpdateArgs:
33223334
type: object
33233335
required:
@@ -3506,6 +3518,18 @@ components:
35063518
$ref: '#/components/schemas/ProfileWhereInput'
35073519
meta:
35083520
$ref: '#/components/schemas/_Meta'
3521+
orderBy:
3522+
oneOf:
3523+
- $ref: '#/components/schemas/ProfileOrderByWithRelationInput'
3524+
- type: array
3525+
items:
3526+
$ref: '#/components/schemas/ProfileOrderByWithRelationInput'
3527+
cursor:
3528+
$ref: '#/components/schemas/ProfileWhereUniqueInput'
3529+
take:
3530+
type: integer
3531+
skip:
3532+
type: integer
35093533
ProfileUpdateArgs:
35103534
type: object
35113535
required:
@@ -3694,6 +3718,18 @@ components:
36943718
$ref: '#/components/schemas/Post_ItemWhereInput'
36953719
meta:
36963720
$ref: '#/components/schemas/_Meta'
3721+
orderBy:
3722+
oneOf:
3723+
- $ref: '#/components/schemas/Post_ItemOrderByWithRelationInput'
3724+
- type: array
3725+
items:
3726+
$ref: '#/components/schemas/Post_ItemOrderByWithRelationInput'
3727+
cursor:
3728+
$ref: '#/components/schemas/Post_ItemWhereUniqueInput'
3729+
take:
3730+
type: integer
3731+
skip:
3732+
type: integer
36973733
Post_ItemUpdateArgs:
36983734
type: object
36993735
required:

packages/plugins/openapi/tests/baseline/rpc-3.1.0-omit.baseline.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,18 @@ components:
610610
$ref: '#/components/schemas/_AnyObject'
611611
meta:
612612
$ref: '#/components/schemas/_Meta'
613+
orderBy:
614+
oneOf:
615+
- $ref: '#/components/schemas/_AnyObject'
616+
- type: array
617+
items:
618+
$ref: '#/components/schemas/_AnyObject'
619+
cursor:
620+
$ref: '#/components/schemas/_AnyObject'
621+
take:
622+
type: integer
623+
skip:
624+
type: integer
613625
UserUpdateArgs:
614626
type: object
615627
required:
@@ -798,6 +810,18 @@ components:
798810
$ref: '#/components/schemas/_AnyObject'
799811
meta:
800812
$ref: '#/components/schemas/_Meta'
813+
orderBy:
814+
oneOf:
815+
- $ref: '#/components/schemas/_AnyObject'
816+
- type: array
817+
items:
818+
$ref: '#/components/schemas/_AnyObject'
819+
cursor:
820+
$ref: '#/components/schemas/_AnyObject'
821+
take:
822+
type: integer
823+
skip:
824+
type: integer
801825
ProfileUpdateArgs:
802826
type: object
803827
required:

packages/plugins/openapi/tests/baseline/rpc-3.1.0.baseline.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3382,6 +3382,18 @@ components:
33823382
$ref: '#/components/schemas/UserWhereInput'
33833383
meta:
33843384
$ref: '#/components/schemas/_Meta'
3385+
orderBy:
3386+
oneOf:
3387+
- $ref: '#/components/schemas/UserOrderByWithRelationInput'
3388+
- type: array
3389+
items:
3390+
$ref: '#/components/schemas/UserOrderByWithRelationInput'
3391+
cursor:
3392+
$ref: '#/components/schemas/UserWhereUniqueInput'
3393+
take:
3394+
type: integer
3395+
skip:
3396+
type: integer
33853397
UserUpdateArgs:
33863398
type: object
33873399
required:
@@ -3570,6 +3582,18 @@ components:
35703582
$ref: '#/components/schemas/ProfileWhereInput'
35713583
meta:
35723584
$ref: '#/components/schemas/_Meta'
3585+
orderBy:
3586+
oneOf:
3587+
- $ref: '#/components/schemas/ProfileOrderByWithRelationInput'
3588+
- type: array
3589+
items:
3590+
$ref: '#/components/schemas/ProfileOrderByWithRelationInput'
3591+
cursor:
3592+
$ref: '#/components/schemas/ProfileWhereUniqueInput'
3593+
take:
3594+
type: integer
3595+
skip:
3596+
type: integer
35733597
ProfileUpdateArgs:
35743598
type: object
35753599
required:
@@ -3758,6 +3782,18 @@ components:
37583782
$ref: '#/components/schemas/Post_ItemWhereInput'
37593783
meta:
37603784
$ref: '#/components/schemas/_Meta'
3785+
orderBy:
3786+
oneOf:
3787+
- $ref: '#/components/schemas/Post_ItemOrderByWithRelationInput'
3788+
- type: array
3789+
items:
3790+
$ref: '#/components/schemas/Post_ItemOrderByWithRelationInput'
3791+
cursor:
3792+
$ref: '#/components/schemas/Post_ItemWhereUniqueInput'
3793+
take:
3794+
type: integer
3795+
skip:
3796+
type: integer
37613797
Post_ItemUpdateArgs:
37623798
type: object
37633799
required:

packages/plugins/openapi/tests/baseline/rpc-type-coverage-3.0.0.baseline.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,6 +1959,18 @@ components:
19591959
$ref: '#/components/schemas/FooWhereInput'
19601960
meta:
19611961
$ref: '#/components/schemas/_Meta'
1962+
orderBy:
1963+
oneOf:
1964+
- $ref: '#/components/schemas/FooOrderByWithRelationInput'
1965+
- type: array
1966+
items:
1967+
$ref: '#/components/schemas/FooOrderByWithRelationInput'
1968+
cursor:
1969+
$ref: '#/components/schemas/FooWhereUniqueInput'
1970+
take:
1971+
type: integer
1972+
skip:
1973+
type: integer
19621974
FooUpdateArgs:
19631975
type: object
19641976
required:

packages/plugins/openapi/tests/baseline/rpc-type-coverage-3.1.0.baseline.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,6 +2001,18 @@ components:
20012001
$ref: '#/components/schemas/FooWhereInput'
20022002
meta:
20032003
$ref: '#/components/schemas/_Meta'
2004+
orderBy:
2005+
oneOf:
2006+
- $ref: '#/components/schemas/FooOrderByWithRelationInput'
2007+
- type: array
2008+
items:
2009+
$ref: '#/components/schemas/FooOrderByWithRelationInput'
2010+
cursor:
2011+
$ref: '#/components/schemas/FooWhereUniqueInput'
2012+
take:
2013+
type: integer
2014+
skip:
2015+
type: integer
20042016
FooUpdateArgs:
20052017
type: object
20062018
required:

0 commit comments

Comments
 (0)