Skip to content

fix: user-defined plural interfaces now take priority over auto-generated plural routes #14

@Many0nne

Description

@Many0nne

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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions