Comments (2)
@AlexTo Hi, please note that there was a minor mistake when using id
s which I've fixed today with 0.9.5-M3. So for the following to work, please update. To answer your original question: you can use addSchema
to make all involved schemas known to the validator. Here's a sample test case for starters, which can be improved upon (this assumes that the references JSON files are stored within a tincan
resource folder on the classpath):
class TinCanSpec extends Specification { self =>
import com.eclipsesource.schema.drafts.Version4
val instance = JsonSource.fromString(
"""
|{
| "actor": {
| "name": "Sally Glider",
| "mbox": "mailto:[email protected]"
| },
| "verb": {
| "id": "http://adlnet.gov/expapi/verbs/experienced",
| "display": { "en-US": "experienced" }
| },
| "object": {
| "id": "http://example.com/activities/solo-hang-gliding",
| "definition": {
| "name": { "en-US": "Solo Hang Gliding" }
| }
| }
|}
""".stripMargin).get
"Tin Can Spec" should {
import Version4._
def readSchema(filename: String) =
JsonSource.schemaFromStream(self.getClass.getResourceAsStream(s"/tincan/$filename.json")).get
"validate basic statement object" in {
val validator = SchemaValidator(Some(Version4))
.addSchema("#agent", readSchema("agent"))
.addSchema("#group", readSchema("group"))
.addSchema("#inversefunctional", readSchema("inversefunctional"))
.addSchema("#mbox", readSchema("mbox"))
.addSchema("#statement_base", readSchema("statement_base"))
.addSchema("#statement_object", readSchema("statement_object"))
.addSchema("#verb", readSchema("verb"))
.addSchema("#languagemap", readSchema("languagemap"))
.addSchema("#activity", readSchema("activity"))
.addSchema("#activity_definition", readSchema("activity_definition"))
.addSchema("#activityid", readSchema("activityid"))
val result = validator.validate(readSchema("statement_base"), instance)
result.isSuccess must beTrue
}
}
}
from play-json-schema-validator.
Thanks a lot, this seems to be a better solution.
After creating this issue, I ended up, modifying all the "$ref" in all the files.
For e.g.
"$ref": "#someschema"
=> "$ref": "classpath:/path/someschema.json"
The problem is I have to update all the JSON schema files which I don't want.
Also, there are some ref which I don't know how to deal with for .e.g I have the followign in activity.json
"id": {"$ref": "#activityid!core"},
And this is activityid.json
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "#activityid",
"type": "object",
"required": ["activityId"],
"properties": {
"activityId": {
"id": "#activityid!core",
"type": "string",
"format": "iri"
}
}
}
I will try your approach, thanks again
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
- 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.