You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, if one wants to configure Siesta to use transformers on a resource with a wildcard in its path, they have to perform said configuration with strings, meaning that a certain amount of repeated information is unavoidable. It also adds a lot of long, unchecked strings that are easy to inadvertently modify without noticing. This isn't too bad with simple APIs, but for those with many endpoints it can really pile up.
I propose the addition of a way to use wildcard elements when configuring Siesta's transformers with resources. One way this could be done is with an any property on Resource that translates to * when path conversion is performed (which would use the same pattern matching logic found in the ConfigurationPatternConvertible extension on String).
Using a class/struct hierarchy that matches your endpoints' paths along with Swift's Codable could look something like this: configureTransformer(API(.v2).tasks.any.assignees) { try decoder.decode([Person].self, from: $0.content) }
which can be shortened to this with a small extension in application code: configureTransformer(API(.v2).tasks.any.assignees, [Person].self)
This enables more conciseness, reduced stringiness, and improved readability. Something like this can done purely in application code but it'd be great if it were part of Siesta itself.
The text was updated successfully, but these errors were encountered:
Quick update on this: in our application I've created an extension for Siesta's Service that allows transformers to be configured with instances of my custom Resource wrapping APIComponent class:
It works and is an improvement on the string-based setup, but it'd still be very nice to see some less specialized form of this idea make its way into Siesta proper.
Currently, if one wants to configure Siesta to use transformers on a resource with a wildcard in its path, they have to perform said configuration with strings, meaning that a certain amount of repeated information is unavoidable. It also adds a lot of long, unchecked strings that are easy to inadvertently modify without noticing. This isn't too bad with simple APIs, but for those with many endpoints it can really pile up.
I propose the addition of a way to use wildcard elements when configuring Siesta's transformers with resources. One way this could be done is with an
any
property onResource
that translates to*
when path conversion is performed (which would use the same pattern matching logic found in theConfigurationPatternConvertible
extension onString
).Using a class/struct hierarchy that matches your endpoints' paths along with Swift's
Codable
could look something like this:configureTransformer(API(.v2).tasks.any.assignees) { try decoder.decode([Person].self, from: $0.content) }
which can be shortened to this with a small extension in application code:
configureTransformer(API(.v2).tasks.any.assignees, [Person].self)
instead of:
configureTransformer("/v2/tasks/*/assignees") { try decoder.decode([Person].self, from: $0.content) }
This enables more conciseness, reduced stringiness, and improved readability. Something like this can done purely in application code but it'd be great if it were part of Siesta itself.
The text was updated successfully, but these errors were encountered: