From 9e456ee8f8afd79a193bff4b57de27e084bb15cb Mon Sep 17 00:00:00 2001 From: Dale Lane Date: Fri, 8 Mar 2024 18:53:31 +0000 Subject: [PATCH] fix: correct invalid use of cases in switch (#187) --- test/mocks/kafka-example.yml | 3 +++ utils/Types.utils.js | 14 ++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/test/mocks/kafka-example.yml b/test/mocks/kafka-example.yml index d4f7b39..006441c 100644 --- a/test/mocks/kafka-example.yml +++ b/test/mocks/kafka-example.yml @@ -42,6 +42,9 @@ components: genre: type: string description: Primary song genre + something: + type: number + description: some non-integer number length: type: integer description: Track length in seconds diff --git a/utils/Types.utils.js b/utils/Types.utils.js index a4e7830..79f7044 100644 --- a/utils/Types.utils.js +++ b/utils/Types.utils.js @@ -133,13 +133,18 @@ export function asyncApiToDemoValue(type, format) { const boolWords = ['true', 'false']; switch (type) { - case ('integer' || 'long'): + case 'integer': + case 'long': return parseInt(Math.random() * 1000, 10); - case ('float' || 'double'): + case 'float': + case 'double': + case 'number': return Math.random(); - case ('string' || 'binary' || 'password'): + case 'string': + case 'binary': + case 'password': if (format === 'uuid') { return 'UUID.randomUUID()'; } @@ -151,7 +156,8 @@ export function asyncApiToDemoValue(type, format) { case 'boolean': return boolWords[Math.floor(Math.random()*boolWords.length)]; - case ('date' || 'dateTime'): + case 'date': + case 'dateTime': return (new Date()).toISOString().split('T')[0]; default: