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
Using `applyDefaults` with `oneOf` will one apply the default value of the sub-schema that matches the condition. For
141
+
example, using this schema:
142
+
143
+
```javascript
144
+
{
145
+
type:"object",
146
+
oneOf: [
147
+
{
148
+
type:"object",
149
+
properties: {
150
+
sun: {
151
+
type:"number",
152
+
default:9000,
153
+
},
154
+
moon: {
155
+
type:"number",
156
+
default:9000,
157
+
},
158
+
},
159
+
required: ["sun"],
160
+
},
161
+
{
162
+
type:"object",
163
+
properties: {
164
+
sun: {
165
+
type:"number",
166
+
default:9000,
167
+
},
168
+
moon: {
169
+
type:"number",
170
+
default:9000,
171
+
},
172
+
},
173
+
required: ["moon"],
174
+
},
175
+
],
176
+
};
177
+
```
178
+
179
+
- The payload `{ sun: 10}` will be modified to `{ sun: 10, moon: 9000 }`.
180
+
- The payload `{ moon: 10}` will be modified to `{ sun: 9000, moon: 10 }`.
181
+
- The payload `{ saturn: 10}` will throw an error because no condition is met.
182
+
139
183
## Custom errors
140
184
141
185
If the new instance options has the `errorMessages` flag set to true, you can use the property `errorMessage` in the schema to define custom error messages.
@@ -160,7 +204,7 @@ const payload = {
160
204
161
205
cabidela.validate(payload);
162
206
// throws "Error: prompt required"
163
-
```
207
+
````
164
208
165
209
## Tests
166
210
@@ -236,7 +280,6 @@ We use Vitest's [bench](https://vitest.dev/api/#bench) feature to run the benchm
236
280
npm run benchmark
237
281
```
238
282
239
-
240
283
## Current limitations
241
284
242
285
Cabidela supports most ofJSON Schema specification, and should be useful for many applications, but it's not complete. **Currently** we do not support:
@@ -249,4 +292,3 @@ Cabidela supports most of JSON Schema specification, and should be useful for ma
0 commit comments