Skip to content

Commit

Permalink
feat: helper message for invalid specification file during model ge…
Browse files Browse the repository at this point in the history
…neration (#618)

Co-authored-by: Lukasz Gornicki <[email protected]>
  • Loading branch information
chinma-yyy and derberg authored Jun 1, 2023
1 parent e6f919a commit 207c623
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/commands/generate/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CSharpFileGenerator, JavaFileGenerator, JavaScriptFileGenerator, TypeSc
import { Flags } from '@oclif/core';
import Command from '../../base';
import { load } from '../../models/SpecificationFile';
import { parse, validationFlags } from '../../parser';
import { formatOutput, parse, validationFlags } from '../../parser';

import type { AbstractGenerator, AbstractFileGenerator } from '@asyncapi/modelina';

Expand Down Expand Up @@ -142,8 +142,10 @@ export default class Models extends Command {
const { tsModelType, tsEnumType, tsIncludeComments, tsModuleSystem, tsExportType, tsJsonBinPack, namespace, csharpAutoImplement, csharpArrayType, csharpNewtonsoft, csharpHashcode, csharpEqual, csharpSystemJson, packageName, output } = flags;
const { language, file } = args;
const inputFile = (await load(file)) || (await load());
const { document, status } = await parse(this, inputFile, flags);
const { document, diagnostics ,status } = await parse(this, inputFile, flags);
if (!document || status === 'invalid') {
const severityErrors = diagnostics.filter((obj) => obj.severity === 0);
this.log(`Input is not a correct AsyncAPI document so it cannot be processed.${formatOutput(severityErrors,'stylish','error')}`);
return;
}

Expand Down
3 changes: 1 addition & 2 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ function logDiagnostics(diagnostics: Diagnostic[], command: Command, specFile: S
command.logToStderr(`\n${sourceString} and/or referenced documents have governance issues.`);
command.logToStderr(formatOutput(diagnostics, diagnosticsFormat, failSeverity));
}
command.exit(1);
return 'invalid';
}

Expand All @@ -95,7 +94,7 @@ function logDiagnostics(diagnostics: Diagnostic[], command: Command, specFile: S
return 'valid';
}

function formatOutput(diagnostics: Diagnostic[], format: `${OutputFormat}`, failSeverity: SeveritytKind) {
export function formatOutput(diagnostics: Diagnostic[], format: `${OutputFormat}`, failSeverity: SeveritytKind) {
const options = { failSeverity: getDiagnosticSeverity(failSeverity) };
switch (format) {
case 'stylish': return stylish(diagnostics, options);
Expand Down

0 comments on commit 207c623

Please sign in to comment.