Skip to content

Commit

Permalink
fix: set proper parser-api version (#849)
Browse files Browse the repository at this point in the history
  • Loading branch information
smoya authored Aug 18, 2023
1 parent 98aa4db commit 95b6e5e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/models/asyncapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import type { ServersInterface } from './servers';

import type { v2, v3 } from '../spec-types';

// https://github.com/asyncapi/parser-api/releases/tag/v2.0.0
export const ParserAPIVersion = '2.0.0';

export interface AsyncAPIDocumentInterface extends BaseModel<v2.AsyncAPIObject | v3.AsyncAPIObject>, ExtensionsMixinInterface {
version(): string;
defaultContentType(): string | undefined;
Expand Down
4 changes: 2 additions & 2 deletions src/parse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AsyncAPIDocumentInterface } from './models';
import { AsyncAPIDocumentInterface, ParserAPIVersion } from './models';

import { customOperations } from './custom-operations';
import { validate } from './validate';
Expand Down Expand Up @@ -61,7 +61,7 @@ export async function parse(parser: Parser, spectral: Spectral, asyncapi: Input,
const detailed = createDetailedAsyncAPI(validatedDoc, asyncapi as DetailedAsyncAPI['input'], options.source);
const document = createAsyncAPIDocument(detailed);
setExtension(xParserSpecParsed, true, document);
setExtension(xParserApiVersion, 1, document);
setExtension(xParserApiVersion, ParserAPIVersion, document);
await customOperations(parser, document, detailed, inventory, options);

return {
Expand Down
4 changes: 2 additions & 2 deletions test/parse.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Document } from '@stoplight/spectral-core';

import { AsyncAPIDocumentV2, AsyncAPIDocumentV3 } from '../src/models';
import { AsyncAPIDocumentV2, AsyncAPIDocumentV3, ParserAPIVersion } from '../src/models';
import { Parser } from '../src/parser';
import { xParserApiVersion } from '../src/constants';

Expand Down Expand Up @@ -92,7 +92,7 @@ describe('parse()', function() {
const { document } = await parser.parse(documentRaw);

expect(document).toBeInstanceOf(AsyncAPIDocumentV2);
expect(document?.extensions().get(xParserApiVersion)?.value()).toEqual(1);
expect(document?.extensions().get(xParserApiVersion)?.value()).toEqual(ParserAPIVersion);
});

it('should preserve references', async function() {
Expand Down

0 comments on commit 95b6e5e

Please sign in to comment.