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
15 changes: 1 addition & 14 deletions src/apps/cli/commands/generate/fromTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Args } from '@oclif/core';
import { BaseGeneratorCommand } from '@cli/internal/base/BaseGeneratorCommand';
import { load, Specification } from '@models/SpecificationFile';

Check warning on line 3 in src/apps/cli/commands/generate/fromTemplate.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import of 'load'.

See more on https://sonarcloud.io/project/issues?id=asyncapi_cli&issues=AZ0BLYgB1XKJBs70ZJFc&open=AZ0BLYgB1XKJBs70ZJFc&pullRequest=2052

Check warning on line 3 in src/apps/cli/commands/generate/fromTemplate.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import of 'Specification'.

See more on https://sonarcloud.io/project/issues?id=asyncapi_cli&issues=AZ0BLYgB1XKJBs70ZJFd&open=AZ0BLYgB1XKJBs70ZJFd&pullRequest=2052
import { ValidationError } from '@errors/validation-error';
import { GeneratorError } from '@errors/generator-error';
import { intro } from '@clack/prompts';
import { inverse } from 'picocolors';
Expand Down Expand Up @@ -65,19 +64,7 @@
const watchTemplate = flags['watch'];
const genOption = this.buildGenOption(flags, parsedFlags);

let specification: Specification;
try {
specification = await load(asyncapi);
} catch {
return this.error(
new ValidationError({

type: 'invalid-file',
filepath: asyncapi,
}),
{ exit: 1 },
);
}
const specification = asyncapiInput;

const result = await this.generatorService.generate(
specification,
Expand Down
20 changes: 17 additions & 3 deletions src/utils/generate/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,26 @@

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=AZ0BLYiV1XKJBs70ZJFe&open=AZ0BLYiV1XKJBs70ZJFe&pullRequest=2052
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 {
throw new Error(`Can't fetch registryURL: ${registryUrl}`);
} catch (err: any) {
clearTimeout(timeoutId);
if (err.name === 'AbortError') {
throw new Error(`Registry URL timed out after ${TIMEOUT_MS}ms: ${registryUrl}`);
}
const cause = err.cause ? `\nCaused by: ${err.cause}` : '';
throw new Error(`Can't fetch registryURL: ${registryUrl}${cause}`);
}
}
Loading