Is it possible to customise type resolution? #1351
Unanswered
paulst-cais
asked this question in
Q&A
Replies: 1 comment
-
Just looking into this a little further, it does seem that this is partly implemented here: Ideally though I want to treat a Date and a DateTime differently, and type them differently to help distinguish between them. I think most of this could be done in this file though: if (context.output.override.customStringFormatResolver && item?.format) {
const type = context.output.override.customStringFormatResolver(item.format);
if (type) {
value = type;
}
} Then a example resolver can just do something like: customStringFormatResolver = (format: string) => {
switch (format) {
case 'date-time':
return 'CustomDateTime'
case 'date':
return 'CustomDate'
default:
return false
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
We want to be able to treat Date types differently in our app, and keep [de]serialisation in the API layer.
So where the the spec for a schema property might look like:
This currently gets translated to a string primitive.
In our custom fetcher we can add deserialisation which actually turns this into a simple struct for holding the Date, giving us better type safety. However, this will then not match the typed response for a specific endpoint, which would be expecting a
string
.It's not clear to me if there is a way to achieve this custom resolver at the moment?
I would expect to be able to pass some configuration key to register a new resolver, ideally it would only have to handle the overridden scenario, and be able to fallback to default resolution, so a custom resolver might do something like:
Is this something that would be useful? I'm a little unsure about resolving to a non-primitive type here, as that would need to be imported / defined in the file; not sure the cleanest way to configure that?
If this isn't currently possible I'd possibly be able to work on a solution if that is something you'd want to add? I'd need some pointers on where best to hook into the code to do this though :)
Beta Was this translation helpful? Give feedback.
All reactions