Skip to content

Commit 838cad3

Browse files
Merge pull request #1193 from cruzdanilo/json-variant
fix(to-json-schema): fix variant schema conversion
2 parents 227978d + d18247d commit 838cad3

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

packages/to-json-schema/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All notable changes to the library will be documented in this file.
66

77
- Add support for `examples` action
88
- Fix conversion of `exactOptional` object properties (pull request #1220)
9+
- Fix conversion of `variant` to use `oneOf` instead of `anyOf` (pull request #1193)
910

1011
## v1.3.0 (June 01, 2025)
1112

packages/to-json-schema/src/converters/convertSchema/convertSchema.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ describe('convertSchema', () => {
882882
createContext()
883883
)
884884
).toStrictEqual({
885-
anyOf: [
885+
oneOf: [
886886
{
887887
type: 'object',
888888
properties: {

packages/to-json-schema/src/converters/convertSchema/convertSchema.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,14 +451,20 @@ export function convertSchema(
451451
break;
452452
}
453453

454-
case 'union':
455-
case 'variant': {
454+
case 'union': {
456455
jsonSchema.anyOf = valibotSchema.options.map((option) =>
457456
convertSchema({}, option as SchemaOrPipe, config, context)
458457
);
459458
break;
460459
}
461460

461+
case 'variant': {
462+
jsonSchema.oneOf = valibotSchema.options.map((option) =>
463+
convertSchema({}, option as SchemaOrPipe, config, context)
464+
);
465+
break;
466+
}
467+
462468
case 'intersect': {
463469
jsonSchema.allOf = valibotSchema.options.map((option) =>
464470
convertSchema({}, option as SchemaOrPipe, config, context)

0 commit comments

Comments
 (0)