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:
Jaidyn Ann 2024-08-24 15:01:24 -05:00
parent 4964c679ee
commit f2522f9ae5
2 changed files with 14 additions and 4 deletions

View File

@ -23,6 +23,8 @@
#:parse #:define-json-type
;; Symbols
#:no-@context
;; Globals
#:*default-json-type*
;; Accessors
#:json-ld-context #:json-ld-etc #:json-ld-id #:json-ld-type
;; Slots
@ -33,6 +35,13 @@
;;; 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 *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)))
;; Now, actually parse.
(let* ((parsed-table (parse-table-inplace table ctx))
(type (identify-json-type table ctx))
(type-def (or (gethash type *json-types*)
(gethash "*" *json-types*))))
(type (identify-json-type parsed-table ctx))
(type-def (or (gethash type *json-types*)
(gethash *default-json-type* *json-types*))))
(parse-table-into-object parsed-table type-def ctx))))
(defun parse-table-inplace (table ctx)

View File

@ -24,7 +24,8 @@
(defun run ()
"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 ()
"Run tests with summary for ACTIVITY-VOCABULARY."