tsoa icon indicating copy to clipboard operation
tsoa copied to clipboard

Regression(?) of @tsoaModel deduplication since #1498

Open E-gy opened this issue 7 months ago • 2 comments

As far as i can tell seemingly since #1498, @tsoaModel has lost its meaning for dealing with duplicated model names, when using the js-doc annotation for respecifying types imported from libraries for TSOA.

This seems to be a follow-up on #1516.

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 following code has a duplicated type - ULID. Once imported from ulidx, and once declared in an purpose-built file and annotated with @tsoaModel. Since we have one and exactly one of the types with identical names with the annotation, we expect TSOA to use that annotation.

MinimalController.ts:

import { Controller, Get, Route} from '@tsoa/runtime';
import { ULID } from './apitypes.js';
import { RealGeo } from './RealGeo';

@Route('garbage/garbage/garbage')
export class GartbageController extends Controller {
	@Get('{stud}')
	public async getStuff(stud: ULID): Promise<RealGeo[]> {
		return [];
	}
}

apitypes.ts:

/**
 * ULID Crockford's base32 string representation.
 * See [ULID Spec](https://github.com/ulid/spec).
 * @pattern [0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}
 * @example "01ARZ3NDEKTSV4RRFFQ69G5FAV"
 * @tsoaModel
 */
export type ULID = string;

RealGeo.ts:

import { ULID } from 'ulidx';

export interface RealGeo {
    id: ULID;
}

Last version where this works correctly* (or at least generates any routes): 6.0.0-rc.2

As-in the routes are still built. It is worth noting that in 6.0.0-rc.2, building the spec with above code does not actually produce any specification what-so-ever, but the command does not print any errors either and simply exits successfully.

Current Behavior

Now take that same code to the latest version of TSOA, and run a route generation to get a following error:

Generate routes error.
 GenerateMetadataError: Found 2 different model definitions for model ULID: orig: [{"fileName":"/workspaces/ReducedExample/node_modules/ulidx/dist/types.d.ts","pos":32}], act: [{"fileName":"/workspaces/ReducedExample/src/api/apitypes.ts","pos":0}] 
 in 'GartbageController.getStuff'

First version where it breaks: 6.0.0-rc.5

Note that still once again running the spec generation produces no spec, and nothing on the error output. This and the above are identical to the current version (6.3.1).

Context (Environment)

Version of NodeJS: v22.4.0 (Reproduced in a node:22.4-alpine3.19 devcontainer)

  • Confirm you were using yarn not npm: all tested versions of TSOA taken from npm.

E-gy avatar Jul 08 '24 14:07 E-gy