Skip to content

TypeError: Cannot read properties of undefined (reading 'split') #141

@lyf7

Description

@lyf7

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions