Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lyf7 opened this issue Jul 6, 2023 · 1 comment
Open

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

lyf7 opened this issue Jul 6, 2023 · 1 comment

Comments

@lyf7
Copy link

lyf7 commented Jul 6, 2023

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.

@martinmeow
Copy link

For me this error was caused because of 2 things:

  • Using a Partial type
  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants