vazco / uniforms

A React library for building forms from any schema.
https://uniforms.tools
MIT License
1.93k stars 239 forks source link

[JSONSchemaBridge] Export `resolveIfNeeded` function #1307

Closed lordrip closed 5 months ago

lordrip commented 5 months ago

Currently, we have partial support for oneOf keywords in uniforms, and as discussed in #863, one of the proposed workarounds is to process the schema before passing it to the form.

This can easily done for schemas that don't use $ref, in case a reference schema is used, it would be beneficial to have available the resolveRefIfNeeded function

The goal for this issue is to export the aforementioned function, either through a standalone export or as a protected method of the JSONSchemaBridge class

lordrip commented 5 months ago

If this is approved, I can provide a PR exporting this function 😃

kestarumper commented 5 months ago

Hi @lordrip, Currently, this function is internal, and we can change it however we want without considering backward compatibility. If we export it, we will have to commit to its signature and support it.

There is also #1278 on the plate, and resolveRefIfNeeded might play a role here.

Another workaround, for now, would be to just copy the function into your codebase because it's not that big: https://github.com/vazco/uniforms/blob/eed59c6e6b67b10a7ba2e996bb4467d349b43792/packages/uniforms-bridge-json-schema/src/JSONSchemaBridge.ts#L14-L49

I'm also considering going with export function experimental_resolveRefIfNeeded to mark that its API might break. That would be the middle ground between your needs and our commitment.

Let me know what you think.

lordrip commented 5 months ago

Thanks for the answer @kestarumper.

I agree that exporting the function will increase the API surface area, I'll copy the function in the meantime, to move forward. I'll close the issue. Thanks once again for taking the time.