fisxoj / json-schema

JSON Schema validation
GNU Lesser General Public License v2.1
17 stars 4 forks source link

Allow parsed schemas to be stored directly into the context. #23

Open ryanobjc opened 4 months ago

ryanobjc commented 4 months ago

Schema sets are sometimes entirely on disk, and we don't want to visit the network, or perhaps the URI doesn't even load. This function will allow the program to parse and store schemas.

fisxoj commented 3 months ago

Thanks for the PR!

I've been trying to think about this and how I'd like it to fit with the API in general. Do you mind sharing how you use it? Are you only adding a single schema or would it be more useful if you could add many files?

ryanobjc commented 3 months ago

My code works something like this:

(defun load-all-schemas (&optional (path-pattern "~/json-schemas/**/*.json"))
  (json-schema.reference:with-context (*context*)
    (loop for p in (directory path-pattern)
          do (json-schema.reference:store-reference (json-schema.parse:parse p)))))

something like that.

In my case, the schemas I'm working with aren't formally published so it's impossible to retrieve them from the URIs provided. I have about 30 files here.