routing-controllers-openapi
routing-controllers-openapi copied to clipboard
TypeError: Cannot read properties of undefined (reading 'split')
There are a bug in the generateSpec.ts file. like
const schema = getParamSchema(headersMeta) as oa.ReferenceObject
headers.push({
in: 'header',
name: schema.$ref.split('/').pop() || '',
required: isRequired(headersMeta, route),
schema,
})
const paramSchema = getParamSchema(queriesMeta) as oa.ReferenceObject
// the last segment after '/'
const paramSchemaName = paramSchema.$ref.split('/').pop() || ''
const currentSchema = schemas[paramSchemaName]
The getParamSchema function may return a empty object which result in an error. What's more, I change
// example1
name: schema.$ref.split('/').pop() || '',
// example2
const paramSchemaName = paramSchema.$ref.split('/').pop() || ''
to
// example1
name: (schema.$ref || '').split('/').pop() || '',
// example2
const paramSchemaName = (paramSchema.$ref || '').split('/').pop() || ''
And it works.
For me this error was caused because of 2 things:
- Using a
Partialtype - Using a destructured object
Both of these only caused issues when used in methods annotated with @Get. I'd guess it didn't happen on other HTTP methods, because those have bodies, instead of query params.