Skip to content

Commit

Permalink
fixup! WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nulltoken committed Feb 20, 2020
1 parent 0d36346 commit 3ddd35a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
7 changes: 2 additions & 5 deletions src/formats/asyncapi.ts
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 5 additions & 0 deletions src/formats/bearsAStringPropertyNamed.ts
Original file line number Diff line number Diff line change
@@ -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';
};
6 changes: 1 addition & 5 deletions src/formats/openapi.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down

0 comments on commit 3ddd35a

Please sign in to comment.