lukeautry / tsoa

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

fix: Referencer, Name conflicts, Mapped unions, etc. #1498

Closed nemnandor closed 10 months ago

nemnandor commented 10 months ago

All Submissions:

Closing issues

closes #477 closes #623 closes #681 closes #1191 closes #1204 closes #1266 closes #1447 closes #1472

If this is a new feature submission:

Fixes:

I have solved locally some problems which are needed for my company. After that I read the TSOA commit guides, so some fixes maybe have no related issues.

  1. Namespaces: Every type should be stored with their full-path namespaced types. Even if the source code not uses this name. This reduces conflicts between types.
  2. Name conflicts: If every reference type name parts are uniq, then the full type name can be handled as uniq. In this type name, we need to sign the jsdoc params if exists, because its they can make differences in the result. Somehow the reference type names are transformed with an irreversible getRefTypeName(), here we need to check if the result name comes from the same original type names, or from more different names.
  3. Handling interfaces - namespaces - enums which have more than one declaration
  4. Keep jsdoc comments + defaults after mapping - as intellisense shows
  5. Do not use original definition in mapped types, because type can change.
  6. Accept unions, intersections, nulls, enums in mapped type.
  7. Fix referencer issues. TypeToTypeNode & TypeNodeToType functions are not exactly the inverse function of each other -> use the original types, and remove conversions.
  8. Do not name more complicated reference type internal parts as "any". - It is needed to recognize name conflicts.
  9. Better keyof handling
  10. Do not mark required if a field has a default value. (Not too relevant, but more beautiful)
  11. Default values from JSdoc uses the expected type. @default true is not a string, but a boolean.

Potential Problems With The Approach

I'm sure, that there are a lot of breaking changes.

Test plan

Added test type literals to the TestModel interface. Every literal checks one solved problem. The members represents one test case.

WoH commented 10 months ago

Can you take a look at CI? Let's start there.

WoH commented 10 months ago

LGTM, thanks for the PR and sorry for the time it took to review.