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

Error, Multiple matching models found #79

Closed
myflowpl opened this issue Mar 12, 2017 · 12 comments
Closed

Error, Multiple matching models found #79

myflowpl opened this issue Mar 12, 2017 · 12 comments

Comments

@myflowpl
Copy link

I have this error when generating routes or swagger

There was a problem resolving type of 'FindForLocationResponse'.
Error: Multiple matching models found for referenced type FindForLocationResponse; please make model names unique.

It's true, i have two interfaces with the same name, but they are in different packages,
one is used internally by the service,
and the other in the controller (for tsoa router and swagger generation)

Is there a way to fis this error other then rename the interface ?

@amozh-op
Copy link
Contributor

@myflowpl I had the same issue with Account model. And the only way to workaround it was renaming the model.
The tricky thing for me was that i had only 1 Account in the project, but debugging helped me to figure out that the duplication happened because of Account model in TypeScript library.

Issue happens because TSOA uses TypeScript's Program.getSourceFiles() to generate metadata, which gives all the source files involved, including libraries.
see https://github.com/lukeautry/tsoa/blob/master/src/metadataGeneration/metadataGenerator.ts#L21
And when TSOA is trying to resolve model type and it finds more than 1 with the same name - it throws an error https://github.com/lukeautry/tsoa/blob/master/src/metadataGeneration/resolveType.ts#L304

I don't see an easy way to resolve this issue.

@myflowpl
Copy link
Author

@amozh thanks for deep explanation of the issue.
I also resolved the problem by renaming the model, right now as a good practice, i call all my models with suffix Model

Location => LocationModel LocationModelRequest, LocationModelResponse

After some time, when the model list got quite big, i found it easier to maintain and read the project structure with suffixes, so it was god workaround for me.

@Cidaas
Copy link

Cidaas commented Sep 18, 2017

I am also getting with @typings

Error: Multiple matching models found for referenced type Response; please make model names unique. Conflicts found: "/usr/local/lib/node_modules/tsoa/node_modules/typescript/lib/lib.d.ts"; "/Users/xxx/node_modules/@types/express-serve-static-core/index.d.ts".

How to fix this?

@lukeautry
Copy link
Owner

@isman-usoh I noticed you tagged this in progress - did you have a solution in the works?

@mellodev
Copy link

mellodev commented Oct 23, 2017

I'm running into the same issue as @Cidaas above, "Multiple matching models found" for basic typing definitions (String in this case). I had tsoa package version 1.3.3 but removed and replaced it with version 2.0.1 but still see the same error. Can anyone share suggestions for a workaround, please?

@isman-usoh

There was a problem resolving type of 'String'.
Error: Multiple matching models found for referenced type String; please make model names unique.
Conflicts found: "/mnt/s/Development/complex-reserve-tsoa/node_modules/typescript/lib/lib.d.ts"; "/mnt/s/Development/complex-reserve-tsoa/node_modules/typescript/lib/lib.d.ts".

@lukeautry
Copy link
Owner

Check out the latest release (2.0.1+). While there isn't a true fix, there's now a way to ignore directories for TypeScript scanning, e.g. in tsoa.json:

{
  "swagger": {
       ...
  },
  "routes": {
      ...
  },
  "ignore": [
    "**/node_modules/**"
  ]
}

My guess is that most folks only want to expose domain-specific models, not interfaces/classes from external libs. That may not be totally true. In any case, this will help you resolve the above issue.

Let me know what you think.

@mellodev
Copy link

mellodev commented Oct 23, 2017

@lukeautry Thanks for the update. That is a step closer and may fully fix the issue for some. In my case I have another bug that has came up, probably need it's own ticket - the error is regarding use of String types in my models. Looks like we need to add support for String Type in resolveType.js.

Error: No matching model found for referenced type String.

This is thrown from src/metadataGeneration/resolveType.ts (my models have String types in them). This issue is similar to the Buffer issue reported here: #38.

I appear to have solved the issue by mapping String to string in resolveType.ts around line 76. Is this the best solution?

    if (typeReference.typeName.text === 'String') {
      return { dataType: 'string' } as Tsoa.Type;
    }

In the mean time I've forked the module for my own use with this fix, but I think this should be handled in tsoa. Edit - I've submitted PR #172

@Cidaas
Copy link

Cidaas commented Nov 29, 2017

I am also getting error for Request object

Error: Multiple matching models found for referenced type Request; please make model names 
unique. Conflicts found: 
"/usr/local/lib/node_modules/tsoa/node_modules/typescript/lib/lib.d.ts";
 "/Users/../Projects/.../node_modules/@types/express-serve-static-core/index.d.ts".

My config file. I am using "tsoa": "^2.0.1"

{
    "swagger": {
        "outputDirectory": "./dist",
        "entryFile": "./src/Routers/entryfile.ts",
        "basePath": "/v1",
        "name": "vimal",
        "description": "vimal"
    },
    "ignore": [
        "**/node_modules/**"
    ]
}

@lukeautry
Copy link
Owner

See the @tsoamodel feature (new): https://github.com/lukeautry/tsoa#dealing-with-duplicate-model-names

@linxiaowu66
Copy link

@lukeautry

Hi, I saw your feature is only to resolve the same model name, but how can i resolve the same namespace definition in different files ?

Thanks in advance.

@NanoMeko
Copy link

NanoMeko commented Apr 12, 2020

Any solution to this? I've tried ignoring the paths in the tsoa config as well as using the @tsoaModel decorator.

UnhandledPromiseRejectionWarning: Error: Multiple matching models found for referenced type Model; please make model names unique. Conflicts found: "/Users/..../node_modules/sequelize/types/lib/model.d.ts"; "/Users/...../node_modules/sequelize-typescript/dist/model/model/model.d.ts".

@davidlj95
Copy link

See the @tsoamodel feature (new): https://github.com/lukeautry/tsoa#dealing-with-duplicate-model-names

Link moved to:
https://tsoa-community.github.io/docs/faq.html#dealing-with-duplicate-model-names

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

No branches or pull requests

8 participants