Skip to content

Bug: default() stores number values as strings in ZodBuilder #46

@a6b8

Description

@a6b8

Problem

In src/v2/task/ZodBuilder.mjs (or the CLI equivalent src/task/ZodBuilder.mjs), the default() option handler always stores the value as a string, even when the primitive type is number().

Example: A parameter defined as z: { primitive: 'number()', options: 'default(100)' } will produce a Zod schema with z.number().default("100") instead of z.number().default(100).

Impact

Any schema with a numeric parameter that has a default value sends the wrong type to the API. This affects common parameters like:

  • limit (default 10, 25, 100, etc.)
  • page (default 1)
  • offset (default 0)
  • startblock / endblock (default 0)

Expected Behavior

The default case in #insertOption() should check the primitive type:

  • number() → parse value with Number() or parseInt()/parseFloat()
  • boolean() → parse value as value === 'true'
  • string() → keep as string (current behavior)

Reproduction

// Schema definition
z: { primitive: 'number()', options: 'default(100)' }

// Current: z.number().default("100")  ← wrong type
// Expected: z.number().default(100)   ← correct type

Priority

P0 — Affects all schemas with numeric defaults.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions