Skip to content

Commit

Permalink
[v2] Report full error for schema violations (#4934)
Browse files Browse the repository at this point in the history
- Fixes #4933
  • Loading branch information
mikeharder authored Mar 29, 2024
1 parent 6a1a091 commit 3d50bb1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/autorest-core/lib/pipeline/schema-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Parse } from '../ref/yaml';
import { CreatePerFilePlugin, PipelinePlugin } from "./common";
import { Channel } from "../message";
import { OperationAbortedException } from '../exception';
import { inspect } from 'util';

export function GetPlugin_SchemaValidator(): PipelinePlugin {
const validator = new SchemaValidator({ breakOnFirstError: false });
Expand All @@ -23,12 +24,15 @@ export function GetPlugin_SchemaValidator(): PipelinePlugin {
const errors = await new Promise<{ code: string, params: string[], message: string, path: string }[] | null>(res => validator.validate(obj, extendedSwaggerSchema, (err, valid) => res(valid ? null : err)));
if (errors !== null) {
for (const error of errors) {
// Replace '_' with '-' to avoid output formatter interpreting as italics
const errorLog = inspect(error, { depth: 3 }).replaceAll('_', '-');

config.Message({
Channel: Channel.Error,
Details: error,
Plugin: "schema-validator",
Source: [{ document: fileIn.key, Position: { path: parseJsonPointer(error.path) } as any }],
Text: `Schema violation: ${error.message}`
Text: `Schema violation: ${error.message}\n${errorLog}`
});
}
throw new OperationAbortedException();
Expand Down

0 comments on commit 3d50bb1

Please sign in to comment.