From 542724400c72edcf30186ad23079a6582e76a671 Mon Sep 17 00:00:00 2001 From: Sergio Moya <1083296+smoya@users.noreply.github.com> Date: Fri, 11 Mar 2022 11:46:09 +0100 Subject: [PATCH] refactor: interface and implementations for each major spec version (#488) --- src/lint.ts | 4 +-- src/models/asyncapi.ts | 28 +++++++++++++----- src/models/contact.ts | 16 +++------- src/models/index.ts | 6 ++-- src/models/info.ts | 37 ++++++----------------- src/models/license.ts | 11 ++----- src/models/v2/asyncapi.ts | 13 ++++++++ src/models/v2/contact.ts | 16 ++++++++++ src/models/v2/index.ts | 4 +++ src/models/v2/info.ts | 32 ++++++++++++++++++++ src/models/v2/license.ts | 12 ++++++++ src/models/v3/asyncapi.ts | 13 ++++++++ src/models/v3/contact.ts | 16 ++++++++++ src/models/v3/index.ts | 4 +++ src/models/v3/info.ts | 32 ++++++++++++++++++++ src/models/v3/license.ts | 12 ++++++++ src/parse.ts | 6 ++-- src/stringify.ts | 6 ++-- src/types.ts | 6 ++-- src/utils.ts | 10 +++---- test/models/asyncapi.spec.ts | 26 ---------------- test/models/v2/asyncapi.spec.ts | 44 ++++++++++++++++++++++++++++ test/models/{ => v2}/contact.spec.ts | 2 +- test/models/{ => v2}/info.spec.ts | 6 ++-- test/models/{ => v2}/license.spec.ts | 2 +- test/parse.spec.ts | 4 +-- test/stringify.spec.ts | 6 ++-- test/utils.spec.ts | 18 ++++++------ 28 files changed, 274 insertions(+), 118 deletions(-) create mode 100644 src/models/v2/asyncapi.ts create mode 100644 src/models/v2/contact.ts create mode 100644 src/models/v2/index.ts create mode 100644 src/models/v2/info.ts create mode 100644 src/models/v2/license.ts create mode 100644 src/models/v3/asyncapi.ts create mode 100644 src/models/v3/contact.ts create mode 100644 src/models/v3/index.ts create mode 100644 src/models/v3/info.ts create mode 100644 src/models/v3/license.ts delete mode 100644 test/models/asyncapi.spec.ts create mode 100644 test/models/v2/asyncapi.spec.ts rename test/models/{ => v2}/contact.spec.ts (95%) rename test/models/{ => v2}/info.spec.ts (93%) rename test/models/{ => v2}/license.spec.ts (93%) diff --git a/src/lint.ts b/src/lint.ts index f108ea5ae..33d2559de 100644 --- a/src/lint.ts +++ b/src/lint.ts @@ -9,7 +9,7 @@ import { asyncapi as aasRuleset } from "@stoplight/spectral-rulesets"; import { toAsyncAPIDocument, normalizeInput, hasWarningDiagnostic, hasErrorDiagnostic } from "./utils"; -import type { AsyncAPIDocument } from "./models/asyncapi"; +import type { AsyncAPIDocumentInterface } from "./models/asyncapi"; import type { ParserInput, Diagnostic } from "./types"; export interface LintOptions extends IConstructorOpts, IRunOpts { @@ -31,7 +31,7 @@ export async function lint(asyncapi: ParserInput, options?: LintOptions): Promis if (toAsyncAPIDocument(asyncapi)) { return; } - const document = normalizeInput(asyncapi as Exclude); + const document = normalizeInput(asyncapi as Exclude); return (await validate(document, options)).diagnostics; } diff --git a/src/models/asyncapi.ts b/src/models/asyncapi.ts index e2d881b37..b370204c0 100644 --- a/src/models/asyncapi.ts +++ b/src/models/asyncapi.ts @@ -1,12 +1,26 @@ +import { InfoInterface } from "./info"; import { BaseModel } from "./base"; -import { Info } from "./info"; +import { AsyncAPIDocumentV2 } from "./v2"; +import { AsyncAPIDocumentV3 } from "./v3"; -export class AsyncAPIDocument extends BaseModel { - version(): string { - return this.json("asyncapi"); +export interface AsyncAPIDocumentInterface extends BaseModel { + version(): string; + info(): InfoInterface +} + +export function newAsyncAPIDocument(json: Record): AsyncAPIDocumentInterface { + const version = json['asyncapi']; // Maybe this should be an arg. + if (version == undefined || version == null || version == '') { + throw new Error('Missing AsyncAPI version in document'); } - info(): Info { - return new Info(this.json("info")); + const major = version.split(".")[0]; + switch (major) { + case '2': + return new AsyncAPIDocumentV2(json); + case '3': + return new AsyncAPIDocumentV3(json); + default: + throw new Error(`Unsupported version: ${version}`); } -} +} \ No newline at end of file diff --git a/src/models/contact.ts b/src/models/contact.ts index 76b6c43d0..7564d384d 100644 --- a/src/models/contact.ts +++ b/src/models/contact.ts @@ -1,15 +1,7 @@ import { BaseModel } from "./base"; -export class Contact extends BaseModel { - name(): string { - return this.json("name"); - } - - url(): string { - return this.json("url"); - } - - email(): string { - return this.json("email"); - } +export interface ContactInterface extends BaseModel { + name(): string; + url(): string; + email(): string; } \ No newline at end of file diff --git a/src/models/index.ts b/src/models/index.ts index 175d27111..dc0a434a7 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -1,5 +1,7 @@ +export * from './v2'; +export * from './v3'; export * from './asyncapi'; export * from './base'; -export * from './contact'; export * from './info'; -export * from './license'; \ No newline at end of file +export * from './contact'; +export * from './license'; diff --git a/src/models/info.ts b/src/models/info.ts index 0ba3af1f5..8909b8bfd 100644 --- a/src/models/info.ts +++ b/src/models/info.ts @@ -1,31 +1,12 @@ +import { ContactInterface } from "./contact"; +import { LicenseInterface } from "./license"; import { BaseModel } from "./base"; -import { Contact } from "./contact"; -import { License } from "./license"; -export class Info extends BaseModel { - title(): string { - return this.json("title"); - } - - version(): string { - return this.json("version"); - } - - description(): string { - return this.json("description"); - } - - termsOfService(): string { - return this.json("termsOfService"); - } - - contact(): Contact | undefined { - const doc = this.json("contact"); - return doc && new Contact(doc); - } - - license(): License | undefined { - const doc = this.json("license"); - return doc && new License(doc); - } +export interface InfoInterface extends BaseModel { + title(): string; + version(): string; + description(): string; + termsOfService(): string; + contact(): ContactInterface | undefined; + license(): LicenseInterface | undefined; } \ No newline at end of file diff --git a/src/models/license.ts b/src/models/license.ts index 8f2b4c939..aeb50ee7e 100644 --- a/src/models/license.ts +++ b/src/models/license.ts @@ -1,11 +1,6 @@ import { BaseModel } from "./base"; -export class License extends BaseModel { - name(): string { - return this.json("name"); - } - - url(): string { - return this.json("url"); - } +export interface LicenseInterface extends BaseModel { + name(): string; + url(): string; } \ No newline at end of file diff --git a/src/models/v2/asyncapi.ts b/src/models/v2/asyncapi.ts new file mode 100644 index 000000000..e170a7716 --- /dev/null +++ b/src/models/v2/asyncapi.ts @@ -0,0 +1,13 @@ +import { AsyncAPIDocumentInterface } from "../../models"; +import { BaseModel } from "../base"; +import { Info } from "./info"; + +export class AsyncAPIDocument extends BaseModel implements AsyncAPIDocumentInterface { + version(): string { + return this.json("asyncapi"); + } + + info(): Info { + return new Info(this.json("info")); + } +} diff --git a/src/models/v2/contact.ts b/src/models/v2/contact.ts new file mode 100644 index 000000000..d16af7df3 --- /dev/null +++ b/src/models/v2/contact.ts @@ -0,0 +1,16 @@ +import { ContactInterface } from "../../models/contact"; +import { BaseModel } from "../base"; + +export class Contact extends BaseModel implements ContactInterface { + name(): string { + return this.json("name"); + } + + url(): string { + return this.json("url"); + } + + email(): string { + return this.json("email"); + } +} \ No newline at end of file diff --git a/src/models/v2/index.ts b/src/models/v2/index.ts new file mode 100644 index 000000000..a06d7d121 --- /dev/null +++ b/src/models/v2/index.ts @@ -0,0 +1,4 @@ +export { AsyncAPIDocument as AsyncAPIDocumentV2 } from './asyncapi'; +export { Contact as ContactV2 } from './contact'; +export { Info as InfoV2 } from './info'; +export { License as LicenseV2 } from './license'; \ No newline at end of file diff --git a/src/models/v2/info.ts b/src/models/v2/info.ts new file mode 100644 index 000000000..d6f594e8b --- /dev/null +++ b/src/models/v2/info.ts @@ -0,0 +1,32 @@ +import { InfoInterface } from "../../models/info"; +import { BaseModel } from "../base"; +import { Contact } from "./contact"; +import { License } from "./license"; + +export class Info extends BaseModel implements InfoInterface { + title(): string { + return this.json("title"); + } + + version(): string { + return this.json("version"); + } + + description(): string { + return this.json("description"); + } + + termsOfService(): string { + return this.json("termsOfService"); + } + + contact(): Contact | undefined { + const doc = this.json("contact"); + return doc && new Contact(doc); + } + + license(): License | undefined { + const doc = this.json("license"); + return doc && new License(doc); + } +} \ No newline at end of file diff --git a/src/models/v2/license.ts b/src/models/v2/license.ts new file mode 100644 index 000000000..67eb74d97 --- /dev/null +++ b/src/models/v2/license.ts @@ -0,0 +1,12 @@ +import { LicenseInterface } from "../../models/license"; +import { BaseModel } from "../base"; + +export class License extends BaseModel implements LicenseInterface { + name(): string { + return this.json("name"); + } + + url(): string { + return this.json("url"); + } +} \ No newline at end of file diff --git a/src/models/v3/asyncapi.ts b/src/models/v3/asyncapi.ts new file mode 100644 index 000000000..08802da35 --- /dev/null +++ b/src/models/v3/asyncapi.ts @@ -0,0 +1,13 @@ +import { AsyncAPIDocumentInterface } from "../../models/asyncapi"; +import { BaseModel } from "../base"; +import { Info } from "./info"; + +export class AsyncAPIDocument extends BaseModel implements AsyncAPIDocumentInterface { + version(): string { + return this.json("asyncapi"); + } + + info(): Info { + return new Info(this.json("info")); + } +} diff --git a/src/models/v3/contact.ts b/src/models/v3/contact.ts new file mode 100644 index 000000000..d16af7df3 --- /dev/null +++ b/src/models/v3/contact.ts @@ -0,0 +1,16 @@ +import { ContactInterface } from "../../models/contact"; +import { BaseModel } from "../base"; + +export class Contact extends BaseModel implements ContactInterface { + name(): string { + return this.json("name"); + } + + url(): string { + return this.json("url"); + } + + email(): string { + return this.json("email"); + } +} \ No newline at end of file diff --git a/src/models/v3/index.ts b/src/models/v3/index.ts new file mode 100644 index 000000000..7be2b264d --- /dev/null +++ b/src/models/v3/index.ts @@ -0,0 +1,4 @@ +export { AsyncAPIDocument as AsyncAPIDocumentV3 } from './asyncapi'; +export { Contact as ContactV3 } from './contact'; +export { Info as InfoV3 } from './info'; +export { License as LicenseV3 } from './license'; \ No newline at end of file diff --git a/src/models/v3/info.ts b/src/models/v3/info.ts new file mode 100644 index 000000000..d6f594e8b --- /dev/null +++ b/src/models/v3/info.ts @@ -0,0 +1,32 @@ +import { InfoInterface } from "../../models/info"; +import { BaseModel } from "../base"; +import { Contact } from "./contact"; +import { License } from "./license"; + +export class Info extends BaseModel implements InfoInterface { + title(): string { + return this.json("title"); + } + + version(): string { + return this.json("version"); + } + + description(): string { + return this.json("description"); + } + + termsOfService(): string { + return this.json("termsOfService"); + } + + contact(): Contact | undefined { + const doc = this.json("contact"); + return doc && new Contact(doc); + } + + license(): License | undefined { + const doc = this.json("license"); + return doc && new License(doc); + } +} \ No newline at end of file diff --git a/src/models/v3/license.ts b/src/models/v3/license.ts new file mode 100644 index 000000000..67eb74d97 --- /dev/null +++ b/src/models/v3/license.ts @@ -0,0 +1,12 @@ +import { LicenseInterface } from "../../models/license"; +import { BaseModel } from "../base"; + +export class License extends BaseModel implements LicenseInterface { + name(): string { + return this.json("name"); + } + + url(): string { + return this.json("url"); + } +} \ No newline at end of file diff --git a/src/parse.ts b/src/parse.ts index 9fe9a1253..10c700316 100644 --- a/src/parse.ts +++ b/src/parse.ts @@ -1,4 +1,4 @@ -import { AsyncAPIDocument } from "./models"; +import { AsyncAPIDocumentInterface, newAsyncAPIDocument } from "./models"; import { normalizeInput, toAsyncAPIDocument } from "./utils"; import { validate } from "./lint"; @@ -21,7 +21,7 @@ export async function parse(asyncapi: ParserInput, options?: ParseOptions): Prom } try { - const document = normalizeInput(asyncapi as Exclude); + const document = normalizeInput(asyncapi as Exclude); options = normalizeOptions(options); const { validated, diagnostics } = await validate(document, options.validateOptions); @@ -33,7 +33,7 @@ export async function parse(asyncapi: ParserInput, options?: ParseOptions): Prom }; } - const parsed = new AsyncAPIDocument(validated as Record); + const parsed = newAsyncAPIDocument(validated as Record); return { source: asyncapi, parsed, diff --git a/src/stringify.ts b/src/stringify.ts index d4287a8b3..1f0d3910d 100644 --- a/src/stringify.ts +++ b/src/stringify.ts @@ -1,4 +1,4 @@ -import { AsyncAPIDocument } from './models'; +import { AsyncAPIDocumentInterface, newAsyncAPIDocument } from './models'; import { isAsyncAPIDocument, isParsedDocument, isStringifiedDocument } from './utils'; import { xParserSpecStringified } from './constants'; @@ -25,7 +25,7 @@ export function stringify(document: unknown, options: StringifyOptions = {}): st }, refReplacer(), options.space || 2); } -export function unstringify(document: unknown): AsyncAPIDocument | undefined { +export function unstringify(document: unknown): AsyncAPIDocumentInterface | undefined { if (!isStringifiedDocument(document)) { return; } @@ -36,7 +36,7 @@ export function unstringify(document: unknown): AsyncAPIDocument | undefined { delete (>document)[String(xParserSpecStringified)]; traverseStringifiedDoc(document, undefined, document, new Map(), new Map()); - return new AsyncAPIDocument(>document); + return newAsyncAPIDocument(>document); } function refReplacer() { diff --git a/src/types.ts b/src/types.ts index 73bf56bdd..9cf8431ba 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,13 +1,13 @@ import type { ISpectralDiagnostic } from '@stoplight/spectral-core'; -import type { AsyncAPIDocument } from './models/asyncapi'; +import type { AsyncAPIDocumentInterface } from './models/asyncapi'; export type MaybeAsyncAPI = { asyncapi: unknown } & Record; -export type ParserInput = string | MaybeAsyncAPI | AsyncAPIDocument; +export type ParserInput = string | MaybeAsyncAPI | AsyncAPIDocumentInterface; export type Diagnostic = ISpectralDiagnostic; export interface ParserOutput { source: ParserInput; - parsed: AsyncAPIDocument | undefined; + parsed: AsyncAPIDocumentInterface | undefined; diagnostics: Diagnostic[]; } diff --git a/src/utils.ts b/src/utils.ts index 253a8026e..69fc1ffa6 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,5 @@ import { DiagnosticSeverity } from '@stoplight/types'; -import { AsyncAPIDocument } from './models'; +import { newAsyncAPIDocument, AsyncAPIDocumentInterface, AsyncAPIDocumentV2, AsyncAPIDocumentV3 } from './models'; import { unstringify } from './stringify'; import { @@ -10,18 +10,18 @@ import { import type { ISpectralDiagnostic } from '@stoplight/spectral-core'; import type { MaybeAsyncAPI } from 'types'; -export function toAsyncAPIDocument(maybeDoc: unknown): AsyncAPIDocument | undefined { +export function toAsyncAPIDocument(maybeDoc: unknown): AsyncAPIDocumentInterface | undefined { if (isAsyncAPIDocument(maybeDoc)) { return maybeDoc; } if (!isParsedDocument(maybeDoc)) { return; } - return unstringify(maybeDoc) || new AsyncAPIDocument(maybeDoc); + return unstringify(maybeDoc) || newAsyncAPIDocument(maybeDoc); } -export function isAsyncAPIDocument(maybeDoc: unknown): maybeDoc is AsyncAPIDocument { - return maybeDoc instanceof AsyncAPIDocument; +export function isAsyncAPIDocument(maybeDoc: unknown): maybeDoc is AsyncAPIDocumentInterface { + return maybeDoc instanceof AsyncAPIDocumentV2 || maybeDoc instanceof AsyncAPIDocumentV3; } export function isParsedDocument(maybeDoc: unknown): maybeDoc is Record { diff --git a/test/models/asyncapi.spec.ts b/test/models/asyncapi.spec.ts deleted file mode 100644 index f73e9b404..000000000 --- a/test/models/asyncapi.spec.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { AsyncAPIDocument } from '../../src/models/asyncapi'; -import { Info } from '../../src/models/info'; - -describe('AsyncAPIDocument model', function() { - describe('.version()', function() { - it('should return the value', function() { - const doc = { asyncapi: "3.0.0" }; - const d = new AsyncAPIDocument(doc); - expect(d.version()).toEqual(doc.asyncapi); - }); - - it('should return undefined when there is no value', function() { - const doc = { }; - const d = new AsyncAPIDocument(doc); - expect(d.version()).toBeUndefined(); - }); - }); - - describe('.info()', function() { - it('should return an Info object', function() { - const doc = { info: { name: "LeChuck" } }; - const d = new AsyncAPIDocument(doc); - expect(d.info() instanceof Info).toBeTruthy(); - }); - }); -}); diff --git a/test/models/v2/asyncapi.spec.ts b/test/models/v2/asyncapi.spec.ts new file mode 100644 index 000000000..cad7e418f --- /dev/null +++ b/test/models/v2/asyncapi.spec.ts @@ -0,0 +1,44 @@ +import { newAsyncAPIDocument, AsyncAPIDocumentV2, InfoV2, AsyncAPIDocumentV3 } from '../../../src/models'; + +describe('AsyncAPIDocument model', function() { + describe('.version()', function() { + it('should return the value', function() { + const doc = { asyncapi: "3.0.0" }; + const d = new AsyncAPIDocumentV2(doc); + expect(d.version()).toEqual(doc.asyncapi); + }); + + it('should return undefined when there is no value', function() { + const doc = { }; + const d = new AsyncAPIDocumentV2(doc); + expect(d.version()).toBeUndefined(); + }); + }); + + describe('.info()', function() { + it('should return an Info object', function() { + const doc = { info: { name: "LeChuck" } }; + const d = new AsyncAPIDocumentV2(doc); + expect(d.info() instanceof InfoV2).toBeTruthy(); + }); + }); +}); + +describe('AsyncAPIDocument factory', function() { + it('should create a valid document from v2.0.0', function() { + const doc = { asyncapi: "2.0.0" }; + const d = newAsyncAPIDocument(doc) + expect(d.version()).toEqual(doc.asyncapi); + expect(d).toBeInstanceOf(AsyncAPIDocumentV2); + }); + it('should create a valid document from v3.0.0', function() { + const doc = { asyncapi: "3.0.0" }; + const d = newAsyncAPIDocument(doc) + expect(d.version()).toEqual(doc.asyncapi); + expect(d).toBeInstanceOf(AsyncAPIDocumentV3); + }); + it('should fail trying to create a document from a non supported spec version', function() { + const doc = { asyncapi: "99.99.99" }; + expect(() => newAsyncAPIDocument(doc)).toThrow("Unsupported version: 99.99.99"); + }); +}); diff --git a/test/models/contact.spec.ts b/test/models/v2/contact.spec.ts similarity index 95% rename from test/models/contact.spec.ts rename to test/models/v2/contact.spec.ts index 32c92d478..d9194f3e7 100644 --- a/test/models/contact.spec.ts +++ b/test/models/v2/contact.spec.ts @@ -1,4 +1,4 @@ -import { Contact } from '../../src/models/contact'; +import { Contact } from '../../../src/models/v2/contact'; describe('Contact model', function() { describe('.name()', function() { diff --git a/test/models/info.spec.ts b/test/models/v2/info.spec.ts similarity index 93% rename from test/models/info.spec.ts rename to test/models/v2/info.spec.ts index 32abd3314..4d7380629 100644 --- a/test/models/info.spec.ts +++ b/test/models/v2/info.spec.ts @@ -1,6 +1,6 @@ -import { Contact } from '../../src/models/contact'; -import { Info } from '../../src/models/info'; -import { License } from '../../src/models/license'; +import { Contact } from '../../../src/models/v2/contact'; +import { Info } from '../../../src/models/v2/info'; +import { License } from '../../../src/models/v2/license'; describe('Info model', function() { describe('.title()', function() { diff --git a/test/models/license.spec.ts b/test/models/v2/license.spec.ts similarity index 93% rename from test/models/license.spec.ts rename to test/models/v2/license.spec.ts index 7bcd1671a..992b54791 100644 --- a/test/models/license.spec.ts +++ b/test/models/v2/license.spec.ts @@ -1,4 +1,4 @@ -import { License } from '../../src/models/license'; +import { License } from '../../../src/models/v2/license'; describe('License model', function() { describe('.name()', function() { diff --git a/test/parse.spec.ts b/test/parse.spec.ts index 3d17329f3..964fcb4f6 100644 --- a/test/parse.spec.ts +++ b/test/parse.spec.ts @@ -1,4 +1,4 @@ -import { AsyncAPIDocument } from '../src/models/asyncapi'; +import { AsyncAPIDocumentV2 } from '../src/models'; import { parse } from '../src/parse'; describe('parse()', function() { @@ -13,7 +13,7 @@ describe('parse()', function() { } const { parsed, diagnostics } = await parse(document); - expect(parsed).toBeInstanceOf(AsyncAPIDocument); + expect(parsed).toBeInstanceOf(AsyncAPIDocumentV2); expect(diagnostics.length > 0).toEqual(true); }); diff --git a/test/stringify.spec.ts b/test/stringify.spec.ts index e23e9598d..6c515f886 100644 --- a/test/stringify.spec.ts +++ b/test/stringify.spec.ts @@ -1,5 +1,5 @@ import { xParserSpecParsed, xParserSpecStringified } from '../src/constants'; -import { AsyncAPIDocument, BaseModel } from '../src/models'; +import { BaseModel, newAsyncAPIDocument } from '../src/models'; import { stringify, unstringify } from '../src/stringify'; describe('stringify & unstringify', function() { @@ -29,7 +29,7 @@ describe('stringify & unstringify', function() { }); it('should stringify AsyncAPIDocument instance', function() { - expect(typeof stringify(new AsyncAPIDocument({ asyncapi: '2.0.0' }))).toEqual('string'); + expect(typeof stringify(newAsyncAPIDocument({ asyncapi: '2.0.0' }))).toEqual('string'); }); }); @@ -55,7 +55,7 @@ describe('stringify & unstringify', function() { }); it('should unstringify stringified document', function() { - expect(unstringify({ [xParserSpecParsed]: true, [xParserSpecStringified]: true })).not.toEqual(undefined); + expect(unstringify({ asyncapi: '2.0.0', [xParserSpecParsed]: true, [xParserSpecStringified]: true })).not.toEqual(undefined); }); }); }); diff --git a/test/utils.spec.ts b/test/utils.spec.ts index 136ec2044..b84e01ead 100644 --- a/test/utils.spec.ts +++ b/test/utils.spec.ts @@ -1,6 +1,6 @@ import { DiagnosticSeverity } from '@stoplight/types'; import { xParserSpecParsed, xParserSpecStringified } from '../src/constants'; -import { AsyncAPIDocument, BaseModel } from '../src/models'; +import { newAsyncAPIDocument, BaseModel, AsyncAPIDocumentV2 } from '../src/models'; import { toAsyncAPIDocument, isAsyncAPIDocument, @@ -31,15 +31,15 @@ describe('utils', function() { }); it('AsyncAPIDocument instance should return AsyncAPIDocument instance', function() { - expect(toAsyncAPIDocument(new AsyncAPIDocument({ asyncapi: '2.0.0' }))).toBeInstanceOf(AsyncAPIDocument); + expect(toAsyncAPIDocument(newAsyncAPIDocument({ asyncapi: '2.0.0' }))).toBeInstanceOf(AsyncAPIDocumentV2); }); it('parsed document should return AsyncAPIDocument instance', function() { - expect(toAsyncAPIDocument({ [xParserSpecParsed]: true })).toBeInstanceOf(AsyncAPIDocument); + expect(toAsyncAPIDocument({ asyncapi: '2.0.0', [xParserSpecParsed]: true })).toBeInstanceOf(AsyncAPIDocumentV2); }); it('stringified document should return AsyncAPIDocument instance', function() { - expect(toAsyncAPIDocument({ [xParserSpecParsed]: true, [xParserSpecStringified]: true })).toBeInstanceOf(AsyncAPIDocument); + expect(toAsyncAPIDocument({ asyncapi: '2.0.0', [xParserSpecParsed]: true, [xParserSpecStringified]: true })).toBeInstanceOf(AsyncAPIDocumentV2); }); it('stringified document (with missed parsed extension) should not return AsyncAPIDocument instance', function() { @@ -65,7 +65,7 @@ describe('utils', function() { }); it('AsyncAPIDocument instance should be AsyncAPI document', function() { - expect(isAsyncAPIDocument(new AsyncAPIDocument({ asyncapi: '2.0.0' }))).toEqual(true); + expect(isAsyncAPIDocument(newAsyncAPIDocument({ asyncapi: '2.0.0' }))).toEqual(true); }); }); @@ -87,11 +87,11 @@ describe('utils', function() { }); it('AsyncAPIDocument instance should not be parsed document', function() { - expect(isParsedDocument(new AsyncAPIDocument({ asyncapi: '2.0.0' }))).toEqual(false); + expect(isParsedDocument(newAsyncAPIDocument({ asyncapi: '2.0.0' }))).toEqual(false); }); it('AsyncAPIDocument instance with proper extension should not be parsed document', function() { - expect(isParsedDocument(new AsyncAPIDocument({ asyncapi: '2.0.0', [xParserSpecParsed]: true }))).toEqual(false); + expect(isParsedDocument(newAsyncAPIDocument({ asyncapi: '2.0.0', [xParserSpecParsed]: true }))).toEqual(false); }); it('object with proper extension should be parsed document', function() { @@ -117,11 +117,11 @@ describe('utils', function() { }); it('AsyncAPIDocument instance should not be parsed document', function() { - expect(isStringifiedDocument(new AsyncAPIDocument({ asyncapi: '2.0.0' }))).toEqual(false); + expect(isStringifiedDocument(newAsyncAPIDocument({ asyncapi: '2.0.0' }))).toEqual(false); }); it('AsyncAPIDocument instance with proper extension should not be parsed document', function() { - expect(isStringifiedDocument(new AsyncAPIDocument({ asyncapi: '2.0.0', [xParserSpecParsed]: true, [xParserSpecStringified]: true }))).toEqual(false); + expect(isStringifiedDocument(newAsyncAPIDocument({ asyncapi: '2.0.0', [xParserSpecParsed]: true, [xParserSpecStringified]: true }))).toEqual(false); }); it('object with only stringified extension should not be parsed document', function() {