Comments (9)
That would be useful, yeah.
When adding a schema, tv4 performs a normalisation pass (to convert "id"
and "$ref"
values into absolute URIs) (function source, called from code).
A tidy way to collect $ref
s might be to move that function to inside the ValidatorContext class, so it can collect the $ref
values as it goes along.
I'm not quite sure what the issue would be with nested/recursive references, though - if ValidatorContexts have a list of all $ref
s in schemas that have been added with then, then you should be able to repeatedly check for $ref
s that haven't been added using addSchema()
, and add the missing ones. Or do you mean the case when a $ref
points to itself?
from tv4.
With nested/recursive references I meant a schema that refers to an external schema that refers to another external schema (etc etc).
To get at the urls of all of them it would need multiple passes: check a schema and get the urls, load and add the sub schemas, check again for new missing ones, load them, and repeat this until they're all cached.
Now I know tv4 will collect the mappings it could have an api like this:
//add our local root schema with no uri (if a uri is set in the data then auto-register it)
//maybe this should clear the cache as well?
tv4.initSchema(schema);
//could also be an addSchema() overload without the uri
// this could allow to preset in a bunch of schema's from local .json without fiddling around to extract their own uri's
tv4.addSchema(schema);
//then grab the list of know ref uri's
var uriList = tv4.getRefUriList(ntoloadedOnly);
//or maybe a bit more reusable in an alternate object style;
//by mapping uri's to schema (with falsy for non-yet-loaded schemas)
var uriMap = tv4.getRefUriMap();
This can then be repeated until no empty uri's show up, after which you can validate synchronously by anyone of these schema.
What do you think?
from tv4.
Sounds about right, yeah. :)
from tv4.
Ok, cool. Do you feel a need to implement this yourself? Otherwise I'll have a go at it.
If I take this I'll create a develop
branch so it won't interfere with master
until ready.
from tv4.
Just to check - what's going into tv4
would just be some methods/variables like tv4.referenceUrls
and tv4.getMissingReferences()
, and the actual fetch/add recursion loop would be a separate thing to be written using those?
I don't have a particular need to write everything myself, so by all means go for it.
from tv4.
Yes, only the basic accessor methods like tv4.referenceUrls
, tv4.getMissingReferences()
and the slightly modified initial tv.addSchema()
should be in the tv4
core (I like those names btw).
They would just be a clean way to get at the reference data so we can do stuff with it (like loading, but also for debugging). The actual fetching and adding would be external.
Once that is stabilised and used in practice we could look at hammering the fetchers I'd write for my own projects into a plugin/addon type of thing.
from tv4.
Sounds great - look forward to seeing it. )
from tv4.
Just now I committed my edits for this to a develop-branch. It's an ugly commit; I tried to clean it up but only got worse: had made the mistake of modifying stuff while I was implementing this (so we learn :)
One thing I added besides implementing Issue was source-map support via grunt-concat-sourcemap/sourcemap-support: now node.js stack traces of the core and tests display path to the actual fragment file (instead of the concatenated file). Pretty neat, also works with in Chrome Debugger if you enable it (also breakpoints etc :)
Also I cleaned some stuff in the tests.
from tv4.
@geraintluff I'm mergin this with your recent edits and pushing it to /master
from tv4.
Related Issues (20)
- Bower repo missing minified version
- Where is version 1.3.0?
- does it possible to add prop for schema using regexp? HOT 1
- Not Case Sensitive
- tv4.validate not finding an induced error
- False positives for an incorrectly constructed schema for an array of objects HOT 1
- The library doesn't recognize a reference to external schema as missing
- Would JSON values appears in subErrors or not
- JSON schema draft 6 support or new project tv6 ? HOT 2
- Inconsistent "schemaPath" for errors
- validateMultiple throws exception on multiple errors
- Config to set additionalProperties=false by default
- ASF with tv4 change language
- tag a relase?
- Where can I find tv4.errorCodes
- tv4.validate does not validate properly when using 'const' schema property HOT 1
- grungey object.isfrozen hack in tv4.js line 118
- Trying to get in touch regarding a security issue
- null error when data is passed "null" when adding addFormat or defineKeword HOT 1
- Support for `required: true` (all properties required) syntax?
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 tv4.