tsoa icon indicating copy to clipboard operation
tsoa copied to clipboard

path-mapping for interface not deeply

Open liaojiwei666 opened this issue 2 years ago • 8 comments

Sorting

  • I'm submitting a ...

    • [x] bug report
    • [ ] feature request
    • [ ] support request
  • I confirm that I

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

Expected Behavior

The path-mapping that I set up on tsoa.config.compilerOptions could mapping correctly.

{
  "entryFile": "src/index.ts",
  "noImplicitAdditionalProperties": "throw-on-extras",
  "controllerPathGlobs": ["src/backyard/controller/*"],
  "spec": {
    "outputDirectory": "build/backyard",
    "specVersion": 3,
  },
  "routes": {
    "basePath": "/api/v2/backyard",
    "routesDir": "build/backyard",
    "authenticationModule": "./authentication.ts"
  },
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"],
      "@public/*": ["src/public/*"],
      "@backyard/*": ["src/backyard/*"]
    }
  }
}
import { Controller, Get, Route } from "tsoa";
import { queryAllListingsInOrder } from "@/src/query";
import { ListingDetailDto } from "@/src/types/listing"; <-- This path could not be found

@Route("listing")
export class ListingController extends Controller {
  @Get("")
  public async getListings(): Promise<{
    listings: Array<ListingDetailDto>;
  }> {
    const listings = await queryAllListingsInOrder({
      page: 1,
      pageSize: 6,
    }).then((res) => res.payload);
    return {
      listings,
    };
  }
}

Current Behavior

The tsoa spec-and-routes will throw error.

Generate routes error.
 GenerateMetadataError: No declarations found for referenced type ListingDetailDto.
    at TypeResolver.getModelTypeDeclaration (/Users/liaojiwei/Desktop/funwoo/backyard-api-oas/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:755:19)
    at TypeResolver.typeArgumentsToContext (/Users/liaojiwei/Desktop/funwoo/backyard-api-oas/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:880:34)
    at TypeResolver.getReferenceType (/Users/liaojiwei/Desktop/funwoo/backyard-api-oas/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:576:14)
    at TypeResolver.resolve (/Users/liaojiwei/Desktop/funwoo/backyard-api-oas/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:389:36)
    at TypeResolver.resolve (/Users/liaojiwei/Desktop/funwoo/backyard-api-oas/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:374:128)
    at /Users/liaojiwei/Desktop/funwoo/backyard-api-oas/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:131:118
    at Array.reduce (<anonymous>)
    at TypeResolver.resolve (/Users/liaojiwei/Desktop/funwoo/backyard-api-oas/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:130:18)
    at TypeResolver.resolve (/Users/liaojiwei/Desktop/funwoo/backyard-api-oas/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:379:118)
    at MethodGenerator.Generate (/Users/liaojiwei/Desktop/funwoo/backyard-api-oas/node_modules/@tsoa/cli/dist/metadataGeneration/methodGenerator.js:39:78)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Possible Solution

The currently possible solution, but that was not good enough.

{
  "entryFile": "src/index.ts",
  "noImplicitAdditionalProperties": "throw-on-extras",
  "controllerPathGlobs": ["src/backyard/controller/*"],
  "spec": {
    "outputDirectory": "build/backyard",
    "specVersion": 3,
    "securityDefinitions": {
      "FUNWOO_AUTH": {
        "type": "apiKey",
        "name": "x-funwoo-token",
        "in": "headers"
      }
    }
  },
  "routes": {
    "basePath": "/api/v2/backyard",
    "routesDir": "build/backyard",
    "authenticationModule": "./authentication.ts"
  },
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"],
      "@/src/types/*": ["src/types/*"], <-- add the deep path
      "@public/*": ["src/public/*"],
      "@backyard/*": ["src/backyard/*"]
    }
  }
}

Context (Environment)

Version of the library: v4.0.0 Version of NodeJS: v16.13.0

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

liaojiwei666 avatar May 17 '22 08:05 liaojiwei666

Hello there liaojiwei666 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

github-actions[bot] avatar May 17 '22 08:05 github-actions[bot]

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

github-actions[bot] avatar Jun 17 '22 00:06 github-actions[bot]

Is there any known solution to this?

I am running into the same problem.

ao-Barbosa avatar Jan 29 '23 20:01 ao-Barbosa

Would you like to provide a PR?

WoH avatar Jan 29 '23 20:01 WoH

This is assuming you tried **/* and tsoa differs from tsc behaviour.

WoH avatar Jan 29 '23 20:01 WoH

Bump this, same issue

lounging-lizard avatar Aug 10 '23 14:08 lounging-lizard

Do you want to send a PR to fix this?

WoH avatar Aug 14 '23 14:08 WoH

Ran into this issue, Same scenario. Why can't it resolve in the first place?

RohitRox avatar Feb 21 '24 06:02 RohitRox