-
Notifications
You must be signed in to change notification settings - Fork 20
Description
Description
The package fails to recognize and resolve TypeScript types that use utility types such as Awaited and ReturnType. This results in the OpenAPI schema generation failing to properly document response types.
Steps to Reproduce
-
Code Example
// app/api/users/[id]/name/route.ts import { NextRequest, NextResponse } from "next/server"; import { getUserNameById } from "./route.utils"; /** * Get User by ID * @description Retrieves a user's profile information * @pathParams UserIdParam * @response UserNameByIdResponse * @openapi */ export async function GET( request: NextRequest, { params }: { params: { id: string } } ) { const user = await getUserNameById(params.id); return NextResponse.json(user); }
// app/api/users/[id]/name/route.utils.ts export const getUserNameById = async (id: string) => { // Simulate fetching user data from a database const result = await new Promise<[{ name: string }]>((resolve) => { return resolve([ { name: "John Doe", }, ]); }); // Do some more processing if needed return result.map(({ name }) => ({ name: name, firstName: name.split(" ")[0], }))[0]; }; type UserNameByIdResponse = Awaited<ReturnType<typeof getUserNameById>>;
-
Generate OpenAPI schema
npx next-openapi-gen generate
Actual Behavior
The OpenAPI schema generation fails to recognize UserNameByIdResponse type properly, leading to incomplete or incorrect documentation for the API response in the openapi.json
{
"components": {
"schemas": {
"UserNameByIdResponse": {}
}
}
}Expected Behavior
The OpenAPI schema generation should correctly resolve and document the UserNameByIdResponse type, reflecting its actual structure in the generated schema in openapi.json
{
"components": {
"schemas": {
"UserNameByIdResponse": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"firstName": {
"type": "string"
}
}
}
}
}
}Additional Context
This is a common pattern in TypeScript applications where the source of truth for types is the implementation (function signature), not separate type definitions. Supporting this would greatly improve the developer experience and reduce type duplication.