diff --git a/packages/functions/src/__tests__/alphabetical.test.ts b/packages/functions/src/__tests__/alphabetical.test.ts index f2883ba73..fe6c20073 100644 --- a/packages/functions/src/__tests__/alphabetical.test.ts +++ b/packages/functions/src/__tests__/alphabetical.test.ts @@ -141,7 +141,7 @@ describe('Core Functions / Alphabetical', () => { [{ keyedBy: 2 }, '"alphabetical" function and its "keyedBy" option accepts only the following types: string'], ])('given invalid %p options, should throw', async (opts, error) => { await expect(runAlphabetical([], opts)).rejects.toThrowAggregateError( - new AggregateError([new RulesetValidationError(error, [])]), + new AggregateError([new RulesetValidationError('invalid-function-options', error, [])]), ); }); }); diff --git a/packages/functions/src/__tests__/casing.test.ts b/packages/functions/src/__tests__/casing.test.ts index 24150bcf9..b78605265 100644 --- a/packages/functions/src/__tests__/casing.test.ts +++ b/packages/functions/src/__tests__/casing.test.ts @@ -379,6 +379,7 @@ describe('Core Functions / Casing', () => { { type: 'foo' }, [ new RulesetValidationError( + 'invalid-function-options', '"casing" function and its "type" option accept the following values: flat, camel, pascal, kebab, cobol, snake, macro', [], ), @@ -386,7 +387,7 @@ describe('Core Functions / Casing', () => { ], [ { type: 'macro', foo: true }, - [new RulesetValidationError('"casing" function does not support "foo" option', [])], + [new RulesetValidationError('invalid-function-options', '"casing" function does not support "foo" option', [])], ], [ { @@ -394,7 +395,13 @@ describe('Core Functions / Casing', () => { disallowDigits: false, separator: {}, }, - [new RulesetValidationError('"casing" function is missing "separator.char" option', [])], + [ + new RulesetValidationError( + 'invalid-function-options', + '"casing" function is missing "separator.char" option', + [], + ), + ], ], [ { @@ -402,11 +409,23 @@ describe('Core Functions / Casing', () => { disallowDigits: false, separator: { allowLeading: true }, }, - [new RulesetValidationError('"casing" function is missing "separator.char" option', [])], + [ + new RulesetValidationError( + 'invalid-function-options', + '"casing" function is missing "separator.char" option', + [], + ), + ], ], [ { type: 'snake', separator: { char: 'a', foo: true } }, - [new RulesetValidationError('"casing" function does not support "separator.foo" option', [])], + [ + new RulesetValidationError( + 'invalid-function-options', + '"casing" function does not support "separator.foo" option', + [], + ), + ], ], [ { @@ -417,6 +436,7 @@ describe('Core Functions / Casing', () => { }, [ new RulesetValidationError( + 'invalid-function-options', '"casing" function and its "separator.char" option accepts only char, i.e. "I" or "/"', [], ), @@ -431,6 +451,7 @@ describe('Core Functions / Casing', () => { }, [ new RulesetValidationError( + 'invalid-function-options', '"casing" function and its "separator.char" option accepts only char, i.e. "I" or "/"', [], ), diff --git a/packages/functions/src/__tests__/defined.test.ts b/packages/functions/src/__tests__/defined.test.ts index deede0bfd..05d3e54b9 100644 --- a/packages/functions/src/__tests__/defined.test.ts +++ b/packages/functions/src/__tests__/defined.test.ts @@ -24,7 +24,9 @@ describe('Core Functions / Defined', () => { describe('validation', () => { it.each([{}, 2])('given invalid %p options, should throw', async opts => { await expect(runDefined([], opts)).rejects.toThrowAggregateError( - new AggregateError([new RulesetValidationError('"defined" function does not accept any options', [])]), + new AggregateError([ + new RulesetValidationError('invalid-function-options', '"defined" function does not accept any options', []), + ]), ); }); }); diff --git a/packages/functions/src/__tests__/enumeration.test.ts b/packages/functions/src/__tests__/enumeration.test.ts index 23dfe379f..ab92c140c 100644 --- a/packages/functions/src/__tests__/enumeration.test.ts +++ b/packages/functions/src/__tests__/enumeration.test.ts @@ -40,7 +40,13 @@ describe('Core Functions / Enumeration', () => { values: ['foo', 2], foo: true, }, - [new RulesetValidationError('"enumeration" function does not support "foo" option', [])], + [ + new RulesetValidationError( + 'invalid-function-options', + '"enumeration" function does not support "foo" option', + [], + ), + ], ], [ { @@ -48,6 +54,7 @@ describe('Core Functions / Enumeration', () => { }, [ new RulesetValidationError( + 'invalid-function-options', '"enumeration" and its "values" option support only arrays of primitive values, i.e. ["Berlin", "London", "Paris"]', [], ), @@ -57,6 +64,7 @@ describe('Core Functions / Enumeration', () => { null, [ new RulesetValidationError( + 'invalid-function-options', '"enumeration" function has invalid options specified. Example valid options: { "values": ["Berlin", "London", "Paris"] }, { "values": [2, 3, 5, 8, 13, 21] }', [], ), @@ -66,6 +74,7 @@ describe('Core Functions / Enumeration', () => { 2, [ new RulesetValidationError( + 'invalid-function-options', '"enumeration" function has invalid options specified. Example valid options: { "values": ["Berlin", "London", "Paris"] }, { "values": [2, 3, 5, 8, 13, 21] }', [], ), diff --git a/packages/functions/src/__tests__/falsy.test.ts b/packages/functions/src/__tests__/falsy.test.ts index 13f620395..7799b442b 100644 --- a/packages/functions/src/__tests__/falsy.test.ts +++ b/packages/functions/src/__tests__/falsy.test.ts @@ -24,7 +24,9 @@ describe('Core Functions / Falsy', () => { describe('validation', () => { it.each([{}, 2])('given invalid %p options, should throw', async opts => { await expect(runFalsy([], opts)).rejects.toThrowAggregateError( - new AggregateError([new RulesetValidationError('"falsy" function does not accept any options', [])]), + new AggregateError([ + new RulesetValidationError('invalid-function-options', '"falsy" function does not accept any options', []), + ]), ); }); }); diff --git a/packages/functions/src/__tests__/length.test.ts b/packages/functions/src/__tests__/length.test.ts index 54ffd46f2..173a5c1ee 100644 --- a/packages/functions/src/__tests__/length.test.ts +++ b/packages/functions/src/__tests__/length.test.ts @@ -59,6 +59,7 @@ describe('Core Functions / Length', () => { null, [ new RulesetValidationError( + 'invalid-function-options', '"length" function has invalid options specified. Example valid options: { "min": 2 }, { "max": 5 }, { "min": 0, "max": 10 }', [], ), @@ -68,6 +69,7 @@ describe('Core Functions / Length', () => { 2, [ new RulesetValidationError( + 'invalid-function-options', '"length" function has invalid options specified. Example valid options: { "min": 2 }, { "max": 5 }, { "min": 0, "max": 10 }', [], ), @@ -78,12 +80,13 @@ describe('Core Functions / Length', () => { min: 2, foo: true, }, - [new RulesetValidationError('"length" function does not support "foo" option', [])], + [new RulesetValidationError('invalid-function-options', '"length" function does not support "foo" option', [])], ], [ { min: '2' }, [ new RulesetValidationError( + 'invalid-function-options', '"length" function and its "min" option accepts only the following types: number', [], ), @@ -94,6 +97,7 @@ describe('Core Functions / Length', () => { { max: '2' }, [ new RulesetValidationError( + 'invalid-function-options', `"length" function and its "max" option accepts only the following types: number`, [], ), @@ -103,10 +107,12 @@ describe('Core Functions / Length', () => { { min: '4', max: '2' }, [ new RulesetValidationError( + 'invalid-function-options', `"length" function and its "min" option accepts only the following types: number`, [], ), new RulesetValidationError( + 'invalid-function-options', `"length" function and its "max" option accepts only the following types: number`, [], ), diff --git a/packages/functions/src/__tests__/pattern.test.ts b/packages/functions/src/__tests__/pattern.test.ts index 9bcfcc424..74b98e084 100644 --- a/packages/functions/src/__tests__/pattern.test.ts +++ b/packages/functions/src/__tests__/pattern.test.ts @@ -57,6 +57,7 @@ describe('Core Functions / Pattern', () => { null, [ new RulesetValidationError( + 'invalid-function-options', '"pattern" function has invalid options specified. Example valid options: { "match": "^Stoplight" }, { "notMatch": "Swagger" }, { "match": "Stoplight", "notMatch": "Swagger" }', [], ), @@ -66,20 +67,37 @@ describe('Core Functions / Pattern', () => { {}, [ new RulesetValidationError( + 'invalid-function-options', `"pattern" function has invalid options specified. Example valid options: { "match": "^Stoplight" }, { "notMatch": "Swagger" }, { "match": "Stoplight", "notMatch": "Swagger" }`, [], ), ], ], - [{ foo: true }, [new RulesetValidationError('"pattern" function does not support "foo" option', [])]], + [ + { foo: true }, + [ + new RulesetValidationError( + 'invalid-function-options', + '"pattern" function does not support "foo" option', + [], + ), + ], + ], [ { match: 2 }, - [new RulesetValidationError('"pattern" function and its "match" option must be string or RegExp instance', [])], + [ + new RulesetValidationError( + 'invalid-function-options', + '"pattern" function and its "match" option must be string or RegExp instance', + [], + ), + ], ], [ { notMatch: null }, [ new RulesetValidationError( + 'invalid-function-options', '"pattern" function and its "notMatch" option must be string or RegExp instance', [], ), @@ -88,8 +106,13 @@ describe('Core Functions / Pattern', () => { [ { match: 4, notMatch: 10 }, [ - new RulesetValidationError(`"pattern" function and its "match" option must be string or RegExp instance`, []), new RulesetValidationError( + 'invalid-function-options', + `"pattern" function and its "match" option must be string or RegExp instance`, + [], + ), + new RulesetValidationError( + 'invalid-function-options', `"pattern" function and its "notMatch" option must be string or RegExp instance`, [], ), diff --git a/packages/functions/src/__tests__/schema.test.ts b/packages/functions/src/__tests__/schema.test.ts index 562226d5f..ee7b53950 100644 --- a/packages/functions/src/__tests__/schema.test.ts +++ b/packages/functions/src/__tests__/schema.test.ts @@ -483,6 +483,7 @@ describe('Core Functions / Schema', () => { 2, [ new RulesetValidationError( + 'invalid-function-options', '"schema" function has invalid options specified. Example valid options: { "schema": { /* any JSON Schema can be defined here */ } , { "schema": { "type": "object" }, "dialect": "auto" }', [], ), @@ -490,16 +491,23 @@ describe('Core Functions / Schema', () => { ], [ { schema: { type: 'object' }, foo: true }, - [new RulesetValidationError('"schema" function does not support "foo" option', [])], + [new RulesetValidationError('invalid-function-options', '"schema" function does not support "foo" option', [])], ], [ { schema: { type: 'object' }, oasVersion: 1 }, - [new RulesetValidationError('"schema" function does not support "oasVersion" option', [])], + [ + new RulesetValidationError( + 'invalid-function-options', + '"schema" function does not support "oasVersion" option', + [], + ), + ], ], [ { schema: { type: 'object' }, dialect: 'foo' }, [ new RulesetValidationError( + 'invalid-function-options', '"schema" function and its "dialect" option accepts only the following values: "auto", "draft4", "draft6", "draft7", "draft2019-09", "draft2020-12"', [], ), @@ -509,6 +517,7 @@ describe('Core Functions / Schema', () => { { schema: { type: 'object' }, allErrors: null }, [ new RulesetValidationError( + 'invalid-function-options', '"schema" function and its "allErrors" option accepts only the following types: boolean', [], ), @@ -518,10 +527,12 @@ describe('Core Functions / Schema', () => { { schema: null, allErrors: null }, [ new RulesetValidationError( + 'invalid-function-options', `"schema" function and its "schema" option accepts only the following types: object`, [], ), new RulesetValidationError( + 'invalid-function-options', `"schema" function and its "allErrors" option accepts only the following types: boolean`, [], ), diff --git a/packages/functions/src/__tests__/truthy.test.ts b/packages/functions/src/__tests__/truthy.test.ts index d49ff8ab7..b135382a2 100644 --- a/packages/functions/src/__tests__/truthy.test.ts +++ b/packages/functions/src/__tests__/truthy.test.ts @@ -24,7 +24,9 @@ describe('Core Functions / Truthy', () => { describe('validation', () => { it.each([{}, 2])('given invalid %p options, should throw', async opts => { await expect(runTruthy([], opts)).rejects.toThrowAggregateError( - new AggregateError([new RulesetValidationError('"truthy" function does not accept any options', [])]), + new AggregateError([ + new RulesetValidationError('invalid-function-options', '"truthy" function does not accept any options', []), + ]), ); }); }); diff --git a/packages/functions/src/__tests__/unreferencedReusableObject.test.ts b/packages/functions/src/__tests__/unreferencedReusableObject.test.ts index c49bee68c..7fdcbe80b 100644 --- a/packages/functions/src/__tests__/unreferencedReusableObject.test.ts +++ b/packages/functions/src/__tests__/unreferencedReusableObject.test.ts @@ -32,6 +32,7 @@ describe('Core Functions / UnreferencedReusableObject', () => { null, [ new RulesetValidationError( + 'invalid-function-options', '"unreferencedReusableObject" function has invalid options specified. Example valid options: { "reusableObjectsLocation": "#/components/schemas" }, { "reusableObjectsLocation": "#/$defs" }', [], ), @@ -41,6 +42,7 @@ describe('Core Functions / UnreferencedReusableObject', () => { 2, [ new RulesetValidationError( + 'invalid-function-options', '"unreferencedReusableObject" function has invalid options specified. Example valid options: { "reusableObjectsLocation": "#/components/schemas" }, { "reusableObjectsLocation": "#/$defs" }', [], ), @@ -50,6 +52,7 @@ describe('Core Functions / UnreferencedReusableObject', () => { {}, [ new RulesetValidationError( + 'invalid-function-options', '"unreferencedReusableObject" function is missing "reusableObjectsLocation" option. Example valid options: { "reusableObjectsLocation": "#/components/schemas" }, { "reusableObjectsLocation": "#/$defs" }', [], ), @@ -60,7 +63,13 @@ describe('Core Functions / UnreferencedReusableObject', () => { reusableObjectsLocation: '#', foo: true, }, - [new RulesetValidationError('"unreferencedReusableObject" function does not support "foo" option', [])], + [ + new RulesetValidationError( + 'invalid-function-options', + '"unreferencedReusableObject" function does not support "foo" option', + [], + ), + ], ], [ { @@ -68,6 +77,7 @@ describe('Core Functions / UnreferencedReusableObject', () => { }, [ new RulesetValidationError( + 'invalid-function-options', '"unreferencedReusableObject" and its "reusableObjectsLocation" option support only valid JSON Pointer fragments, i.e. "#", "#/foo", "#/paths/~1user"', [], ), @@ -79,6 +89,7 @@ describe('Core Functions / UnreferencedReusableObject', () => { }, [ new RulesetValidationError( + 'invalid-function-options', '"unreferencedReusableObject" and its "reusableObjectsLocation" option support only valid JSON Pointer fragments, i.e. "#", "#/foo", "#/paths/~1user"', [], ), diff --git a/packages/functions/src/__tests__/xor.test.ts b/packages/functions/src/__tests__/xor.test.ts index 908f8e3d1..2bf7deed7 100644 --- a/packages/functions/src/__tests__/xor.test.ts +++ b/packages/functions/src/__tests__/xor.test.ts @@ -71,6 +71,7 @@ describe('Core Functions / Xor', () => { null, [ new RulesetValidationError( + 'invalid-function-options', '"xor" function has invalid options specified. Example valid options: { "properties": ["id", "name"] }, { "properties": ["country", "street"] }', [], ), @@ -80,6 +81,7 @@ describe('Core Functions / Xor', () => { 2, [ new RulesetValidationError( + 'invalid-function-options', '"xor" function has invalid options specified. Example valid options: { "properties": ["id", "name"] }, { "properties": ["country", "street"] }', [], ), @@ -87,12 +89,13 @@ describe('Core Functions / Xor', () => { ], [ { properties: ['foo', 'bar'], foo: true }, - [new RulesetValidationError('"xor" function does not support "foo" option', [])], + [new RulesetValidationError('invalid-function-options', '"xor" function does not support "foo" option', [])], ], [ { properties: ['foo', 'bar', 'baz'] }, [ new RulesetValidationError( + 'invalid-function-options', '"xor" and its "properties" option support 2-item tuples, i.e. ["id", "name"]', [], ), @@ -102,6 +105,7 @@ describe('Core Functions / Xor', () => { { properties: ['foo', {}] }, [ new RulesetValidationError( + 'invalid-function-options', '"xor" and its "properties" option support 2-item tuples, i.e. ["id", "name"]', [], ), @@ -111,6 +115,7 @@ describe('Core Functions / Xor', () => { { properties: ['foo'] }, [ new RulesetValidationError( + 'invalid-function-options', '"xor" and its "properties" option support 2-item tuples, i.e. ["id", "name"]', [], ), @@ -120,6 +125,7 @@ describe('Core Functions / Xor', () => { { properties: [] }, [ new RulesetValidationError( + 'invalid-function-options', '"xor" and its "properties" option support 2-item tuples, i.e. ["id", "name"]', [], ),