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

FieldType detected as string, but it should be a number #265

Open
sharenz opened this issue Jan 8, 2025 · 6 comments
Open

FieldType detected as string, but it should be a number #265

sharenz opened this issue Jan 8, 2025 · 6 comments
Assignees

Comments

@sharenz
Copy link

sharenz commented Jan 8, 2025

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?

@gustavoguichard
Copy link
Contributor

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

@gustavoguichard gustavoguichard self-assigned this Jan 8, 2025
@gustavoguichard
Copy link
Contributor

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

@danielweinmann
Copy link
Contributor

@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
Copy link
Contributor

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

@sharenz
Copy link
Author

sharenz commented Jan 8, 2025

@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.

@danielweinmann
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants