From 726774e6b3e9ff97ee063e0a7468a3ba5b523196 Mon Sep 17 00:00:00 2001 From: Timon Back Date: Fri, 24 May 2024 18:26:35 +0200 Subject: [PATCH] fix(rulesets): always allow string examples in asyncapi schema MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: David Müller --- .../functions/__tests__/asyncApi2SchemaValidation.test.ts | 8 ++++---- .../src/asyncapi/functions/asyncApi2SchemaValidation.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/rulesets/src/asyncapi/functions/__tests__/asyncApi2SchemaValidation.test.ts b/packages/rulesets/src/asyncapi/functions/__tests__/asyncApi2SchemaValidation.test.ts index db2ef4255..e4538dc5c 100644 --- a/packages/rulesets/src/asyncapi/functions/__tests__/asyncApi2SchemaValidation.test.ts +++ b/packages/rulesets/src/asyncapi/functions/__tests__/asyncApi2SchemaValidation.test.ts @@ -7,19 +7,19 @@ function runPayloadValidation(targetVal: any, opts: { type: 'examples' | 'defaul describe('asyncApi2SchemaValidation', () => { test('validates examples', () => { const payload = { - type: 'string', - examples: [17, 'one', 13], + type: 'object', + examples: [17, {}, 13, 'string-is-always-accepted'], }; const results = runPayloadValidation(payload, { type: 'examples' }); expect(results).toEqual([ { - message: '"0" property type must be string', + message: '"0" property type must be object', path: ['examples', 0], }, { - message: '"2" property type must be string', + message: '"2" property type must be object', path: ['examples', 2], }, ]); diff --git a/packages/rulesets/src/asyncapi/functions/asyncApi2SchemaValidation.ts b/packages/rulesets/src/asyncapi/functions/asyncApi2SchemaValidation.ts index dc36f0692..3fa907b03 100644 --- a/packages/rulesets/src/asyncapi/functions/asyncApi2SchemaValidation.ts +++ b/packages/rulesets/src/asyncapi/functions/asyncApi2SchemaValidation.ts @@ -67,7 +67,7 @@ export default createRulesetFunction( }, ); - if (Array.isArray(result)) { + if (Array.isArray(result) && typeof relevantItem.value !== 'string') { results.push(...result); } }