-
-
Notifications
You must be signed in to change notification settings - Fork 157
Description
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)
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.