tsoa with nx integrated repo - No declarations found referenced type

332 Views Asked by At

I have an nx integrated monorepo containing 2 packages:

apps/mtb-api
  containing the express api
  containing tsoa for building the swagger doc
  tsconfig.json
libs/mtb-requests
  Containing interface definitions to be used in the api
  tsconfig.json
tsconfig.base.json\`

When I try to run ...

cd apps/api && npx tsoa spec

I do get the following error

GenerateMetadataError: No declarations found for referenced type ISwitchTenantResponse.
at TypeResolver.getModelTypeDeclaration (C:\\Source\\mtb-v3\\node_modules@tsoa\\cli\\dist\\metadataGeneration\\typeResolver.js:758:19)
at TypeResolver.typeArgumentsToContext (C:\\Source\\mtb-v3\\node_modules@tsoa\\cli\\dist\\metadataGeneration\\typeResolver.js:886:34)
at TypeResolver.getReferenceType (C:\\Source\\mtb-v3\\node_modules@tsoa\\cli\\dist\\metadataGeneration\\typeResolver.js:579:14)
at TypeResolver.resolve (C:\\Source\\mtb-v3\\node_modules@tsoa\\cli\\dist\\metadataGeneration\\typeResolver.js:390:36)
at C:\\Source\\mtb-v3\\node_modules@tsoa\\cli\\dist\\metadataGeneration\\typeResolver.js:132:118
at Array.reduce (\<anonymous\>)
at TypeResolver.resolve (C:\\Source\\mtb-v3\\node_modules@tsoa\\cli\\dist\\metadataGeneration\\typeResolver.js:131:18)
at TypeResolver.resolve (C:\\Source\\mtb-v3\\node_modules@tsoa\\cli\\dist\\metadataGeneration\\typeResolver.js:380:118)
at MethodGenerator.Generate (C:\\Source\\mtb-v3\\node_modules@tsoa\\cli\\dist\\metadataGeneration\\methodGenerator.js:39:78)
at C:\\Source\\mtb-v3\\node_modules@tsoa\\cli\\dist\\metadataGeneration\\controllerGenerator.js:46:41

My tsconfig.base.json at the root file is the following:

{
  "compileOnSave": false,
  "compilerOptions": {
    "rootDir": ".",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noImplicitAny": true,
    "importHelpers": true,
    "target": "es2015",
    "module": "esnext",
    "lib": ["es2020", "dom"],
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "baseUrl": ".",
    "resolveJsonModule": true,
    "paths": {
      "@mtb/mtb-requests": ["libs/mtb-requests/src/index.ts"]
    }
  },
  "exclude": ["node_modules", "tmp"]
}

my tsconfig.json for the api is the followoing

{
  "extends": "../../tsconfig.base.json",
  "files": [],
  "include": [],
  "references": [
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.spec.json"
    }
  ],
  "compilerOptions": {
    "esModuleInterop": true,
  }
}

And fynally the tsconfig.json for the mtb-requests library

{
  "extends": "../../tsconfig.base.json",
  "compilerOptions": {
    "module": "commonjs"
  },
  "files": [],
  "include": [],
  "references": [
    {
      "path": "./tsconfig.lib.json"
    },
    {
      "path": "./tsconfig.spec.json"
    }
  ]
}

In the mtb-api application I have a tsoa.json

{
  "entryFile": "src/index.ts",
  "noImplicitAdditionalProperties": "throw-on-extras",
  "spec": {
    "outputDirectory": "public",
    "specVersion": 3
  }
}
1

There are 1 best solutions below

0
On

Do this:

https://tsoa-community.github.io/docs/path-mapping.html#path-mapping

This is mine for example:

{
  "entryFile": "apps/api/src/main.ts",
  "noImplicitAdditionalProperties": "throw-on-extras",
  "spec": {
    "outputDirectory": "apps/api/src",
    "specVersion": 3
  },
  "compilerOptions": {
    "paths": {
      "shared": ["library/shared/src/index.ts"]
    }
  }
}