@@ -129,7 +129,7 @@ model Bar {
129
129
}
130
130
} ) ;
131
131
132
- it ( 'options' , async ( ) => {
132
+ it ( 'common options' , async ( ) => {
133
133
const { model, dmmf, modelFile } = await loadZModelAndDmmf ( `
134
134
plugin openapi {
135
135
provider = '${ normalizePath ( path . resolve ( __dirname , '../dist' ) ) } '
@@ -396,6 +396,39 @@ model User {
396
396
expect . arrayContaining ( [ 'role' , 'company' ] )
397
397
) ;
398
398
} ) ;
399
+
400
+ it ( 'works with mapped model name' , async ( ) => {
401
+ const { model, dmmf, modelFile } = await loadZModelAndDmmf ( `
402
+ plugin openapi {
403
+ provider = '${ normalizePath ( path . resolve ( __dirname , '../dist' ) ) } '
404
+ title = 'My Awesome API'
405
+ prefix = '/api'
406
+ modelNameMapping = {
407
+ User: 'myUser'
408
+ }
409
+ }
410
+
411
+ model User {
412
+ id String @id
413
+ posts Post[]
414
+ }
415
+
416
+ model Post {
417
+ id String @id
418
+ author User @relation(fields: [authorId], references: [id])
419
+ authorId String
420
+ }
421
+ ` ) ;
422
+
423
+ const { name : output } = tmp . fileSync ( { postfix : '.yaml' } ) ;
424
+ const options = buildOptions ( model , modelFile , output ) ;
425
+ await generate ( model , options , dmmf ) ;
426
+ console . log ( 'OpenAPI specification generated:' , output ) ;
427
+ const api = await OpenAPIParser . validate ( output ) ;
428
+ expect ( api . paths ?. [ '/api/myUser' ] ) . toBeTruthy ( ) ;
429
+ expect ( api . paths ?. [ '/api/user' ] ) . toBeFalsy ( ) ;
430
+ expect ( api . paths ?. [ '/api/post' ] ) . toBeTruthy ( ) ;
431
+ } ) ;
399
432
} ) ;
400
433
401
434
function buildOptions ( model : Model , modelFile : string , output : string , specVersion = '3.0.0' ) {
0 commit comments