gcornut / valibot-json-schema

Converter from Valibot schemas to JSON schema
https://www.npmjs.com/package/@gcornut/valibot-json-schema
MIT License
43 stars 4 forks source link

Support file type #78

Closed wineTGH closed 1 month ago

wineTGH commented 1 month ago

Currently library just gives an error if you try to use it with file type in schema

Link to an File API docs

gcornut commented 1 month ago

Hello, yes file are not a thing in JSON so we can't have a conversion to JSON schema.

You can generate an empty schema on files by doing:

toJSONSchema({
    schema: file(),
    customSchemaConversion: {
        // Return an empty JSON schema (equivalent to `any`)
        file: () => {
            return {};
        }
    },
})
// => {}
wineTGH commented 1 month ago

That's a shame. I came here in the first place because of an error message in sveltekit superforms. I found something similar to validate non-JSON data, but not enough fields and no support for binary content format (which makes sense). Thanks for the reply

gcornut commented 1 month ago

@wineTGH Can you contact the maintainers of sveltekit superforms ?

Of course js file could be serialized in JSON but it would need a custom serializer and then a custom schema conversion which is definitely possible with customSchemaConversion

gcornut commented 1 month ago

Actually I see that they already encountered the same error on instance and just ignored it:

https://github.com/ciscoheat/sveltekit-superforms/blob/1dcb881a61d8bf8074c639834a733652d3878506/src/lib/adapters/valibot.ts#L32

wineTGH commented 1 month ago

Thanks. I will open issue on their repo. This can be closed