schema-enforcer icon indicating copy to clipboard operation
schema-enforcer copied to clipboard

Issue 147

Open anakhalil opened this issue 3 years ago • 3 comments

#147 What do you think?

anakhalil avatar Dec 20 '22 18:12 anakhalil

I am working on try to pass an optional argument that will be evaluated. i.e. errMessage: "'$fqdn' is invalid." which would print as: -host.test.com is invalid

anakhalil avatar Dec 20 '22 19:12 anakhalil

The message can look like: ''$value' is incorrect $value will be replaced by the instance data. I need to make a change so that it will use path and resolve $value rather then just substituting err.instance.

One issue is that top level properties will return all instance data, if $value is used within the custom error message.

anakhalil avatar Dec 20 '22 22:12 anakhalil

Going to leave it here until I get some feedback. Its quite simple now. If the custom message (value of errMessage) contains $iData then it will replace $iData with instance data.

Of course there are some limitations to this:

  • it will replace all occurrences of $iData (can limit this with count)
  • you can no longer use $iData in the message
  • if the instance data is top level then it will print all instance data

Use cases:

hosts:
  type: string
  pattern: -regex-
  errMessage: "'$iData' does not match the regex pattern. Please see the docs"

Will print: FAIL ...... 'bad*host*' does not match the regex pattern. Please see the docs ...

or

hosts:
  type: string
  pattern: -regex-
  errMessage: "Config has bad host. Please see the docs"

Will print: FAIL ...... Config has bad host. Please see the docs ...

anakhalil avatar Dec 21 '22 12:12 anakhalil