@@ -444,6 +444,33 @@ describe('RPC OpenAPI spec generation - response data shapes', () => {
444444 expect ( postSchema . required ) . toContain ( 'title' ) ;
445445 expect ( postSchema . required ) . toContain ( 'published' ) ;
446446 } ) ;
447+
448+ it ( 'enum schemas are present in components and enum fields reference them' , async ( ) => {
449+ const enumSchema = `
450+ enum Role {
451+ USER
452+ ADMIN
453+ }
454+
455+ model User {
456+ id Int @id @default(autoincrement())
457+ role Role
458+ }
459+ ` ;
460+ const client = await createTestClient ( enumSchema ) ;
461+ const handler = new RPCApiHandler ( { schema : client . $schema } ) ;
462+ const s = await generateSpec ( handler ) ;
463+
464+ // Enum component must be registered so the $ref resolves
465+ expect ( s . components ?. schemas ?. [ 'Role' ] ) . toBeDefined ( ) ;
466+ expect ( s . components ?. schemas ?. [ 'Role' ] . type ) . toBe ( 'string' ) ;
467+ expect ( s . components ?. schemas ?. [ 'Role' ] . enum ) . toEqual ( [ 'USER' , 'ADMIN' ] ) ;
468+
469+ // The entity schema must reference the enum via $ref
470+ const userSchema = s . components ?. schemas ?. [ 'User' ] as any ;
471+ const roleField = userSchema ?. properties ?. role ;
472+ expect ( roleField ?. [ '$ref' ] ) . toBe ( '#/components/schemas/Role' ) ;
473+ } ) ;
447474} ) ;
448475
449476describe ( 'RPC OpenAPI spec generation - operationIds' , ( ) => {
@@ -753,6 +780,7 @@ procedure optionalSearch(query: String?): User[]
753780
754781 const operation = spec ?. paths ?. [ '/$procs/createUser' ] ?. post ;
755782 expect ( operation ?. requestBody ) . toBeDefined ( ) ;
783+ expect ( ( operation ?. requestBody as any ) ?. required ) . toBe ( true ) ;
756784 const bodySchema = ( operation ?. requestBody as any ) ?. content ?. [ 'application/json' ] ?. schema ;
757785 // args is a $ref to the registered ProcArgs component schema
758786 const argsRef = bodySchema ?. properties ?. args ?. $ref ;
@@ -763,6 +791,23 @@ procedure optionalSearch(query: String?): User[]
763791 expect ( argsSchema ?. required ) . toContain ( 'name' ) ;
764792 } ) ;
765793
794+ it ( 'mutation with only optional params does not set requestBody.required' , async ( ) => {
795+ const optionalMutationSchema = `
796+ model User {
797+ id Int @id @default(autoincrement())
798+ name String
799+ }
800+ mutation procedure softDelete(id: Int?): User
801+ ` ;
802+ const client = await createTestClient ( optionalMutationSchema ) ;
803+ const handler = new RPCApiHandler ( { schema : client . $schema } ) ;
804+ const spec = await generateSpec ( handler ) ;
805+
806+ const operation = spec ?. paths ?. [ '/$procs/softDelete' ] ?. post ;
807+ expect ( operation ?. requestBody ) . toBeDefined ( ) ;
808+ expect ( ( operation ?. requestBody as any ) ?. required ) . toBeUndefined ( ) ;
809+ } ) ;
810+
766811 it ( 'optional procedure params are not in required array' , async ( ) => {
767812 const client = await createTestClient ( procSchema ) ;
768813 const handler = new RPCApiHandler ( { schema : client . $schema } ) ;
@@ -799,6 +844,33 @@ procedure optionalSearch(query: String?): User[]
799844 expect ( spec . paths ?. [ '/$procs/getUser' ] ) . toBeUndefined ( ) ;
800845 expect ( spec . paths ?. [ '/$procs/createUser' ] ) . toBeDefined ( ) ;
801846 } ) ;
847+
848+ it ( 'slicing excludedProcedures removes procedure args from components schemas' , async ( ) => {
849+ const client = await createTestClient ( procSchema ) ;
850+ const handler = new RPCApiHandler ( {
851+ schema : client . $schema ,
852+ queryOptions : { slicing : { excludedProcedures : [ 'getUser' ] as any } } ,
853+ } ) ;
854+ const spec = await generateSpec ( handler ) ;
855+
856+ const schemaKeys = Object . keys ( spec . components ?. schemas ?? { } ) ;
857+ expect ( schemaKeys . some ( ( k ) => k . startsWith ( 'getUser' ) ) ) . toBe ( false ) ;
858+ expect ( schemaKeys . some ( ( k ) => k . startsWith ( 'createUser' ) ) ) . toBe ( true ) ;
859+ } ) ;
860+
861+ it ( 'slicing includedProcedures removes non-listed procedure args from components schemas' , async ( ) => {
862+ const client = await createTestClient ( procSchema ) ;
863+ const handler = new RPCApiHandler ( {
864+ schema : client . $schema ,
865+ queryOptions : { slicing : { includedProcedures : [ 'createUser' ] as any } } ,
866+ } ) ;
867+ const spec = await generateSpec ( handler ) ;
868+
869+ const schemaKeys = Object . keys ( spec . components ?. schemas ?? { } ) ;
870+ expect ( schemaKeys . some ( ( k ) => k . startsWith ( 'createUser' ) ) ) . toBe ( true ) ;
871+ expect ( schemaKeys . some ( ( k ) => k . startsWith ( 'getUser' ) ) ) . toBe ( false ) ;
872+ expect ( schemaKeys . some ( ( k ) => k . startsWith ( 'optionalSearch' ) ) ) . toBe ( false ) ;
873+ } ) ;
802874} ) ;
803875
804876describe ( 'RPC OpenAPI spec generation - respectAccessPolicies' , ( ) => {
0 commit comments