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

Cannot read properties of undefined (reading 'type') Oas.ts:80:33 #1575

Open
RichAyotte opened this issue Feb 24, 2025 · 8 comments
Open

Cannot read properties of undefined (reading 'type') Oas.ts:80:33 #1575

RichAyotte opened this issue Feb 24, 2025 · 8 comments
Labels
bug Something isn't working

Comments

@RichAyotte
Copy link

RichAyotte commented Feb 24, 2025

What version of kubb is running?

3.6.0

What kind of platform do you use?

Linux

How does your kubb.config.ts config look like

import { defineConfig } from '@kubb/core'
import { pluginMsw } from '@kubb/plugin-msw'
import { pluginOas } from '@kubb/plugin-oas'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginVueQuery } from '@kubb/plugin-vue-query'
import { pluginZod } from '@kubb/plugin-zod'

export default defineConfig(() => {
	return {
		name: 'internal-api',
		input: {
			path: 'https://api.payman.dev/api/v3/api-docs',
		},
		output: {
			barrelType: 'named',
			clean: true,
			extension: {
				'.ts': '',
			},
			path: './src/generated',
		},
		plugins: [
			pluginOas({
				output: {
					path: 'schemas',
					barrelType: false,
				},
			}),
			pluginTs({
				enumSuffix: '',
				enumType: 'literal',
				output: {
					path: 'types',
					barrelType: false,
				},
				unknownType: 'unknown',
			}),
			pluginVueQuery({
				client: {
					importPath: '@/utils/paymanClient',
				},
				infinite: {
					queryParam: 'page',
					cursorParam: 'nextPage',
				},
				output: {
					path: 'composables',
					barrelType: false,
				},
				paramsType: 'object',
				pathParamsType: 'object',
				parser: 'zod',
			}),
			pluginZod({
				output: {
					path: 'zod',
					barrelType: false,
				},
				typed: false,
				unknownType: 'unknown',
				inferred: true,
			}),
			pluginMsw({
				output: {
					path: 'mocks',
					barrelType: false,
				},
				handlers: true,
			}),
		],
	}
})

Swagger/OpenAPI file?

https://api.payman.dev/api/v3/api-docs

What version of external packages are you using(@tanstack-query, MSW, React, Vue, ...)

{
	"type": "module",
	"dependencies": {
		"@amplitude/analytics-browser": "^2.11.12",
		"@dinero.js/calculator-bigint": "^2.0.0-alpha.14",
		"@dinero.js/currencies": "^2.0.0-alpha.14",
		"@growthbook/growthbook": "^1.4.1",
		"@intercom/messenger-js-sdk": "^0.0.14",
		"@quasar/extras": "^1.16.17",
		"@stripe/connect-js": "^3.3.21",
		"@stripe/stripe-js": "^5.6.0",
		"@tanstack/vue-query": "^5.66.9",
		"@vue-stripe/vue-stripe": "^4.5.0",
		"@vueuse/core": "^12.7.0",
		"@zxcvbn-ts/core": "^3.0.4",
		"@zxcvbn-ts/language-common": "^3.0.4",
		"@zxcvbn-ts/language-en": "^3.0.2",
		"date-fns": "^4.1.0",
		"dinero.js": "^2.0.0-alpha.14",
		"eslint-plugin-package-json": "^0.26.0",
		"js-cookie": "^3.0.5",
		"jwt-decode": "^4.0.0",
		"ky": "^1.7.5",
		"lodash-es": "^4.17.21",
		"pinia": "^3.0.1",
		"pinia-plugin-persistedstate": "^4.2.0",
		"qrcode": "^1",
		"qrcode.vue": "^3.6.0",
		"quasar": "^2.17.7",
		"register-service-worker": "^1.7.2",
		"vue": "^3.5.13",
		"vue-component-type-helpers": "^2.2.4",
		"vue-markdown-render": "^2.2.1",
		"vue-router": "^4.5.0",
		"zod": "^3.24.2"
	},
	"devDependencies": {
		"@biomejs/biome": "1.9.4",
		"@eslint/js": "^9.21.0",
		"@happy-dom/global-registrator": "^17.1.4",
		"@kubb/cli": "^3.6.0",
		"@kubb/core": "^3.6.0",
		"@kubb/plugin-msw": "^3.6.0",
		"@kubb/plugin-oas": "^3.6.0",
		"@kubb/plugin-ts": "^3.6.0",
		"@kubb/plugin-vue-query": "^3.6.0",
		"@kubb/plugin-zod": "^3.6.0",
		"@quasar/app-vite": "^2.1.1",
		"@stoplight/spectral-core": "^1.19.4",
		"@stoplight/spectral-rulesets": "^1.21.3",
		"@total-typescript/ts-reset": "^0.6.1",
		"@types/bun": "^1.2.3",
		"@types/eslint__js": "^9.14.0",
		"@types/js-cookie": "^3.0.6",
		"@types/lodash-es": "^4.17.12",
		"@typescript-eslint/eslint-plugin": "^8.24.1",
		"@typescript-eslint/parser": "^8.24.1",
		"ajv": "^8.17.1",
		"autoprefixer": "^10.4.20",
		"eslint": "^9.21.0",
		"eslint-config-prettier": "^10.0.1",
		"eslint-plugin-prettier": "^5.2.3",
		"eslint-plugin-vue": "^9.32.0",
		"globals": "^16.0.0",
		"msw": "2.4.3",
		"prettier": "^3.5.2",
		"prettier-plugin-css-order": "^2.1.2",
		"typescript": "5.7.3",
		"typescript-eslint": "^8.24.1",
		"vite-plugin-checker": "^0.9.0",
		"vue-tsc": "^2.2.4"
	},
}

What steps can reproduce the bug?

kubb generate

How often does this bug happen?

Every time

What is the expected behavior?

No throwing

Additional information

❯ bun kubb generate
◐ Loading config                                                 12:09:51 p.m.
✔ Config loaded(kubb.config.ts)                                 12:09:52 p.m.
◐ Building https://api.payman.dev/api/v3/api-docs   internal-api 12:09:52 p.m.
60% ██████████████████░░░░░░░░░░░░ 3/5 | plugin-vue-query: buildStart
[internal-api 12:09:53 p.m.]  ERROR  Build failed https://api.payman.dev/api/v3/api-docs


 ╭───────────────────────────────────internal-api─────────────────────────────────────╮
 │                                                                                    │
 │  Plugins:        5 failed, 5 total                                                 │
 │  Failed:          plugin-oas, plugin-ts, plugin-vue-query, plugin-zod, plugin-msw  │
 │  Generated:      0 files in 0.974s                                                 │
 │  Output:         /home/rich/Projects/payman/dashboard/src/generated                │
 │                                                                                    │
 ╰────────────────────────────────────────────────────────────────────────────────────╯


[internal-api 12:09:53 p.m.]  ERROR  Cannot read properties of undefined (reading 'type') (plugin: plugin-oas, hook: buildStart) (plugin: plugin-oas, hook: buildStart)

    at EventEmitter.<anonymous> (node_modules/@kubb/core/src/logger.ts:93:19)
    at EventEmitter.emit (node:events:520:28)
    at EventEmitter.emit (node_modules/@kubb/core/src/utils/EventEmitter.ts:10:19)
    at Object.emit (node_modules/@kubb/core/src/logger.ts:111:21)
    at PluginManager.#catcher (node_modules/@kubb/core/src/PluginManager.ts:648:17)
    at node_modules/@kubb/core/src/PluginManager.ts:383:26
    at Array.forEach (<anonymous>)
    at PluginManager.hookParallel (node_modules/@kubb/core/src/PluginManager.ts:379:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at safeBuild (node_modules/@kubb/core/src/build.ts:100:5)

  [cause]: Cannot read properties of undefined (reading 'type') (plugin: plugin-oas, hook: buildStart)

      at EventEmitter.<anonymous> (node_modules/@kubb/core/src/logger.ts:93:19)
      at EventEmitter.emit (node:events:520:28)
      at EventEmitter.emit (node_modules/@kubb/core/src/utils/EventEmitter.ts:10:19)
      at Object.emit (node_modules/@kubb/core/src/logger.ts:111:21)
      at PluginManager.#catcher (node_modules/@kubb/core/src/PluginManager.ts:648:17)
      at node_modules/@kubb/core/src/PluginManager.ts:571:14
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async Promise.allSettled (index 0)
      at PluginManager.hookParallel (node_modules/@kubb/core/src/PluginManager.ts:377:21)
      at safeBuild (node_modules/@kubb/core/src/build.ts:100:5)

    [cause]: Cannot read properties of undefined (reading 'type')

        at node_modules/@kubb/oas/src/Oas.ts:86:30
        at Array.forEach (<anonymous>)
        at node_modules/@kubb/oas/src/Oas.ts:80:33
        at Array.forEach (<anonymous>)
        at Oas.resolveDiscriminators (node_modules/@kubb/oas/src/Oas.ts:67:29)
        at _SchemaGenerator.build (node_modules/@kubb/plugin-oas/src/SchemaGenerator.ts:912:9)
        at Object.buildStart (node_modules/@kubb/plugin-oas/src/plugin.ts:135:49)
        at processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async Promise.allSettled (index 0)
        at PluginManager.hookParallel (node_modules/@kubb/core/src/PluginManager.ts:377:21)
@RichAyotte RichAyotte added the bug Something isn't working label Feb 24, 2025
@RichAyotte
Copy link
Author

Reverting just the @kubb/plugin-oas package to 3.5.12 eliminates the error.

@stijnvanhulle
Copy link
Collaborator

Same as #1561

Setting enumSuffix to an empty string will result in some issues in creating enums, best to not set that or Kubb will override other values. I will add an error when an empty string is being used.

@RichAyotte
Copy link
Author

RichAyotte commented Feb 27, 2025

Same error with enumSuffix not set.

			pluginTs({
				enumType: 'literal',
				output: {
					path: 'types',
					barrelType: false,
				},
				unknownType: 'unknown',
			}),
 ╭───────────────────────────────────internal-api─────────────────────────────────────╮
 │                                                                                    │
 │  Plugins:        5 failed, 5 total                                                 │
 │  Failed:          plugin-oas, plugin-ts, plugin-vue-query, plugin-zod, plugin-msw  │
 │  Generated:      0 files in 0.876s                                                 │
 │  Output:         /home/rich/Projects/payman/dashboard/src/generated                │
 │                                                                                    │
 ╰────────────────────────────────────────────────────────────────────────────────────╯


[internal-api 3:21:59 p.m.]  ERROR  Cannot read properties of undefined (reading 'type') (plugin: plugin-oas, hook: buildStart) (plugin: plugin-oas, hook: buildStart)

    at EventEmitter.<anonymous> (node_modules/@kubb/core/src/logger.ts:93:19)
    at EventEmitter.emit (node:events:520:28)
    at EventEmitter.emit (node_modules/@kubb/core/src/utils/EventEmitter.ts:10:19)
    at Object.emit (node_modules/@kubb/core/src/logger.ts:111:21)
    at PluginManager.#catcher (node_modules/@kubb/core/src/PluginManager.ts:648:17)
    at node_modules/@kubb/core/src/PluginManager.ts:383:26
    at Array.forEach (<anonymous>)
    at PluginManager.hookParallel (node_modules/@kubb/core/src/PluginManager.ts:379:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at safeBuild (node_modules/@kubb/core/src/build.ts:100:5)

  [cause]: Cannot read properties of undefined (reading 'type') (plugin: plugin-oas, hook: buildStart)

      at EventEmitter.<anonymous> (node_modules/@kubb/core/src/logger.ts:93:19)
      at EventEmitter.emit (node:events:520:28)
      at EventEmitter.emit (node_modules/@kubb/core/src/utils/EventEmitter.ts:10:19)
      at Object.emit (node_modules/@kubb/core/src/logger.ts:111:21)
      at PluginManager.#catcher (node_modules/@kubb/core/src/PluginManager.ts:648:17)
      at node_modules/@kubb/core/src/PluginManager.ts:571:14
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async Promise.allSettled (index 0)
      at PluginManager.hookParallel (node_modules/@kubb/core/src/PluginManager.ts:377:21)
      at safeBuild (node_modules/@kubb/core/src/build.ts:100:5)

    [cause]: Cannot read properties of undefined (reading 'type')

        at node_modules/@kubb/oas/src/Oas.ts:86:30
        at Array.forEach (<anonymous>)
        at node_modules/@kubb/oas/src/Oas.ts:80:33
        at Array.forEach (<anonymous>)
        at Oas.resolveDiscriminators (node_modules/@kubb/oas/src/Oas.ts:67:29)
        at _SchemaGenerator.build (node_modules/@kubb/plugin-oas/src/SchemaGenerator.ts:912:9)
        at Object.buildStart (node_modules/@kubb/plugin-oas/src/plugin.ts:135:49)
        at processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async Promise.allSettled (index 0)
        at PluginManager.hookParallel (node_modules/@kubb/core/src/PluginManager.ts:377:21)

@stijnvanhulle
Copy link
Collaborator

Can you add the input with adding --debug to the cli command or create a playground/repo to so we can try out what is going wrong?

@stijnvanhulle stijnvanhulle reopened this Feb 27, 2025
@RichAyotte
Copy link
Author

bun kubb generate --debug
stdout ❯ bun kubb generate --debug > debug.log

[internal-api 3:34:07 p.m.] ERROR Build failed https://api.payman.dev/api/v3/api-docs

[internal-api 3:34:07 p.m.] ERROR Cannot read properties of undefined (reading 'type')

at node_modules/@kubb/oas/src/Oas.ts:86:30
at Array.forEach (<anonymous>)
at node_modules/@kubb/oas/src/Oas.ts:80:33
at Array.forEach (<anonymous>)
at Oas.resolveDiscriminators (node_modules/@kubb/oas/src/Oas.ts:67:29)
at _SchemaGenerator.build (node_modules/@kubb/plugin-oas/src/SchemaGenerator.ts:916:9)
at Object.buildStart (node_modules/@kubb/plugin-oas/src/plugin.ts:135:49)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Promise.allSettled (index 0)
at PluginManager.hookParallel (node_modules/@kubb/core/src/PluginManager.ts:377:21)

[internal-api 3:34:07 p.m.] ERROR Cannot read properties of undefined (reading 'type') (plugin: plugin-oas, hook: buildStart) (plugin: plugin-oas, hook: buildStart)

at EventEmitter.<anonymous> (node_modules/@kubb/core/src/logger.ts:93:19)
at EventEmitter.emit (node:events:520:28)
at EventEmitter.emit (node_modules/@kubb/core/src/utils/EventEmitter.ts:10:19)
at Object.emit (node_modules/@kubb/core/src/logger.ts:111:21)
at PluginManager.#catcher (node_modules/@kubb/core/src/PluginManager.ts:648:17)
at node_modules/@kubb/core/src/PluginManager.ts:383:26
at Array.forEach (<anonymous>)
at PluginManager.hookParallel (node_modules/@kubb/core/src/PluginManager.ts:379:13)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at safeBuild (node_modules/@kubb/core/src/build.ts:100:5)

[cause]: Cannot read properties of undefined (reading 'type') (plugin: plugin-oas, hook: buildStart)

  at EventEmitter.<anonymous> (node_modules/@kubb/core/src/logger.ts:93:19)
  at EventEmitter.emit (node:events:520:28)
  at EventEmitter.emit (node_modules/@kubb/core/src/utils/EventEmitter.ts:10:19)
  at Object.emit (node_modules/@kubb/core/src/logger.ts:111:21)
  at PluginManager.#catcher (node_modules/@kubb/core/src/PluginManager.ts:648:17)
  at node_modules/@kubb/core/src/PluginManager.ts:571:14
  at processTicksAndRejections (node:internal/process/task_queues:95:5)
  at async Promise.allSettled (index 0)
  at PluginManager.hookParallel (node_modules/@kubb/core/src/PluginManager.ts:377:21)
  at safeBuild (node_modules/@kubb/core/src/build.ts:100:5)

[cause]: Cannot read properties of undefined (reading 'type')

    at node_modules/@kubb/oas/src/Oas.ts:86:30
    at Array.forEach (<anonymous>)
    at node_modules/@kubb/oas/src/Oas.ts:80:33
    at Array.forEach (<anonymous>)
    at Oas.resolveDiscriminators (node_modules/@kubb/oas/src/Oas.ts:67:29)
    at _SchemaGenerator.build (node_modules/@kubb/plugin-oas/src/SchemaGenerator.ts:916:9)
    at Object.buildStart (node_modules/@kubb/plugin-oas/src/plugin.ts:135:49)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.allSettled (index 0)
    at PluginManager.hookParallel (node_modules/@kubb/core/src/PluginManager.ts:377:21)

kubb-1740688438530.log

@RichAyotte
Copy link
Author

I also tried enumType: 'asConst' but same issue.

@RichAyotte
Copy link
Author

Here's the repro. https://github.com/RichAyotte/kubb-repro

bun generate

@metinsut
Copy link

metinsut commented Mar 1, 2025

current versions

"@kubb/cli": "^2.28.4",
"@kubb/core": "^2.28.4",
"@kubb/plugin-oas": "^2.28.4",
"@kubb/swagger": "^2.28.4",
"@kubb/swagger-client": "^2.28.4",
"@kubb/swagger-ts": "^2.28.4",

`import { defineConfig } from "@kubb/core";
import { pluginOas } from "@kubb/plugin-oas";
import { pluginClient } from "@kubb/swagger-client";
import { pluginTs } from "@kubb/swagger-ts";

export default defineConfig({
root: ".",
input: {
path: "...",
},
output: {
path: "./src",
clean: true,
},
plugins: [
pluginOas(),
pluginTs(),
pluginClient({
output: {
path: "./clients/axios",
},
group: {
type: "tag",
output: "./clients/axios/{{tag}}Service",
},
exclude: [
{
type: "tag",
pattern: "store",
},
],
pathParamsType: "object",
dataReturnType: "full",
}),
],
});`

When I upgrade to v3, I encounter the same error.
mac/bun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants