Library version: 5.0.0
Node version: 20.12.1
Description
When using the @QueryParams() decorator to inject a parameter of type Object, the OpenAPI generation crashes. The error occurs in generateSpec.js, specifically in the getParamSchema() function. At the end of this function, when type.name === 'Object', no $ref is assigned. As a result, the getQueryParams() function (line 125) attempts to reference an undefined schema and crashes the process.
The following line: const paramSchemaName = paramSchema.$ref.split('/').pop() || ''; causes the crash because paramSchema.$ref is undefined.
Steps to Reproduce
-
Define a controller route like this:
@Get('/some-route')
someAction(@QueryParams() query: Object) { // or @QueryParams() query: any
// ...
}
-
Call routingControllersToSpec(...) to generate the OpenAPI schema.
-
The generator crashes due to $ref being undefined for the Object-typed query parameter.
Expected Behavior
When encountering a query parameter of a generic Object type - provide a default fallback schema (e.g. type: 'object'), or
Additional Context / Workarounds
- There's an older issue around parsing
@QueryParams() in the repository, but it refers to ignoring multiple query params—not this crash behavior ([github.com][1], [npmjs.com][2]).
- Providing a class-based DTO for query parameters (with decorators like
@IsInt(), etc.) works safely and avoids crashes.
Proposed Fix
In getParamSchema():
- Detect when
type.name === 'Object'.
In getQueryParams():
- Use guard clauses to check if
paramSchema.$ref is defined before attempting to split it.
- Or use
?. to safely access paramSchema.$ref. like this: const paramSchemaName = paramSchema.$ref?.split('/').pop() || '';
Another Issue:
In the 'OpenApi.js' file, the isSchemaObject function may also cause a crash when the schema is undefined. This can happen if the schema is not properly defined or if the type is not recognized.
Proposed Fix for isSchemaObject
In OpenApi.js, modify the isSchemaObject function to handle undefined schemas gracefully:
function isSchemaObject(schema) {
return schema && typeof schema === "object" && !Array.isArray(schema);
}
Library version: 5.0.0
Node version: 20.12.1
Description
When using the
@QueryParams()decorator to inject a parameter of typeObject, the OpenAPI generation crashes. The error occurs ingenerateSpec.js, specifically in thegetParamSchema()function. At the end of this function, whentype.name === 'Object', no$refis assigned. As a result, thegetQueryParams()function (line 125) attempts to reference an undefined schema and crashes the process.The following line:
const paramSchemaName = paramSchema.$ref.split('/').pop() || '';causes the crash becauseparamSchema.$refis undefined.Steps to Reproduce
Define a controller route like this:
Call
routingControllersToSpec(...)to generate the OpenAPI schema.The generator crashes due to
$refbeing undefined for theObject-typed query parameter.Expected Behavior
When encountering a query parameter of a generic
Objecttype - provide a default fallback schema (e.g.type: 'object'), orAdditional Context / Workarounds
@QueryParams()in the repository, but it refers to ignoring multiple query params—not this crash behavior ([github.com][1], [npmjs.com][2]).@IsInt(), etc.) works safely and avoids crashes.Proposed Fix
In
getParamSchema():type.name === 'Object'.In
getQueryParams():paramSchema.$refis defined before attempting to split it.?.to safely accessparamSchema.$ref. like this:const paramSchemaName = paramSchema.$ref?.split('/').pop() || '';Another Issue:
In the 'OpenApi.js' file, the
isSchemaObjectfunction may also cause a crash when theschemaisundefined. This can happen if the schema is not properly defined or if the type is not recognized.Proposed Fix for
isSchemaObjectIn
OpenApi.js, modify theisSchemaObjectfunction to handle undefined schemas gracefully: