Skip to content

Commit 5fd457c

Browse files
committed
Add upgrade notice for Array[String]
If Array[String] is used without a coerce_with block, existing APIs may quietly fail without explanation. This change to the upgrade documentation makes that clear. Closes #2013
1 parent 20a6d3f commit 5fd457c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

UPGRADING.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,26 @@ end
4242

4343
Custom types which don't depend on Virtus don't require any changes.
4444

45+
#### Ensure that Array[String] types have explicit coercions
46+
47+
Unlike Virtus, dry-types does not perform any implict coercions. If you
48+
have any uses of `Array[String]`, be sure they use a `coerce_with`
49+
block. For example:
50+
51+
```ruby
52+
requires :values, type: Array[String]
53+
```
54+
55+
It's quite common to pass a comma-separated list, such as `tag1,tag2` as
56+
`values`. Previously Virtus would implicitly coerce this to
57+
`Array(values)` so that `["tag1,tag2"]` would pass the type checks, but
58+
with `dry-types` the values are no longer coerced for you. To fix this,
59+
you might do:
60+
61+
```ruby
62+
requires :values, type: Array[String], coerce_with: ->(val) { val.split(',').map(&:strip) }
63+
```
64+
4565
For more information see [#1920](https://github.com/ruby-grape/grape/pull/1920).
4666

4767
### Upgrading to >= 1.2.4

0 commit comments

Comments
 (0)