lukeautry / tsoa

Build OpenAPI-compliant REST APIs using TypeScript and Node
MIT License
3.48k stars 498 forks source link

Type Aliases not working when imported from ambient module #1653

Closed alexng353 closed 1 month ago

alexng353 commented 2 months ago

Sorting

Expected Behavior

I expect that in the following code snippets, tsoa will properly resolve the imports & types, generating the correct openapi schema on output.

// types.ts
/**
 * Stringified UUIDv4.
 * See [RFC 4112](https://tools.ietf.org/html/rfc4122)
 * @pattern [0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-4[0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}
 * @format uuid
 */
export type UUID = string;
// thing.controller.ts
import type { UUID } from "types.ts";

@Route("/api/v1/user/")
export class UserController extends Controller {
  @Get("/")
  @Security("jwt")
  async getUsers(
    @Query("userIds") userIds: UUID[],
  ): Promise<NonSensitiveUser[]> {
    const users = await db
      .select(defaultUserSelection)
      .from(Users)
      .where(inArray(Users.id, userIds));

    return users;
  }
}

Current Behavior

Tsoa errors while attempting to build and generate swagger for this code.

image
Full Error Message (plaintext)
```bash killing previous process Generate routes error. GenerateMetadataError: No declarations found for referenced type UUID. in 'UserController.getUsers' at /Users/alex/code/edubeyond/mono/2024-07/27-tsoa-postgres/node_modules/.pnpm/@tsoa+cli@6.4.0/node_modules/@tsoa/cli/dist/metadataGeneration/methodGenerator.js:104:23 at Array.map () at MethodGenerator.buildParameters (/Users/alex/code/edubeyond/mono/2024-07/27-tsoa-postgres/node_modules/.pnpm/@tsoa+cli@6.4.0/node_modules/@tsoa/cli/dist/metadataGeneration/methodGenerator.js:96:14) at MethodGenerator.Generate (/Users/alex/code/edubeyond/mono/2024-07/27-tsoa-postgres/node_modules/.pnpm/@tsoa+cli@6.4.0/node_modules/@tsoa/cli/dist/metadataGeneration/methodGenerator.js:66:33) at /Users/alex/code/edubeyond/mono/2024-07/27-tsoa-postgres/node_modules/.pnpm/@tsoa+cli@6.4.0/node_modules/@tsoa/cli/dist/metadataGeneration/controllerGenerator.js:46:41 at Array.map () at ControllerGenerator.buildMethods (/Users/alex/code/edubeyond/mono/2024-07/27-tsoa-postgres/node_modules/.pnpm/@tsoa+cli@6.4.0/node_modules/@tsoa/cli/dist/metadataGeneration/controllerGenerator.js:46:14) at ControllerGenerator.Generate (/Users/alex/code/edubeyond/mono/2024-07/27-tsoa-postgres/node_modules/.pnpm/@tsoa+cli@6.4.0/node_modules/@tsoa/cli/dist/metadataGeneration/controllerGenerator.js:35:27) at /Users/alex/code/edubeyond/mono/2024-07/27-tsoa-postgres/node_modules/.pnpm/@tsoa+cli@6.4.0/node_modules/@tsoa/cli/dist/metadataGeneration/metadataGenerator.js:210:41 at Array.map () error: "tsoa" exited with code 1 Failed to reload tsoa ```

Possible Solution

Steps to Reproduce

You can see this error by copying the provided code blocks.

Context (Environment)

Version of the library: ^6.4.0 Version of NodeJS: v20.15.0

Detailed Description

I am directly copying code from the docs, so I expect this to work properly.

Breaking change?

github-actions[bot] commented 1 month ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

victor-floor commented 1 week ago

I'm facing the same issue with an interface defined in a different file and used as the response.