Apply callback functions for schemas #487
Closed
daniikpando
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi everyone!
We're trying to adapt this library in our elixir project, but we found a little customization problem.
Problem
The schemas are in the high layer level of the API and that is good, but sometimes we need to transform some values that were accepted in one format, and then we need to convert to another internal format, for example:
The IDs must be accepted in base62 format, but internally we need to work with it in UUID format (to make db query and etc...), it's not good to convert the IDs into the business logic because it increases the complexity of the code and we have to make it everytime. What happen if we try solving this by leveraging the serialization process with
Open API spex
.Maybe it could be good if we implement
callbacks
function for schemas and the general idea could be to create a callback function that should be call in the cast and validate logic for every field that it's being validated, for example:call
post_validate_field
in theOpenApiSpex.Cast
functions (i'm not sure of this).and for each module schema, we can override the
post_validate_field
to apply our custom transformations.Let me know if this could be possible or it's a crazy strange idea :)
Beta Was this translation helpful? Give feedback.
All reactions