Skip to content

Commit

Permalink
chore: update multi-parser to last version (#1043)
Browse files Browse the repository at this point in the history
  • Loading branch information
smoya authored Oct 4, 2023
1 parent a6f9eca commit ff3b4de
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
9 changes: 5 additions & 4 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ const parser = module.exports;
* Convert the template defined value `apiVersion: 'v1'` to only contain the numeric value `1`.
*/
parser.sanitizeTemplateApiVersion = (apiVersion) => {
if (!apiVersion) return;
if (apiVersion && apiVersion.length > 1) {
return apiVersion.substring(1);
return Number(apiVersion.substring(1));
}
return apiVersion;
return Number(apiVersion);
};

parser.parse = async (asyncapi, oldOptions, generator) => {
let apiVersion = this.sanitizeTemplateApiVersion(generator.templateConfig.apiVersion);
// Defaulting to apiVersion v1 to convert it to the Parser-API v1 afterwards.
if (!this.usesNewAPI(generator.templateConfig)) {
apiVersion = '1';
apiVersion = 1;
}
const options = convertOldOptionsToNew(oldOptions, generator);
const parser = NewParser(apiVersion, {parserOptions: options, includeSchemaParsers: true});
Expand All @@ -34,7 +35,7 @@ parser.parse = async (asyncapi, oldOptions, generator) => {
* If the template expect one of the Parser-API versions, it must be above 0
*/
parser.usesNewAPI = (templateConfig = {}) => {
return Number(this.sanitizeTemplateApiVersion(templateConfig.apiVersion)) > 0;
return this.sanitizeTemplateApiVersion(templateConfig.apiVersion) > 0;
};

/**
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
"dependencies": {
"@asyncapi/generator-react-sdk": "^0.2.23",
"@asyncapi/parser": "2.1.0",
"@smoya/multi-parser": "3.0.0",
"@npmcli/arborist": "^2.2.4",
"@smoya/multi-parser": "^4.0.0",
"ajv": "^8.12.0",
"chokidar": "^3.4.0",
"commander": "^6.1.0",
Expand Down
6 changes: 3 additions & 3 deletions test/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ describe('Parser', () => {
describe('sanitizeTemplateApiVersion', () => {
it('should return version number when given `v2` syntax', () => {
const rawVersion = 'v2';
const expectedVersion = '2';
const expectedVersion = 2;
const sanitizedVersion = sanitizeTemplateApiVersion(rawVersion);

expect(sanitizedVersion).toStrictEqual(expectedVersion);
});
it('should return version number when given `v1` syntax', () => {
const rawVersion = 'v1';
const expectedVersion = '1';
const expectedVersion = 1;
const sanitizedVersion = sanitizeTemplateApiVersion(rawVersion);

expect(sanitizedVersion).toStrictEqual(expectedVersion);
});
it('should return version number when given `1` syntax', () => {
const rawVersion = '1';
const expectedVersion = '1';
const expectedVersion = 1;
const sanitizedVersion = sanitizeTemplateApiVersion(rawVersion);

expect(sanitizedVersion).toStrictEqual(expectedVersion);
Expand Down

0 comments on commit ff3b4de

Please sign in to comment.