-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Description:
Problem
When a user explicitly defined a plural interface (e.g., Users) alongside its singular counterpart (User), two bugs
occurred:
Routing (findTypeForUrl):
URL /users was always singularized to "user" → "User" before the typeMap lookup. This made any user-defined plural
interface (e.g., Users) permanently unreachable — the router would never match it regardless of its definition.
OpenAPI spec (generateOpenAPISpec):
Both User and Users would independently generate a path for /users. The result was order-dependent: whichever
interface was processed last would overwrite the other's definition in the spec.
Fix
src/utils/typeMapping.ts — findTypeForUrl:
Before falling back to singularization, the function now checks whether the PascalCase form of the URL segment (e.g.,
"Users" from /users) exists directly in the typeMap. If it does, that interface is used as-is with isArray: false,
honoring the user's explicit definition.
src/core/swagger.ts — generateOpenAPISpec:
When auto-generating the plural path for a singular interface (e.g., /users for User), the function now skips that
generation if a corresponding user-defined plural interface (e.g., Users) is already present in the typeMap. The
explicit interface's own path generation handles it instead.
Behavior after fix
| TypeMap contains | GET /users | GET /user |
|---|---|---|
| User only | Array of User | Single User |
| Users only | Single Users | 404 |
| User + Users | Single Users (user wins) | Single User |