From ad8ec46c8d3c549d0a9f03823d77d2bb9f22ea93 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 4 Aug 2020 15:35:27 +0200 Subject: [PATCH 1/2] only format message when errors are actually requested --- errors.go | 1 - go.mod | 2 ++ result.go | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/errors.go b/errors.go index e4e9814..147d2ac 100644 --- a/errors.go +++ b/errors.go @@ -323,7 +323,6 @@ func newError(err ResultError, context *JsonContext, value interface{}, locale l details["context"] = context.String() } - err.SetDescription(formatErrorDescription(err.DescriptionFormat(), details)) } // formatErrorDescription takes a string in the default text/template diff --git a/go.mod b/go.mod index b709d7f..2d62787 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,7 @@ module github.com/xeipuuv/gojsonschema +go 1.14 + require ( github.com/stretchr/testify v1.3.0 github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect diff --git a/result.go b/result.go index 0a01791..81a5e9c 100644 --- a/result.go +++ b/result.go @@ -188,6 +188,9 @@ func (v *Result) Valid() bool { // Errors returns the errors that were found func (v *Result) Errors() []ResultError { + for _, err := range v.errors { + err.SetDescription(formatErrorDescription(err.DescriptionFormat(), err.Details())) + } return v.errors } From 507e99717d6a9e58d1f5abcd54c7ef9892386ea5 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 4 Aug 2020 15:37:22 +0200 Subject: [PATCH 2/2] revert go.mod changes --- go.mod | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.mod b/go.mod index 2d62787..b709d7f 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,5 @@ module github.com/xeipuuv/gojsonschema -go 1.14 - require ( github.com/stretchr/testify v1.3.0 github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect