tsoa
tsoa copied to clipboard
Using Prisma with TSOA
Sorting
-
I'm submitting a ...
- [ ] bug report
- [ x ] feature request
- [ ] support request
-
I confirm that I
- [ x ] used the search to make sure that a similar issue hasn't already been submit
Note: There is a similar issue, but it was not natively fixed on tsoa itself but used a third-party package. (https://github.com/lukeautry/tsoa/issues/1481)
Expected Behavior
import { CoreDatabaseService } from './databaseService';
import type { admin_roles } from '@prisma/client; // ideally reads the type from prisma itself
export class CoreService {
constructor(private coreDatabaseService: CoreDatabaseService) {}
async getAdminRoles(): Promise<admin_roles[] | null> {
try {
const roles = await this.coreDatabaseService.admin_roles.findMany();
console.log(roles);
return roles;
} catch (error) {
console.log(error);
return null;
}
}
}
Current Behavior
import { CoreDatabaseService } from './databaseService';
// i have to recreate the types in an interface, which might be out of sync from prisma if multiple people are working on it
interface admin_roles {
id: number,
role_name: string
}
export class CoreService {
constructor(private coreDatabaseService: CoreDatabaseService) {}
async getAdminRoles(): Promise<admin_roles[] | null> {
try {
const roles = await this.coreDatabaseService.admin_roles.findMany();
console.log(roles);
return roles;
} catch (error) {
console.log(error);
return null;
}
}
}
An error is shown stating that tsoa is unable to reference the type admin_roles
from prisma client
Generate routes error.
GenerateMetadataError: No declarations found for referenced type admin_roles.
at TypeResolver.getModelTypeDeclarations (/Users/annabel/Work/rapidzpay-tsoa/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:871:62)
at TypeResolver.calcRefTypeName (/Users/annabel/Work/rapidzpay-tsoa/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:536:39)
at TypeResolver.calcTypeReferenceTypeName (/Users/annabel/Work/rapidzpay-tsoa/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:712:34)
at TypeResolver.getReferenceType (/Users/annabel/Work/rapidzpay-tsoa/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:721:35)
at TypeResolver.resolveTypeReferenceNode (/Users/annabel/Work/rapidzpay-tsoa/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:468:21)
at TypeResolver.resolve (/Users/annabel/Work/rapidzpay-tsoa/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:293:21)
at TypeResolver.resolve (/Users/annabel/Work/rapidzpay-tsoa/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:81:119)
at TypeResolver.resolveTypeReferenceNode (/Users/annabel/Work/rapidzpay-tsoa/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:458:93)
at TypeResolver.resolve (/Users/annabel/Work/rapidzpay-tsoa/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:293:21)
at MethodGenerator.Generate (/Users/annabel/Work/rapidzpay-tsoa/node_modules/@tsoa/cli/dist/metadataGeneration/methodGenerator.js:62:78)
Possible Solution
allow tsoa's typeresolver to be able to read the prisma types that have been generated in the schema?
Steps to Reproduce
Context (Environment)
Version of the library: 6.5.0 Version of NodeJS: 20.17.0
Note: i was using npm for this