Implementation of Drizzle and tsoa

Hello, I am trying implementing Drizzle but I also want to implement tsoa for auto generating documentation. Do you guys have any idea how to make the model schema with tsoa annotations? https://tsoa-community.github.io/docs/descriptions.html
Descriptions | tsoa
A VitePress site
3 Replies
rizaldiariif
rizaldiariifOP16mo ago
right now here is my code, how do I give descriptions for the Model and each of the columns?
// src\api\auth\sub-api\user\model\entity\user.entity.ts
import { pgTable, serial, varchar, pgEnum } from "drizzle-orm/pg-core";
import { InferModel } from "drizzle-orm";

const statusEnum = pgEnum("status", ["Happy", "Sad"]);

const users = pgTable("users", {
id: serial("id").primaryKey(),
name: varchar("name", { length: 256 }),
email: varchar("email", { length: 256 }),
status: statusEnum("status"),
phone_number: varchar("phone_number", { length: 256 }),
});

/**
* User objects allow you to associate actions performed
* in the system with the user that performed them.
* The User object contains common information across
* every user in the system regardless of status and role.
*/
export type User = InferModel<typeof users>;
export type NewUser = InferModel<typeof users, "insert">;
export type SelectUser = InferModel<typeof users, "select">;
// src\api\auth\sub-api\user\model\entity\user.entity.ts
import { pgTable, serial, varchar, pgEnum } from "drizzle-orm/pg-core";
import { InferModel } from "drizzle-orm";

const statusEnum = pgEnum("status", ["Happy", "Sad"]);

const users = pgTable("users", {
id: serial("id").primaryKey(),
name: varchar("name", { length: 256 }),
email: varchar("email", { length: 256 }),
status: statusEnum("status"),
phone_number: varchar("phone_number", { length: 256 }),
});

/**
* User objects allow you to associate actions performed
* in the system with the user that performed them.
* The User object contains common information across
* every user in the system regardless of status and role.
*/
export type User = InferModel<typeof users>;
export type NewUser = InferModel<typeof users, "insert">;
export type SelectUser = InferModel<typeof users, "select">;
alexblokh
alexblokh16mo ago
I think you should create an issue on GH with link to this thread and we'll have a look when we have time doesn't seem like a quick solution
baronnoraz
baronnoraz11mo ago
I was curious if an issue ever got created, so that I could follow it. I am also lookin into how to update descriptions, but I'm having another problem to and was curious if @rizaldiariif had encountered it since they're using tsoa. When I do the following export type UserDbType = typeof user.$inferSelect then in a separate models packing in my monorepo, I do export type User = Pick<UserDbType, 'id', 'email'> tsoa generates my swagger documentation. But if I change the model to be export type User = UserDbType I get an error when generating the documentation that says
There was a problem resolving type of 'UserDbType'.
There was a problem resolving type of 'User'.
Generate swagger error.
GenerateMetadataError: Unknown type: TypeQuery
There was a problem resolving type of 'UserDbType'.
There was a problem resolving type of 'User'.
Generate swagger error.
GenerateMetadataError: Unknown type: TypeQuery
Have you ever had that problem? Actually my issue appears to be between TSOA and Zod, https://github.com/lukeautry/tsoa/issues/1256
GitHub
Support zod's infer type · Issue #1256 · lukeautry/tsoa
When using a Zod validator and then passing it to TSOA, it throws this error: Error: No matching model found for referenced type infer. Types File export const MyValidator = z.object({ result: z.ob...
Want results from more Discord servers?
Add your server