Comments (5)
Hi!
The validator should already report errors for all properties, e.g. when using the following schema
{
"properties": {
"title": { "type": "string", "minLength": 3 },
"foo" : { "type": "string", "pattern": "^[A-Z].*" }
}
}
and passing {"title": "a", "foo": "a" } to the validate
method it will report errors for title
as well as foo
:
[ {
"schemaPath" : "#/properties/foo",
"errors" : { },
"msgs" : [ "a does not match pattern ^[A-Z].*" ],
"value" : "a",
"instancePath" : "/foo"
}, {
"schemaPath" : "#/properties/title",
"errors" : { },
"msgs" : [ "a violates min length of 3" ],
"value" : "a",
"instancePath" : "/title"
} ]
Is this what you mean? If not, can you post an example and your expected outcome?
Thank you!
from play-json-schema-validator.
Yes, that's exactly what i mean
I've mistaken, it works:
scala> import com.eclipsesource.schema._
import com.eclipsesource.schema._
scala> import play.api.libs.json._
import play.api.libs.json._
scala> val schema = Json.fromJson[SchemaType](Json.obj("type" -> "object", "properties" -> Json.obj("name" -> Json.obj("type" -> "string"), "job" -> Json.obj("type" -> "string")), "required" -> List("name", "job")))
schema: play.api.libs.json.JsResult[com.eclipsesource.schema.SchemaType] = JsSuccess(object,)
scala> SchemaValidator.validate(schema.get, Json.obj().as[JsValue]).toString
res6: String = JsError(List((,List(ValidationError(List(Property job missing),WrappedArray({"schemaPath":"#","instancePath":"","value":{},"errors":{}})))), (,List(ValidationError(List(Property name missing),WrappedArray({"schemaPath":"#","instancePath":"","value":{},"errors":{}}))))))
There's is some bug in my code..
Thank you for reply!
from play-json-schema-validator.
Ah, no, i reproduced the problem:
scala> val result = SchemaValidator.validate(schema.get, Json.obj())
result: play.api.libs.json.JsResult[play.api.libs.json.JsObject] = JsError(List((,List(ValidationError(List(Property job missing),WrappedArray({"schemaPath":"#","instancePath":"","value":{},"errors":{}})))), (,List(ValidationError(List(Property name missing),WrappedArray({"schemaPath":"#","instancePath":"","value":{},"errors":{}}))))))
scala> result.asEither.left.map(err => JsError.toJson(err))
res3: Product with Serializable with scala.util.Either[play.api.libs.json.JsObject,play.api.libs.json.JsObject] = Left({"obj":[{"msg":["Property name missing"],"args":[{"schemaPath":"#","instancePath":"","value":{},"errors":{}}]}]})
It fails when i try to convert JsError to JsObject with JsError.toJson method. Where is "job" property?
from play-json-schema-validator.
JsError.toJson
currently doesn't work with the result returned by the validator since it overwrites properties with the same name during the merge (in this case the returned array contains the empty instance path twice), therefore you have to use the toJson
method on the returned result like mentioned here. Let me know if that works for you.
That said, the validator should probably merge entries within the returned result, such that it is compatible with JsError.
from play-json-schema-validator.
Yes, it works!
It seems like i used it before but forgot, too much information :)
Thank you!
from play-json-schema-validator.
Related Issues (20)
- Validating instances by passing the schema url to the validator is slower than passing it the preloaded schema HOT 1
- Invalid schema type should not throw MatchError exception HOT 2
- Question: Ref resolution outside of validation? HOT 2
- Double.Min|Max values do not trigger an error for integer type property HOT 2
- date-time format validator is better if implemented via java.time.OffsetDateTime.parse HOT 1
- Convert a SchemaType back to JSON HOT 2
- Investigate possible performance issues
- Exception in Play 2.6.0-RC2 HOT 3
- Add support for Scala 2.11 HOT 1
- support for other draft versions HOT 5
- library should not depend on external resources HOT 2
- Include meta schema for default version as well
- Add documentation about config options/versions
- Compiler error after upgrade to 0.9.5-M2 HOT 3
- Not sure how to use the library with multiple JSON schema files HOT 2
- How to validate with schema id? HOT 2
- compilation error when using SchemaType HOT 3
- messages.txt can not be found HOT 11
- Release for scala 2.13 HOT 5
- Looking for a new maintainer
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from play-json-schema-validator.