Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type Aliases not working when imported from ambient module #1653

Closed
2 of 4 tasks
alexng353 opened this issue Jul 29, 2024 · 2 comments
Closed
2 of 4 tasks

Type Aliases not working when imported from ambient module #1653

alexng353 opened this issue Jul 29, 2024 · 2 comments
Labels

Comments

@alexng353
Copy link

Sorting

  • I'm submitting a ...

    • bug report
    • feature request
    • support request
  • I confirm that I

    • used the search to make sure that a similar issue hasn't already been submit

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)
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 (<anonymous>)
    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 (<anonymous>)
    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 (<anonymous>)
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

  • Confirm you were using yarn not npm: [x]

Detailed Description

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

Breaking change?

Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants