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

MinLength and maxLength are missing in Zod generated schema #928

Closed
shatynska opened this issue Apr 9, 2024 · 1 comment · Fixed by #929
Closed

MinLength and maxLength are missing in Zod generated schema #928

shatynska opened this issue Apr 9, 2024 · 1 comment · Fixed by #929
Labels
bug Something isn't working

Comments

@shatynska
Copy link

What version of kubb is running?

2.12.5

What platform is your computer?

Windows, use WSL

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

"zod": "^3.22.4"

What steps can reproduce the bug?

My OpenApi 3.1

...
"LoginDto": {
        "type": [
          "object"
        ],
        "properties": {
          "identifier": {
            "type": [
              "string"
            ],
            "minLength": 3,
            "maxLength": 40
          },
          "password": {
            "type": [
              "string"
            ],
            "minLength": 8,
            "maxLength": 20
          }
        },
        "required": [
          "identifier",
          "password"
        ]
      },
...

My Kubb config:

...
    createSwaggerZod({
      output: {
        path: './zod',
      },
      group: { type: 'tag' },
    }),
...

I recieved:

export const loginDtoSchema = z.object({
  identifier: z.string(),
  password: z.string(),
});

How often does this bug happen?

Every time

What is the expected behavior?

export const loginDtoSchema = 
  z.object({
    identifier: z.string().min(3).max(40),
    password: z.string().min(8).max(20),
  });

Swagger/OpenAPI file?

{
  "openapi": "3.1.0",
  "paths": {
    "/api/auth/login": {
      "post": {
        "operationId": "AuthController_login",
        "summary": "Login user",
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LoginDto"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LoginResponseDto"
                }
              }
            }
          }
        },
        "tags": [
          "auth"
        ]
      }
    },
  },
  "info": {
    "title": "",
    "description": "",
    "version": "0.0.1",
    "contact": {
    }
  },
  "tags": [
    {
      "name": "profiles",
      "description": ""
    }
  ],
  "servers": [],
  "components": {
    "securitySchemes": {
      "bearer": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "type": "http"
      }
    },
    "schemas": {
      "LoginDto": {
        "type": [
          "object"
        ],
        "properties": {
          "identifier": {
            "type": [
              "string"
            ],
            "minLength": 3,
            "maxLength": 40
          },
          "password": {
            "type": [
              "string"
            ],
            "minLength": 8,
            "maxLength": 20
          }
        },
        "required": [
          "identifier",
          "password"
        ]
      },
      "LoginResponseDto": {
        "type": [
          "object"
        ],
        "properties": {
          "accessToken": {
            "type": [
              "string"
            ]
          }
        },
        "required": [
          "accessToken"
        ]
      }
    }
  }
}

Additional information

I notice that such bug have already appeared and was fixed: #770 (comment) , but I got it.
And similar one was with an array: #806 (comment)

@shatynska shatynska added the bug Something isn't working label Apr 9, 2024
@stijnvanhulle
Copy link
Collaborator

@shatynska We still have some issues with OpenAPI 3.1.0, same for this one. I will have a look later this week to resolve this :)

@stijnvanhulle stijnvanhulle linked a pull request Apr 12, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants