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

[@kubb/plugin-faker]: If only min is specified for a string length, an error will occur #1532

Closed
xeoneux opened this issue Jan 22, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@xeoneux
Copy link

xeoneux commented Jan 22, 2025

What version of kubb is running?

3.5.3

What kind of platform do you use?

MacOS

How does your kubb.config.ts config look like

import { defineConfig } from "@kubb/core";
import { pluginOas } from "@kubb/plugin-oas";
import { pluginFaker } from "@kubb/plugin-faker";
import { pluginZod } from "@kubb/plugin-zod";
import { pluginTs } from "@kubb/plugin-ts";

export default defineConfig({
  input: {
    path: "./src/openapi/test.yaml",
  },
  output: {
    path: "./src/generated",
  },
  plugins: [pluginOas(), pluginTs(), pluginZod(), pluginFaker()],
});

Swagger/OpenAPI file?

openapi: 3.0.3
info:
  title: Test
  version: 1.0.0
paths:
  /item:
    get:
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Item"
components:
  schemas:
    Item:
      type: object
      properties:
        name:
          type: string
          minLength: 3
        price:
          type: number
          minimum: 5
      required:
        - name
        - price

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

"@faker-js/faker": "9.4.0",
"@kubb/cli": "3.5.3",
"@kubb/core": "3.5.3",
"@kubb/plugin-faker": "3.5.3",
"@kubb/plugin-msw": "3.5.3",
"@kubb/plugin-oas": "3.5.3",
"@kubb/plugin-ts": "3.5.3",

What steps can reproduce the bug?

The generated code looks as follows,

export function createItem(data?: Partial<Item>) {
  return {
    ...{ name: faker.string.alpha({ min: 3 }), price: faker.number.float({ min: 5, max: Number.MAX_VALUE }) },
    ...(data || {}),
  }
}

It throws an error on name because max is missing

https://fakerjs.dev/api/string.html#alpha

How often does this bug happen?

Every time

What is the expected behavior?

export function createItem(data?: Partial<Item>) {
  return {
    ...{ name: faker.string.alpha({ min: 3, max: SOME_DEFAULT_VALUE }), price: faker.number.float({ min: 5, max: Number.MAX_VALUE }) },
    ...(data || {}),
  }
}

This default value should either be configurable by the kubb config or some really large default value like 2,147,483,647
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length#description
(But I'm not sure if this would have any performance impacts)

Additional information

No response

@xeoneux xeoneux added the bug Something isn't working label Jan 22, 2025
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

2 participants