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: README.md
+56Lines changed: 56 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -121,6 +121,62 @@ type t =
121
121
}
122
122
```
123
123
124
+
Note that the implicit tuple in a polymorphic variant is flattened. This can be disabled using the `~polymorphic_variant_tuple` flag.
125
+
126
+
```ocaml
127
+
type a = [ `A of int * string * bool ] [@@deriving jsonschema]
128
+
```
129
+
130
+
```json
131
+
{
132
+
"anyOf": [
133
+
{
134
+
"type": "array",
135
+
"prefixItems": [
136
+
{ "const": "A" },
137
+
{ "type": "integer" },
138
+
{ "type": "string" },
139
+
{ "type": "boolean" }
140
+
],
141
+
"unevaluatedItems": false,
142
+
"minItems": 4,
143
+
"maxItems": 4
144
+
}
145
+
]
146
+
}
147
+
```
148
+
149
+
```ocaml
150
+
type b = [ `B of int * string * bool ] [@@deriving jsonschema ~polymorphic_variant_tuple]
151
+
```
152
+
153
+
```json
154
+
{
155
+
"anyOf": [
156
+
{
157
+
"type": "array",
158
+
"prefixItems": [
159
+
{ "const": "B" },
160
+
{
161
+
"type": "array",
162
+
"prefixItems": [
163
+
{ "type": "integer" },
164
+
{ "type": "string" },
165
+
{ "type": "boolean" }
166
+
],
167
+
"unevaluatedItems": false,
168
+
"minItems": 3,
169
+
"maxItems": 3
170
+
}
171
+
],
172
+
"unevaluatedItems": false,
173
+
"minItems": 2,
174
+
"maxItems": 2
175
+
}
176
+
]
177
+
}
178
+
```
179
+
124
180
A `~variant_as_string` flag is exposed to obtain a more natural representation `"anyOf": [{ "const": "..." }, ...]`. This representation does _not_ support payloads. It reproduces the representation of `melange-json` for [enumeration like variants](https://github.com/melange-community/melange-json?tab=readme-ov-file#enumeration-like-variants). For example:
0 commit comments