forked from eclipsesource/play-json-schema-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide default validation fallback messages
In case of a missing messages.txt file, default messages are now provided via the `ValidatorMessages` object.
- Loading branch information
1 parent
82e1ca9
commit 0b41f8b
Showing
14 changed files
with
143 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/scala/com/eclipsesource/schema/internal/ValidatorMessages.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.eclipsesource.schema.internal | ||
|
||
import java.text.MessageFormat | ||
|
||
import com.osinka.i18n.{Lang, Messages} | ||
|
||
import scala.util.Try | ||
|
||
object ValidatorMessages { | ||
|
||
val DefaultMessages: Map[String, String] = Map( | ||
"obj.missing.prop.dep" -> "Missing property dependency {0}.", | ||
"obj.max.props" -> "Too many properties. {0} properties found, but only a maximum of {1} is allowed.", | ||
"obj.min.props" -> "Found {0} properties, but a minimum of {1} is required.", | ||
"obj.additional.props" -> "Additional properties are not allowed, but found properties {0}.", | ||
"obj.required.prop" -> "Property {0} missing.", | ||
"arr.max" -> "Too many items. {0} items found, but only a maximum of {1} is allowed.", | ||
"arr.min" -> "Found {0} items, but a minimum of {1} is required.", | ||
"arr.dups" -> "Found duplicates.", | ||
"arr.out.of.bounds" -> "Array index {0} out of bounds.", | ||
"arr.invalid.index" -> "Invalid array index {0}.", | ||
"str.pattern" -> "''{0}'' does not match pattern ''{1}''.", | ||
"str.invalid.pattern" -> "Invalid pattern ''{0}''.", | ||
"str.min.length" -> "''{0}'' does not match minimum length of {1}.", | ||
"str.max.length" -> "''{0}'' exceeds maximum length of {1}.", | ||
"str.format" -> "''{0}'' does not match format {1}.", | ||
"num.multiple.of" -> "{0} is not a multiple of {1}.", | ||
"num.max" -> "{0} exceeds maximum value of {1}.", | ||
"num.max.exclusive" -> "{0} exceeds exclusive maximum value of {1}.", | ||
"num.min" -> "{0} is smaller than required minimum value of {1}.", | ||
"num.min.exclusive" -> "{0} is smaller than required exclusive minimum value of {1}.", | ||
"any.not" -> "Instance matches schema although it must not.", | ||
"any.all" -> "Instance does not match all schemas.", | ||
"any.any" -> "Instance does not match any of the schemas.", | ||
"any.one.of.none" -> "Instance does not match any schema.", | ||
"any.one.of.many" -> "Instance matches more than one schema.", | ||
"any.enum" -> "Instance is invalid enum value.", | ||
"any.const" -> "Instance does not match const value.", | ||
"comp.no.schema" -> "No schema applicable.", | ||
"err.expected.type" -> "Wrong type. Expected {0}, was {1}.", | ||
"err.unresolved.ref" -> "Could not resolve ref {0}.", | ||
"err.prop.not.found" -> "Could not find property {0}.", | ||
"err.ref.expected" -> "Expected to find ref at {0}.", | ||
"err.res.scope.id.empty" -> "Resolution scope ID must not be empty.", | ||
"err.parse.json" -> "Could not parse JSON.", | ||
"err.max.depth" -> "Maximum recursion depth reached.", | ||
"err.dependencies.not.found" -> "Dependency not found.", | ||
"err.definitions.not.found" -> "Definition not found.", | ||
"err.patternProperties.not.found" -> "Pattern Properties not found.", | ||
"err.false.schema" -> "Boolean false schema encountered.", | ||
"err.contains" -> "Array does not contain valid item.", | ||
"err.if.then.else" -> "Conditional validation failed." | ||
) | ||
|
||
def apply(msg: String, args: Any*)(implicit lang: Lang): String = { | ||
Try(Messages(msg, args:_*)) | ||
.getOrElse( | ||
new MessageFormat(DefaultMessages(msg)).format(args.map(_.asInstanceOf[java.lang.Object]).toArray) | ||
) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.