fix: trim trailing dot from error locations

This commit is contained in:
Daniel G. Taylor 2022-04-11 13:53:24 -07:00
parent 8aa6989f4c
commit 09e1ebac6a
No known key found for this signature in database
GPG key ID: 74AE195C5112E534

View file

@ -46,7 +46,7 @@ func validAgainstSchema(ctx *hcontext, label string, schema *schema.Schema, data
if err := recover(); err != nil {
ctx.AddError(&ErrorDetail{
Message: fmt.Errorf("unable to validate against schema: %w", err.(error)).Error(),
Location: label,
Location: strings.TrimSuffix(label, "."),
Value: string(data),
})
@ -72,7 +72,7 @@ func validAgainstSchema(ctx *hcontext, label string, schema *schema.Schema, data
// those off to prevent duplicating data. (e.g. see the enum error)
ctx.AddError(&ErrorDetail{
Message: strings.TrimPrefix(desc.Description(), desc.Context().String()+" "),
Location: label + strings.TrimPrefix(desc.Field(), "(root)"),
Location: strings.TrimSuffix(label+strings.TrimPrefix(desc.Field(), "(root)"), "."),
Value: desc.Value(),
})
}