-
Notifications
You must be signed in to change notification settings - Fork 332
PR #511: Improve validation messages (German and default) #536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PR #511: Improve validation messages (German and default) #536
Conversation
|
ALL CLEAR: I have finally uncovered the real root cause of what only seemed to be Locale/testing issues: Due to suboptimal error handling in I18nSupport, a MissingResourceException during ResourceBundle init could make it impossible for the JVM to load class ValidatorTypeCode, which lead to massively misleading error messages and stack traces like "java.lang.NoClassDefFoundError: Could not initialize class com.networknt.schema.ValidatorTypeCode" The above second commit fixes this issue in I18nSupport by failing early and fatally with System.exit() in case of MissingResourceExceptions - and with this change (and the fix for "dateTime" in ValidatorTypeCode), the tests are passing just fine when I override Maven property "argLine" in my settings.xml like this
So I am pretty confident now that you can indeed safely apply this PR now... 😄 |
unionType = {0}: {1} wurde gefunden aber {2} wird verlangt | ||
uniqueItems = {0}: Die Element(e) des Arrays m�ssen einmalig sein | ||
uniqueItems = {0}: Die Element(e) des Arrays d�rfen nur einmal auftreten |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, that's better!
required = {0}.{1} ist ein Pflichtfeld aber fehlt | ||
type = {0}: {1} wurde gefunden aber {2} erwartet | ||
type = {0}: {1} wurde gefunden, aber {2} erwartet | ||
unevaluatedProperties = Eigenschaften in folgenden Pfaden wurden nicht evaluiert: {0} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!
@@ -308,8 +308,7 @@ private ValidationMessage getMultiSchemasValidErrorMsg(String at){ | |||
msg = msg.concat(schemaValue); | |||
} | |||
|
|||
return ValidationMessage.of(getValidatorType().getValue(), ValidatorTypeCode.ONE_OF , | |||
at, String.format("but more than one schemas {%s} are valid ",msg)); | |||
return ValidationMessage.of(getValidatorType().getValue(), ValidatorTypeCode.ONE_OF, at, msg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
creative solution 😄 have you verified that the compiled message is correctly compiled with all placeholder variables being substituted accordingly?
I'm asking because you noticed this bug due to your personal code returning an incompletely translated message. Then, I wouldn't have to check it myself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message used to be before:
requestBody.data darf nur für ein einziges Schema but more than one schemas {{"$ref":"#/components/schemas/tEnS"}{"$ref":"#/components/schemas/vEnS"}{"$ref":"#/components/schemas/vEnSAndTens"}} are valid gültig sein
this means that variable msg contained the String {"$ref":"#/components/schemas/tEnS"}{"$ref":"#/components/schemas/vEnS"}{"$ref":"#/components/schemas/vEnSAndTens"}
, and what we saw was a combination of the previous text for oneOf: "{0} darf nur für ein einziges Schema {1} gültig sein" and the result of String.format()...
So I changed the text for oneOf to "{0} darf nur für ein einziges Schema gültig sein, aber mehr als ein Schema ist gültig: {1}", and thus the error message now indeed in my scenario is the following:
requestBody.data darf nur für ein einziges Schema gültig sein, aber mehr als ein Schema ist gültig: {"$ref":"#/components/schemas/tEnS"}{"$ref":"#/components/schemas/vEnS"}{"$ref":"#/components/schemas/vEnSAndTens"}
(note that I left out the second pair of curly brackets, we can re-introduce them if you like)
If you would like me to create a test case that explicitly validates this, I am fine with this, but due to the fact that I have a hospital stay scheduled for next week, it might only be at/around Easter that I will be able to do so.
This would still be fine from my point of view, as I think the German translation for the validation messages is currently rather a "niche feature" of json-schema-validator 😄 ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, and also to the best of my knowledge (checking search results for "oneOf" in the project) no other place in the code is using of the message resource with the "oneOf" key...
As discussed with @rustermi here is my pull request after improving German validation messages.
Note that in order to support better comparisons between language versions, I have sorted all message properties files by the message keys, such that they are now in the same order.
As stated, I have been unable to validate my PR by executing Maven "surefire" tests, as I cannot get them to run on a Windows machine with a default locale of German (and I must not change my Windows locale)...
I will also attach the full output I get from running Maven tests with German locale:
[ERROR] Tests run: 371, Failures: 26, Errors: 0, Skipped: 55