From 3ddd35adb02397147b5de95875778840d7f972dc Mon Sep 17 00:00:00 2001 From: nulltoken Date: Thu, 20 Feb 2020 08:07:15 +0100 Subject: [PATCH] fixup! WIP --- src/formats/asyncapi.ts | 7 ++----- src/formats/bearsAStringPropertyNamed.ts | 5 +++++ src/formats/openapi.ts | 6 +----- 3 files changed, 8 insertions(+), 10 deletions(-) create mode 100644 src/formats/bearsAStringPropertyNamed.ts diff --git a/src/formats/asyncapi.ts b/src/formats/asyncapi.ts index 97ad30a9cd..f50852e0fd 100644 --- a/src/formats/asyncapi.ts +++ b/src/formats/asyncapi.ts @@ -1,9 +1,6 @@ -import { isObject } from 'lodash'; +import { bearsAStringPropertyNamed } from './bearsAStringPropertyNamed'; type MaybeAsyncApi2 = Partial<{ asyncapi: unknown }>; export const isAsyncApiv2 = (document: unknown) => - isObject(document) && - 'asyncapi' in document && - typeof document.asyncapi === 'string' && - parseFloat(String((document as MaybeAsyncApi2).asyncapi)) === 2; + bearsAStringPropertyNamed(document, 'asyncapi') && parseFloat(String((document as MaybeAsyncApi2).asyncapi)) === 2; diff --git a/src/formats/bearsAStringPropertyNamed.ts b/src/formats/bearsAStringPropertyNamed.ts new file mode 100644 index 0000000000..cf778a53c1 --- /dev/null +++ b/src/formats/bearsAStringPropertyNamed.ts @@ -0,0 +1,5 @@ +import { isObject } from 'lodash'; + +export const bearsAStringPropertyNamed = (document: unknown, propertyName: string) => { + return isObject(document) && propertyName in document && typeof document[propertyName] === 'string'; +}; diff --git a/src/formats/openapi.ts b/src/formats/openapi.ts index 7e2312b68e..a857764bbd 100644 --- a/src/formats/openapi.ts +++ b/src/formats/openapi.ts @@ -1,12 +1,8 @@ -import { isObject } from 'lodash'; +import { bearsAStringPropertyNamed } from './bearsAStringPropertyNamed'; type MaybeOAS2 = Partial<{ swagger: unknown }>; type MaybeOAS3 = Partial<{ openapi: unknown }>; -const bearsAStringPropertyNamed = (document: unknown, propertyName: string) => { - return isObject(document) && propertyName in document && typeof document[propertyName] === 'string'; -}; - export const isOpenApiv2 = (document: unknown) => bearsAStringPropertyNamed(document, 'swagger') && String((document as MaybeOAS2).swagger) === '2.0';