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

schemaObject.required?.includes is not a function #223

Open
nicofishman opened this issue Sep 22, 2024 · 0 comments
Open

schemaObject.required?.includes is not a function #223

nicofishman opened this issue Sep 22, 2024 · 0 comments

Comments

@nicofishman
Copy link

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Having this swagger.yaml and running npx ts-node -r tsconfig-paths/register src/main.swagger.ts && npx openapi-typescript ./swagger.yaml -o ./types/schema.ts threw TypeError: schemaObject.required?.includes is not a function. I use zod-nestjs to generate classes with zod. I tracked the problem down to the package and could solve it with a simple check

Here is the diff that solved my problem:

diff --git a/node_modules/@anatine/zod-nestjs/src/lib/create-zod-dto.js b/node_modules/@anatine/zod-nestjs/src/lib/create-zod-dto.js
index deb2e7d..d62395e 100644
--- a/node_modules/@anatine/zod-nestjs/src/lib/create-zod-dto.js
+++ b/node_modules/@anatine/zod-nestjs/src/lib/create-zod-dto.js
@@ -49,7 +49,7 @@ const createZodDto = (zodSchema) => {
              * array to a boolean.
              */
             const convertedSchemaObject = schemaObject;
-            if (required !== undefined) {
+            if (required !== undefined && Array.isArray(required)) {
                 convertedSchemaObject.required = required;
             }
             // @nestjs/swagger expects OpenAPI 3.0-style schema objects
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