Open bartkl opened 2 years ago
Making matters more pressing: the SQL schema generation code also does this list parsing itself, and now that we're implementing OpenAPI as a new schema target, we would yet again have to repeat ourselves.
This is the time to fix this.
(ns metamorph.graph.db
(:require [clojure.walk :as walk]
[asami.core :as d]
[metamorph.rdf.datatype :refer [rdf-list->seq]]))
;; ...
(defn parse-rdf-lists [n]
(letfn [(rdf-list? [f] (and (:rdf/first f) (:rdf/rest f)))
(single-property? [f] (and
(vector? f)
(= (first f) :sh/property)
(not (set? (second f)))))]
(println (:id n))
(->> n
(walk/prewalk #(cond
(rdf-list? %) (into [] (rdf-list->seq %))
(single-property? %) [(first %) (hash-set (second %))]
:else %)))))
;; ...
(defn get-resource [conn iri]
(parse-rdf-lists (d/entity conn iri true)))
;; And of course remove the existing calls to `rdf-list->seq`.
Now, RDF lists in the Asami results are converted to seqs (using
rdf-list->seq
) during the Avro processing. That's bad separation of concerns.Spec'ing made me catch this! Because I now had to deal with RDF lists in my SHACL specs.