remix-forms icon indicating copy to clipboard operation
remix-forms copied to clipboard

FieldType detected as string, but it should be a number

Open sharenz opened this issue 1 year ago • 6 comments

I am creating my zod schema using orval from my openapi spec.

So the resulting schema looks like:

"costs": zod.number().or(zod.null()).optional(),

The FieldType is string in this case, so I always get the error "Number expected, received string".

When I change the schema it is working fine. Unfortunately this is not a good solution for me, as I want to generate the forms directly from the api definition.

"costs": zod.number().optional(),

Can I overwrite the type somehow or is there a chance this can be fixed?

sharenz avatar Jan 08 '25 07:01 sharenz

Hi @sharenz , have you tried zod.number().nullish() yet? I think it might work for you. LMK if not!

gustavoguichard avatar Jan 08 '25 13:01 gustavoguichard

@sharenz I'm gonna close the issue but feel free to re-open it if it doesn't work

gustavoguichard avatar Jan 08 '25 13:01 gustavoguichard

@gustavoguichard, I'm reopening this one because we should strive to support all possible ways of construing Zod schemas. Zod's API has grown a lot since the early days of Remix Forms, and now we need to catch up 😅

The only reason to close this one would be if we could not find a solution and gave up.

danielweinmann avatar Jan 08 '25 16:01 danielweinmann

@sharenz, you are creating the schemas dynamically, right?

danielweinmann avatar Jan 08 '25 16:01 danielweinmann

@danielweinmann Yes they are generated automatically.

In detail, I have a python backend using fastapi, which automatically generates the openapi spec. Then I am using "orval" to create the zod schema for my remix app.

I checked briefly and I am using the correct way in both projects to setup the schema. So I am not aware of a workaround which would allow me to change the generated schema.

sharenz avatar Jan 08 '25 19:01 sharenz

Awesome, thanks! I don't think we'll be able to fix this before v3, but we plan to release v3 with a solution for this use case.

danielweinmann avatar Jan 09 '25 18:01 danielweinmann