From 3d50bb1315ea6a45012ac5c0a1dc8492cf896cdb Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Fri, 29 Mar 2024 16:56:49 -0700 Subject: [PATCH] [v2] Report full error for schema violations (#4934) - Fixes #4933 --- src/autorest-core/lib/pipeline/schema-validation.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/autorest-core/lib/pipeline/schema-validation.ts b/src/autorest-core/lib/pipeline/schema-validation.ts index a872c00a04..80ea1ac958 100644 --- a/src/autorest-core/lib/pipeline/schema-validation.ts +++ b/src/autorest-core/lib/pipeline/schema-validation.ts @@ -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 }); @@ -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();