Adds *DEFAULT-JSON-TYPE* to JSON-LD
Allows customization of the type assumed for an unrecognized JSON-LD object-type.
This commit is contained in:
parent
4964c679ee
commit
f2522f9ae5
|
@ -23,6 +23,8 @@
|
||||||
#:parse #:define-json-type
|
#:parse #:define-json-type
|
||||||
;; Symbols
|
;; Symbols
|
||||||
#:no-@context
|
#:no-@context
|
||||||
|
;; Globals
|
||||||
|
#:*default-json-type*
|
||||||
;; Accessors
|
;; Accessors
|
||||||
#:json-ld-context #:json-ld-etc #:json-ld-id #:json-ld-type
|
#:json-ld-context #:json-ld-etc #:json-ld-id #:json-ld-type
|
||||||
;; Slots
|
;; Slots
|
||||||
|
@ -33,6 +35,13 @@
|
||||||
|
|
||||||
;;; Globals
|
;;; Globals
|
||||||
;;; ————————————————————————————————————————
|
;;; ————————————————————————————————————————
|
||||||
|
(defvar *default-json-type* "*"
|
||||||
|
"When parsing JSON-LD, objects of unrecognized types will be assumed to be
|
||||||
|
of this type. Should be a string, the IRI corresponding to a registered type.
|
||||||
|
For example: “https://www.w3.org/ns/activitystreams#Object”
|
||||||
|
|
||||||
|
The default value “*” refers to the base JSON-LD-OBJECT type.")
|
||||||
|
|
||||||
(defvar *http-cache* (make-hash-table :test #'equal))
|
(defvar *http-cache* (make-hash-table :test #'equal))
|
||||||
(defvar *json-types* (make-hash-table :test #'equal))
|
(defvar *json-types* (make-hash-table :test #'equal))
|
||||||
|
|
||||||
|
@ -277,9 +286,9 @@ name, though it might be unresolved if context was unprovided or lacking."
|
||||||
(let ((ctx (parse-context (gethash "@context" table) ctx)))
|
(let ((ctx (parse-context (gethash "@context" table) ctx)))
|
||||||
;; Now, actually parse.
|
;; Now, actually parse.
|
||||||
(let* ((parsed-table (parse-table-inplace table ctx))
|
(let* ((parsed-table (parse-table-inplace table ctx))
|
||||||
(type (identify-json-type table ctx))
|
(type (identify-json-type parsed-table ctx))
|
||||||
(type-def (or (gethash type *json-types*)
|
(type-def (or (gethash type *json-types*)
|
||||||
(gethash "*" *json-types*))))
|
(gethash *default-json-type* *json-types*))))
|
||||||
(parse-table-into-object parsed-table type-def ctx))))
|
(parse-table-into-object parsed-table type-def ctx))))
|
||||||
|
|
||||||
(defun parse-table-inplace (table ctx)
|
(defun parse-table-inplace (table ctx)
|
||||||
|
|
|
@ -24,7 +24,8 @@
|
||||||
|
|
||||||
(defun run ()
|
(defun run ()
|
||||||
"Run all ACTIVITY-VOCABULARY tests."
|
"Run all ACTIVITY-VOCABULARY tests."
|
||||||
(lisp-unit2:run-tests :package :activity-servist/tests/activity-vocabulary))
|
(let ((json-ld:*default-json-type* "https://www.w3.org/ns/activitystreams#Object"))
|
||||||
|
(lisp-unit2:run-tests :package :activity-servist/tests/activity-vocabulary)))
|
||||||
|
|
||||||
(defun run-with-summary ()
|
(defun run-with-summary ()
|
||||||
"Run tests with summary for ACTIVITY-VOCABULARY."
|
"Run tests with summary for ACTIVITY-VOCABULARY."
|
||||||
|
|
Ŝarĝante…
Reference in New Issue