lukeautry / tsoa

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

Regression(?) of @tsoaModel deduplication since #1498 #1650

Open E-gy opened 2 months ago

E-gy commented 2 months ago

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

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)

pgerlich commented 2 months ago

We're also seeing this issue. Hoping to get some eyes on it? @lukeautry

ttrreevvoorr commented 1 month ago

+1