Repository: asyncapi/parser-js
Pull request #849 (2023-08-18 10:06:09)

fix: set proper parser-api version
**Description**

This PR fixes the parser-api version in use from `1` to `2.0.0`. It moves the value to a constant set in the same file as `AsyncAPIDocumentInterface` is declared.

sonarcloud[bot]: Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=asyncapi_parser-js&pullRequest=849)

[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=asyncapi_parser-js&pullRequest=849&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=asyncapi_parser-js&pullRequest=849&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=asyncapi_parser-js&pullRequest=849&resolved=false&types=BUG)  
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=asyncapi_parser-js&pullRequest=849&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=asyncapi_parser-js&pullRequest=849&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=asyncapi_parser-js&pullRequest=849&resolved=false&types=VULNERABILITY)  
[![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=asyncapi_parser-js&pullRequest=849&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=asyncapi_parser-js&pullRequest=849&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=asyncapi_parser-js&pullRequest=849&resolved=false&types=SECURITY_HOTSPOT)  
[![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=asyncapi_parser-js&pullRequest=849&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=asyncapi_parser-js&pullRequest=849&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonarcloud.io/project/issues?id=asyncapi_parser-js&pullRequest=849&resolved=false&types=CODE_SMELL)

[![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=asyncapi_parser-js&pullRequest=849) No Coverage information  
[![No Duplication information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/NoDuplicationInfo-16px.png 'No Duplication information')](https://sonarcloud.io/component_measures?id=asyncapi_parser-js&pullRequest=849&metric=duplicated_lines_density&view=list) No Duplication information


smoya: > Is this breaking? 🤔

Well, the breaking change is **already** in `next-major-spec` branch because it implements parser-api v2.
jonaslagoni: @smoya 👍 
smoya: /rtm

Patch:
diff --git a/src/models/asyncapi.ts b/src/models/asyncapi.ts
index 4db88b3..6f85dc5 100644
--- a/src/models/asyncapi.ts
+++ b/src/models/asyncapi.ts
@@ -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;
diff --git a/src/parse.ts b/src/parse.ts
index c743cf7..988f9ae 100644
--- a/src/parse.ts
+++ b/src/parse.ts
@@ -1,4 +1,4 @@
-import { AsyncAPIDocumentInterface } from './models';
+import { AsyncAPIDocumentInterface, ParserAPIVersion } from './models';
 
 import { customOperations } from './custom-operations';
 import { validate } from './validate';
@@ -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 { 


Test patch:
diff --git a/test/parse.spec.ts b/test/parse.spec.ts
index e8c941c..d7cf4fd 100644
--- a/test/parse.spec.ts
+++ b/test/parse.spec.ts
@@ -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';
 
@@ -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() {