You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Move schema-verson type to utils package
* reference: Make context encompass schema version and base schema
* utils: New typedef for schemas
* json-schema: Use new interface for validate
* json-schema.asd: Untabify
* t/reference: Fix call to internal function
* benchmark.lisp: Add a simple benchmark of caching
* json-schema, reference: Export more context slots and rework validate
Make sure calling validate uses the right values whether a schema or
context is passed.
* README: Add a section about contexts
Copy file name to clipboardExpand all lines: README.rst
+61-10Lines changed: 61 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ json-schema is a validator for drafts 4, 6, 7, and 2019-09 of the `JSON Schema <
20
20
21
21
**Drafts 4, 6, 7:**
22
22
23
-
- ``$ref`` overrides any sibling keywords
23
+
- ``$ref`` does not override any sibling keywords
24
24
25
25
-------
26
26
Example
@@ -86,6 +86,66 @@ If your data contains a top-level ``$schema`` key, you don't need to pass a sche
86
86
Usage Notes
87
87
-----------
88
88
89
+
~~~~~~~~
90
+
Contexts
91
+
~~~~~~~~
92
+
93
+
A context is a reusable set of state that contains all of the fetched network resources (if your schema references external resources) and resolved ids. By storing that all, you can reuse the validation context multiple times without fetching/resolving everything again.
So, for this trivial example, the cached version is around a 245x speedup! Note, though, that json-schema evaluates these things lazily, so not every reference is necessarily resolved when the context is created. They are mutable, though, and will build up state as they go.
146
+
147
+
Thank you to `Raymond Wiker <https://github.com/rwiker>`_ for contributing the initial implementation.
148
+
89
149
~~~~~~~~~~~~~
90
150
Decoding JSON
91
151
~~~~~~~~~~~~~
@@ -98,12 +158,3 @@ Network access
98
158
~~~~~~~~~~~~~~
99
159
100
160
JSON Schema allows schemas to reference other documents over the network. This library will fetch them automatically, by default. If you don't want this to be allowed, you should set :variable:`json-schema.reference:*resolve-remote-references*` to ``nil``. If a schema references a remote one, it will raise a :class:`json-schema.reference:fetching-not-allowed-error` instead of fetching it when fetching references is disallowed.
101
-
102
-
103
-
~~~~~~~~~~~~~~~
104
-
Reusing Schemas
105
-
~~~~~~~~~~~~~~~
106
-
107
-
Because of the nature of JSON Schema's references (location-independent references, particularly), schema documents need to be walked when loaded to discover named anchors and ids. They also may load other schemas.
108
-
109
-
If you're reusing a large schema document repeatedly, you might want to cache the resolution context. Unfortunately, I'm still working on this feature!
"The primary validation function for json-schema. Takes data: which can be a simple value or an object as a hash table, and then optionally accepts a schema (if the data doesn't contain a top-level ``$schema`` key), schema version and pretty-errors-p deterimines whether the second return value is exception objects or strings of the rendered errors (strings by default)."
"The primary validation function for json-schema. Takes data: which can be a simple value or an object as a hash table, and then optionally accepts a schema (if the data doesn't contain a top-level ``$schema`` key), schema version and pretty-errors-p deterimines whether the second return value is exception objects or strings of the rendered errors (strings by default).
The third return value is a :class:`json-schema.reference::context`, which contains all of the state stored in processing a schema including caching network resources and all of the resolved ids."
24
+
(assert (not (and schema context)) nil"You should only pass one of ")
0 commit comments