Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(next): match anyOf and oneOf error messages #147

Merged
merged 2 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions next/src/validation/composition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function validateAnyOf(
{
path,
validation: 'anyOf',
message: 'Must match at least one of the provided schemas',
message: `The option "${value}" is not valid.`,
},
]
}
Expand Down Expand Up @@ -127,7 +127,7 @@ export function validateOneOf(
{
path,
validation: 'oneOf',
message: 'Must match exactly one of the provided schemas',
message: `The option "${value}" is not valid.`,
},
]
}
Expand All @@ -137,7 +137,7 @@ export function validateOneOf(
{
path,
validation: 'oneOf',
message: 'Must match exactly one schema but matches multiple',
message: `The option "${value}" is not valid.`,
},
]
}
Expand Down
8 changes: 4 additions & 4 deletions next/test/validation/composition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe('schema composition validators', () => {
const errors = validateSchema(value, schema)
expect(errors).toHaveLength(1)
expect(errors[0].validation).toBe('anyOf')
expect(errors[0].message).toBe('Must match at least one of the provided schemas')
expect(errors[0].message).toBe(`The option "${value}" is not valid.`)
})
})

Expand Down Expand Up @@ -256,15 +256,15 @@ describe('schema composition validators', () => {
const errors = validateSchema(value, schema)
expect(errors).toHaveLength(1)
expect(errors[0].validation).toBe('oneOf')
expect(errors[0].message).toBe('Must match exactly one of the provided schemas')
expect(errors[0].message).toBe(`The option "${value}" is not valid.`)
})

it('should fail when value matches multiple schemas', () => {
const value = 15 // multiple of both 3 and 5
const errors = validateSchema(value, schema)
expect(errors).toHaveLength(1)
expect(errors[0].validation).toBe('oneOf')
expect(errors[0].message).toBe('Must match exactly one schema but matches multiple')
expect(errors[0].message).toBe(`The option "${value}" is not valid.`)
})
})

Expand Down Expand Up @@ -322,7 +322,7 @@ describe('schema composition validators', () => {
const errors = validateSchema(value, schema)
expect(errors).toHaveLength(1)
expect(errors[0].validation).toBe('oneOf')
expect(errors[0].message).toBe('Must match exactly one schema but matches multiple')
expect(errors[0].message).toBe(`The option "${value}" is not valid.`)
})
})

Expand Down