Skip to content

zodSchema.isOptional is not a function #296

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

Open
SimonTweddle1 opened this issue Mar 20, 2025 · 0 comments
Open

zodSchema.isOptional is not a function #296

SimonTweddle1 opened this issue Mar 20, 2025 · 0 comments

Comments

@SimonTweddle1
Copy link

I basically have this code

import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi'
import { coerce, object, z } from 'zod'

extendZodWithOpenApi(z)

const id = id: coerce.number().openapi({
    param: {
      name: 'id',
      in: 'path'
    },
    example: '1'
  })

// in another file which is imported after the previous code, the endpoint is defined and I include here the `id`
responses: {
  200: {
    content: 'application/json': {
      schema: object({ id })
    }
  }
}

Which triggers this error

"type": "TypeError",
"message": "zodSchema.isOptional is not a function",
"stack":
    TypeError: zodSchema.isOptional is not a function
        at Metadata.isOptionalSchema (/node_modules/.pnpm/@asteasolutions+zod-to-openapi@7.3.0_zod@3.24.1/node_modules/@asteasolutions/zod-to-openapi/dist/index.cjs:465:26)
        at /node_modules/.pnpm/@asteasolutions+zod-to-openapi@7.3.0_zod@3.24.1/node_modules/@asteasolutions/zod-to-openapi/dist/index.cjs:650:49
        at Array.filter (<anonymous>)
        at ObjectTransformer.requiredKeysOf (/node_modules/.pnpm/@asteasolutions+zod-to-openapi@7.3.0_zod@3.24.1/node_modules/@asteasolutions/zod-to-openapi/dist/index.cjs:650:14)
        at ObjectTransformer.transform (/node_modules/.pnpm/@asteasolutions+zod-to-openapi@7.3.0_zod@3.24.1/node_modules/@asteasolutions/zod-to-openapi/dist/index.cjs:613:31)
        at OpenApiTransformer.transform (/node_modules/.pnpm/@asteasolutions+zod-to-openapi@7.3.0_zod@3.24.1/node_modules/@asteasolutions/zod-to-openapi/dist/index.cjs:786:43)
        at OpenAPIGenerator.toOpenAPISchema (/node_modules/.pnpm/@asteasolutions+zod-to-openapi@7.3.0_zod@3.24.1/node_modules/@asteasolutions/zod-to-openapi/dist/index.cjs:1223:40)
        at OpenAPIGenerator.generateSchemaWithMetadata (/node_modules/.pnpm/@asteasolutions+zod-to-openapi@7.3.0_zod@3.24.1/node_modules/@asteasolutions/zod-to-openapi/dist/index.cjs:1051:20)
        at OpenAPIGenerator.generateSimpleSchema (/node_modules/.pnpm/@asteasolutions+zod-to-openapi@7.3.0_zod@3.24.1/node_modules/@asteasolutions/zod-to-openapi/dist/index.cjs:1078:25)
        at OpenAPIGenerator.generateSchemaWithRef (/node_modules/.pnpm/@asteasolutions+zod-to-openapi@7.3.0_zod@3.24.1/node_modules/@asteasolutions/zod-to-openapi/dist/index.cjs:1112:29)
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

1 participant