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
Copy file name to clipboardExpand all lines: docs/HOW_TO_MODEL_A_RECURSIVE_TAGGED_UNION.md
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,14 +21,14 @@ type RecursiveNode =
21
21
let rec nodeSchema : Schema<RecursiveNode> =
22
22
delay (fun () ->
23
23
union [
24
-
case1
24
+
tagWith
25
25
"leaf"
26
26
(function
27
27
| Leaf value -> Some value
28
28
| _ -> None)
29
29
Leaf
30
30
string
31
-
case1
31
+
tagWith
32
32
"branch"
33
33
(function
34
34
| Branch value -> Some value
@@ -77,13 +77,15 @@ value.value.value=ok
77
77
78
78
Use these helpers:
79
79
80
-
-`case0` for a case with no payload
81
-
-`case1` for a case with exactly one payload value
80
+
-`tag` for a tag without payload
81
+
-`tagWith` for a tag with exactly one payload value
82
82
-`union` for the default field names `"case"` and `"value"`
83
83
-`unionNamed` when another system expects different field names
84
84
85
85
If you need the exact emitted JSON, XML, YAML, or KeyValue shapes, see [Tagged Union Wire Shape Reference](TAGGED_UNION_REFERENCE.md).
86
86
87
+
If you want concrete malformed payload examples and the exact failure messages the codecs are expected to produce, see [`tests/CodecMapper.Tests/TaggedUnionErrorTests.fs`](../tests/CodecMapper.Tests/TaggedUnionErrorTests.fs).
88
+
87
89
Example with a payload-free case and custom field names:
88
90
89
91
```fsharp
@@ -93,8 +95,8 @@ type Status =
93
95
94
96
let statusSchema =
95
97
unionNamed "kind" "details" [
96
-
case0 "pending" Pending ((=) Pending)
97
-
case1
98
+
tag "pending" Pending ((=) Pending)
99
+
tagWith
98
100
"failed"
99
101
(function Failed message -> Some message | _ -> None)
Copy file name to clipboardExpand all lines: docs/TAGGED_UNION_REFERENCE.md
+10-8Lines changed: 10 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,8 +2,8 @@
2
2
3
3
This page is for lookup once you already know the authored tagged-union API:
4
4
5
-
-`Schema.case0`
6
-
-`Schema.case1`
5
+
-`Schema.tag`
6
+
-`Schema.tagWith`
7
7
-`Schema.union`
8
8
-`Schema.unionNamed`
9
9
-`Schema.delay`
@@ -29,8 +29,8 @@ type Status =
29
29
30
30
let statusSchema =
31
31
union [
32
-
case0 "pending" Pending ((=) Pending)
33
-
case1
32
+
tag "pending" Pending ((=) Pending)
33
+
tagWith
34
34
"failed"
35
35
(function Failed message -> Some message | _ -> None)
36
36
Failed
@@ -108,8 +108,8 @@ Example:
108
108
```fsharp
109
109
let statusSchema =
110
110
unionNamed "kind" "details" [
111
-
case0 "pending" Pending ((=) Pending)
112
-
case1
111
+
tag "pending" Pending ((=) Pending)
112
+
tagWith
113
113
"failed"
114
114
(function Failed message -> Some message | _ -> None)
115
115
Failed
@@ -157,12 +157,12 @@ type RecursiveNode =
157
157
let rec nodeSchema : Schema<RecursiveNode> =
158
158
delay (fun () ->
159
159
union [
160
-
case1
160
+
tagWith
161
161
"leaf"
162
162
(function Leaf value -> Some value | _ -> None)
163
163
Leaf
164
164
string
165
-
case1
165
+
tagWith
166
166
"branch"
167
167
(function Branch value -> Some value | _ -> None)
168
168
Branch
@@ -188,3 +188,5 @@ The codecs currently reject:
188
188
- stray payload keys for payload-free KeyValue cases
189
189
190
190
For KeyValue specifically, the payload-free case check matters because extra flattened keys would otherwise be easy to miss.
191
+
192
+
For readable, executable examples of malformed payloads and the expected error messages across JSON, XML, YAML, and KeyValue, see [`tests/CodecMapper.Tests/TaggedUnionErrorTests.fs`](../tests/CodecMapper.Tests/TaggedUnionErrorTests.fs).
0 commit comments