Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make serde_with schemars support extensible
Implementing JsonSchema directly on serde_with::Schema<T, TA> works fine when within serde_with. Once you are outside the crate, however, the orphan rules prevent you from adding impls of the form impl JsonSchema for Schema<T, MyCustomType> { ... } We would like users to be able to make that impl (or something equivalent) so we need to find a way to make it work. We make this work by adding a new layer of trait indirection. This commit introduces an new JsonSchemaAs<T> trait, adds a blanket impl<T, TA> JsonSchema for Schema<T, TA> where TA: JsonSchemaAs<T> and then changes all the existing impls to be for JsonSchemaAs<T>. Now, when a user wants to add json schema support for their own type they can implement JsonSchemaAs<T> for their custom type and the orphan rules will allow it. As a bonus, this seems to have made the extraordinarily confusing "reached recursion limit" errors that I have been encountering disappear. Which is nice.
- Loading branch information