Skip to content

Commit

Permalink
resolve test case failure
Browse files Browse the repository at this point in the history
  • Loading branch information
aayushRedHat committed Sep 16, 2023
1 parent a5307cb commit b956097
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
26 changes: 13 additions & 13 deletions src/errors/specification-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ export class ErrorLoadingSpec extends Error {
if (from === 'file') {
this.name = 'error loading AsyncAPI document from file';
this.message = `${param} file does not exist.`;
} else
if (from === 'url') {
this.name = 'error loading AsyncAPI document from url';
this.message = `Failed to download ${param}.`;
} else
if (from === 'context') {
this.name = 'error loading AsyncAPI document from context';
this.message = `${param} context name does not exist.`;
} else
if (from === 'invalid file') {
this.name = 'Invalid AsyncAPI file type';
this.message = 'cli only supports yml ,yaml ,json extension';
}
}
if (from === 'url') {
this.name = 'error loading AsyncAPI document from url';
this.message = `Failed to download ${param}.`;
}
if (from === 'context') {
this.name = 'error loading AsyncAPI document from context';
this.message = `${param} context name does not exist.`;
}
if (from === 'invalid file') {
this.name = 'Invalid AsyncAPI file type';
this.message = 'cli only supports yml ,yaml ,json extension';
}

if (!from) {
this.name = 'error locating AsyncAPI document';
Expand Down
9 changes: 5 additions & 4 deletions src/models/SpecificationFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,18 @@ export async function isURL(urlpath: string): Promise<boolean> {

export async function fileExists(name: string): Promise<boolean> {
try {
if ((await lstat(name)).isFile()) {
return true;
}

const extension = name.split('.')[1];

const allowedExtenstion=['yml','yaml','json'];

if (!allowedExtenstion.includes(extension)) {
throw new ErrorLoadingSpec('invalid file',name);
}

if ((await lstat(name)).isFile()) {
return true;
}

throw new ErrorLoadingSpec('file', name);
} catch (e) {
throw new ErrorLoadingSpec('file', name);
Expand Down

0 comments on commit b956097

Please sign in to comment.