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

ZodGenerator ignores minLength and maxLength for string properties #770

Closed
3rd1t opened this issue Jan 13, 2024 · 0 comments · Fixed by #771
Closed

ZodGenerator ignores minLength and maxLength for string properties #770

3rd1t opened this issue Jan 13, 2024 · 0 comments · Fixed by #771
Assignees
Labels
bug Something isn't working

Comments

@3rd1t
Copy link

3rd1t commented Jan 13, 2024

What version of kubb is running?

2.2.0

What platform is your computer?

MacOS

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

@kubb/swagger-zod

What steps can reproduce the bug?

ZodGenerator ignores minLength and maxLength for string properties like this:

...
"properties": {
  "username": {
    "maxLength": 100,
    "minLength": 5,
    "type": "string"
  }
},
...

How often does this bug happen?

Every time

What is the expected behavior?

import { z } from 'zod'

export const addUserRequestSchema = z.object({ username: z.string().min(5).max(100) })

Swagger/OpenAPI file?

{
  "openapi": "3.0.1",
  "info": {
    "title": "SystemsCrm.Api",
    "version": "1.0"
  },
  "paths": {
    "/api/users": {
      "post": {
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/AddUserRequest"
                  }
                ]
              }
            }
          },
          "required": true
        }
      },
    }
  },
  "components": {
    "schemas": {
      "AddUserRequest": {
        "required": [
          "username"
        ],
        "type": "object",
        "properties": {
          "username": {
            "maxLength": 100,
            "minLength": 5,
            "type": "string"
          }
        },
        "additionalProperties": false
      }
    }
  }
}

Additional information

No response

@3rd1t 3rd1t added the bug Something isn't working label Jan 13, 2024
@stijnvanhulle stijnvanhulle self-assigned this Jan 14, 2024
@stijnvanhulle stijnvanhulle linked a pull request Jan 14, 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