We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
3.4.0
MacOS
kubb.config.ts
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()], });
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 maxLength: 25 price: type: number minimum: 1 required: - name - price
@tanstack-query
MSW
React
Vue
"@kubb/cli": "^3.4.0", "@kubb/core": "^3.4.0", "@kubb/plugin-faker": "^3.4.0", "@kubb/plugin-oas": "^3.4.0", "@kubb/plugin-ts": "^3.4.0", "@kubb/plugin-zod": "^3.4.0",
Generate the code and look at the generated file createItem.ts, it contains:
createItem.ts
export function createItem(data?: Partial<Item>) { return { ...{ name: faker.string.alpha(), price: faker.number.float() }, ...(data || {}), } }
And then compare it to itemSchema.ts:
itemSchema.ts
export const itemSchema = z.object({ name: z.string().min(3).max(25), price: z.number().min(1), })
Notice that zod includes the min and max values while faker doesn't. This can cause a generated faker object not being correctly validated by zod.
Every time
Expected behavior: plugin-faker should take into account min and max values. Expect the code to be something similar to this:
export function createItem(data?: Partial<Item>) { return { ...{ name: faker.string.alpha({length: {min: 3, max: 25}}), price: faker.number.float({min: 1}) }, ...(data || {}), } }
It seems to be working for arrays when minItems and maxItems are defined in the api specification
minItems
maxItems
The text was updated successfully, but these errors were encountered:
v3.4.1 of Kubb will resolve this issue :)
v3.4.1
Sorry, something went wrong.
stijnvanhulle
No branches or pull requests
What version of
kubb
is running?3.4.0
What kind of platform do you use?
MacOS
How does your
kubb.config.ts
config look likeSwagger/OpenAPI file?
What version of external packages are you using(
@tanstack-query
,MSW
,React
,Vue
, ...)What steps can reproduce the bug?
Generate the code and look at the generated file
createItem.ts
, it contains:And then compare it to
itemSchema.ts
:Notice that zod includes the min and max values while faker doesn't. This can cause a generated faker object not being correctly validated by zod.
How often does this bug happen?
Every time
What is the expected behavior?
Expected behavior: plugin-faker should take into account min and max values.
Expect the code to be something similar to this:
Additional information
It seems to be working for arrays when
minItems
andmaxItems
are defined in the api specificationThe text was updated successfully, but these errors were encountered: