Coder Social home page Coder Social logo

Comments (12)

lukeautry avatar lukeautry commented on April 28, 2024 11

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.

from tsoa.

amozh-op avatar amozh-op commented on April 28, 2024 2

@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.

from tsoa.

linxiaowu66 avatar linxiaowu66 commented on April 28, 2024 2

@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.

from tsoa.

NanoMeko avatar NanoMeko commented on April 28, 2024 2

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".

from tsoa.

davidlj95 avatar davidlj95 commented on April 28, 2024 2

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

from tsoa.

 avatar commented on April 28, 2024 1

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?

from tsoa.

lukeautry avatar lukeautry commented on April 28, 2024 1

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

from tsoa.

myflowpl avatar myflowpl commented on April 28, 2024

@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.

from tsoa.

mellodev avatar mellodev commented on April 28, 2024

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".

from tsoa.

mellodev avatar mellodev commented on April 28, 2024

@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

from tsoa.

 avatar commented on April 28, 2024

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/**"
    ]
}

from tsoa.

lukeautry avatar lukeautry commented on April 28, 2024

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

from tsoa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.