Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/domains/services/archiver.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ export class ArchiverService {

public appendAsyncAPIDocument(
archive: Archiver,
asyncapi: string,
asyncapi: string | object,
fileName = 'asyncapi',
) {
asyncapi = JSON.stringify(asyncapi);
const language = retrieveLangauge(asyncapi);
const content =
typeof asyncapi === 'string'
? asyncapi
: JSON.stringify(asyncapi, null, 2);
const language = retrieveLangauge(content);
if (language === 'yaml') {
archive.append(asyncapi, { name: `${fileName}.yml` });
archive.append(content, { name: `${fileName}.yml` });
} else {
archive.append(asyncapi, { name: `${fileName}.json` });
archive.append(content, { name: `${fileName}.json` });
}
}

Expand Down
17 changes: 15 additions & 2 deletions src/utils/generate/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,25 @@

export async function registryValidation(registryUrl?: string, registryAuth?: string, registryToken?: string) {
if (!registryUrl) { return; }
const TIMEOUT_MS = 5000;
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), TIMEOUT_MS);

try {
const response = await fetch(registryUrl as string);
const response = await fetch(registryUrl as string, {

Check warning on line 16 in src/utils/generate/registry.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This assertion is unnecessary since it does not change the type of the expression.

See more on https://sonarcloud.io/project/issues?id=asyncapi_cli&issues=AZ0BBQYi0sF8KYMCxRK5&open=AZ0BBQYi0sF8KYMCxRK5&pullRequest=2049
method: 'HEAD',
signal: controller.signal,
});
clearTimeout(timeoutId);

if (response.status === 401 && !registryAuth && !registryToken) {
throw new Error('You Need to pass either registryAuth in username:password encoded in Base64 or need to pass registryToken');
}
} catch {
} catch (err: any) {
clearTimeout(timeoutId);
if (err.name === 'AbortError') {
throw new Error(`Registry URL timed out after ${TIMEOUT_MS}ms: ${registryUrl}`);
}
throw new Error(`Can't fetch registryURL: ${registryUrl}`);
}
}
Loading