lukeautry / tsoa

Build OpenAPI-compliant REST APIs using TypeScript and Node
MIT License
3.42k stars 489 forks source link

PR 1498 break generating spec or routes #1516

Closed eungkyu closed 7 months ago

eungkyu commented 9 months ago

Sorting

Expected Behavior

// src/TestController.ts
import { Body, Controller, Post, Route } from "tsoa";

type PostBody = {
  arg1: string;
};

@Route("test")
export class TestController extends Controller {
  @Post("/post")
  public post(@Body() body: PostBody) {
    return "ok";
  }
}
// src/Test2Controller.ts
import { Body, Controller, Post, Route } from "tsoa";

type PostBody = {
  arg2: string;
};

@Route("test2")
export class Test2Controller extends Controller {
  @Post("/post")
  public post(@Body() body: PostBody) {
    return "ok";
  }
}

If I use @tsoa/cli@6.0.0-rc.3, tsoa spec runs without error.

sample: https://codesandbox.io/p/devbox/tsoa-project-forked-y3vmtd

Current Behavior

If I use @tsoa/cli@6.0.0-rc.5, tsoa spec fails like followings

sample: https://codesandbox.io/p/devbox/tsoa-project-84ng5t

$ npx tsoa spec  
Generate swagger error.
 GenerateMetadataError: Found 2 different model definitions for model PostBody: orig: [{"fileName":"src/TestController.ts","pos":53}], act: [{"fileName":"src/Test2Controller.ts","pos":53}] 
 in 'Test2Controller.post'
    at /workspaces/workspace/node_modules/@tsoa/cli/dist/metadataGeneration/methodGenerator.js:104:23
    at Array.map (<anonymous>)
    at MethodGenerator.buildParameters (/workspaces/workspace/node_modules/@tsoa/cli/dist/metadataGeneration/methodGenerator.js:96:14)
    at MethodGenerator.Generate (/workspaces/workspace/node_modules/@tsoa/cli/dist/metadataGeneration/methodGenerator.js:66:33)
    at /workspaces/workspace/node_modules/@tsoa/cli/dist/metadataGeneration/controllerGenerator.js:46:41
    at Array.map (<anonymous>)
    at ControllerGenerator.buildMethods (/workspaces/workspace/node_modules/@tsoa/cli/dist/metadataGeneration/controllerGenerator.js:46:14)
    at ControllerGenerator.Generate (/workspaces/workspace/node_modules/@tsoa/cli/dist/metadataGeneration/controllerGenerator.js:35:27)
    at /workspaces/workspace/node_modules/@tsoa/cli/dist/metadataGeneration/metadataGenerator.js:210:41
    at Array.map (<anonymous>)

Possible Solution

I think https://github.com/lukeautry/tsoa/pull/1498 caused the problem because Found 2 different model definitions... error message is added at this PR.

Steps to Reproduce

in https://codesandbox.io/p/devbox/tsoa-project-84ng5t

run npx tsoa spec or npx tsoa routes

Context (Environment)

Version of the library: 6.0.0-rc.5 Version of NodeJS: 18

Detailed Description

Please see codesandbox examples.

Breaking change?

WoH commented 8 months ago

Did it uncover a bug or create a bug? FWIW I think this was a bug before that is now fixed

eungkyu commented 8 months ago

Did it uncover a bug or create a bug? FWIW I think this was a bug before that is now fixed

type PostBody of TestController.ts and type PostBody of Test2Controller.ts are not the same type. If it is not a bug, all of the non-exported internal type must have different name. Is it right?

WoH commented 8 months ago

All the exposed interfaces must have a different name.

github-actions[bot] commented 7 months ago

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