Skip to content

Commit

Permalink
Release 0.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
luposlip committed Sep 15, 2021
1 parent 1673ddd commit 9985a14
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).

## 0.3.2 - 2021-09-15

- Eliminated reflective function calls
- Updated Java Library

## 0.3.1 - 2021-04-25

Now relative $ref's are supported.

## 0.3.0 - 2021-04-15

This release adds usage of $ref pointing to resources in the classpath.

## 0.2.9 - 2020-12-03

### Changed
Expand Down
9 changes: 5 additions & 4 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
(defproject luposlip/json-schema "0.3.1"
(defproject luposlip/json-schema "0.3.2"
:description "Clojure library for JSON Schema validation and generation - Draft-07 compatible"
:url "https://github.com/luposlip/json-schema"
:license {:name "Apache License, Version 2.0"
:url "https://www.apache.org/licenses/LICENSE-2.0"}
:repositories {"jitpack" {:url "https://jitpack.io"}}
:dependencies [[org.clojure/clojure "1.10.1"]
[cheshire "5.10.0"]
[com.github.everit-org.json-schema/org.everit.json.schema "1.12.1"]]
:dependencies [[org.clojure/clojure "1.10.3"]
[cheshire "5.10.1"]
[com.github.everit-org.json-schema/org.everit.json.schema "1.13.0"]]
:global-vars {*warn-on-reflection* true}
:repl-options {:init-ns json-schema.core}
:profiles {:dev {:resource-paths ["test/resources"]}})
34 changes: 20 additions & 14 deletions src/json_schema/core.clj
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
(ns json-schema.core
(:require [cheshire.core :as json])
(:import [org.json JSONObject JSONArray JSONTokener]
[org.everit.json.schema.loader SchemaLoader SchemaClient]
(:import [java.io Reader StringReader]
[org.json JSONObject JSONArray JSONTokener]
[org.everit.json.schema.loader
SchemaLoader SchemaClient SchemaLoader$SchemaLoaderBuilder]
[org.everit.json.schema Schema]
[org.everit.json.schema ValidationException]))

(defn- ^JSONTokener prepare-tokener
"Prepares a JSONTokener instance for further processing"
[input]
(JSONTokener. ^String (if (string? input)
input
(json/generate-string input))))
[input]
(JSONTokener.
^Reader (StringReader.
^String (if (string? input)
input
(json/generate-string input)))))

(defn- prepare-json
"Prepares JSON instance based on input string, map or vector"
[input]
(if (or (associative? input)
(and (string? input)
(#{\{ \[} (first input))))
(let [json-tokener (prepare-tokener input)]
(let [json-tokener ^JSONTokener(prepare-tokener input)]
(if (or (vector? input)
(= \[ (first input)))
(JSONArray. ^JSONTokener json-tokener)
(JSONObject. ^JSONTokener json-tokener)))
(JSONArray. json-tokener)
(JSONObject. json-tokener)))
(throw (ex-info "Unsupported JSON input" {:input input}))))

(defn- assert-schema-input-valid! [input]
Expand Down Expand Up @@ -52,13 +56,15 @@
(if-not (:classpath-aware? params)
(prepare-schema* input)
(let [resolution-scope (:default-resolution-scope params)
set-resolution-scope (fn [client] (if resolution-scope
(.resolutionScope client resolution-scope)
client))
set-resolution-scope (fn [^SchemaLoader$SchemaLoaderBuilder builder]
(if resolution-scope
(.resolutionScope builder ^String resolution-scope)
builder))
schema-loader (-> (SchemaLoader/builder)
(.schemaClient (SchemaClient/classPathAwareClient))
(set-resolution-scope)
(.schemaJson (JSONObject. (prepare-tokener input)))
^SchemaLoader$SchemaLoaderBuilder (set-resolution-scope)
(.schemaJson
^JSONObject (JSONObject. (prepare-tokener input)))
(.build))]
(.build (.load schema-loader))))))

Expand Down
2 changes: 1 addition & 1 deletion test/json_schema/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
(json/validate schema "{}" :include-original-exception)
(catch Throwable ex
ex))]
(is (instance? ValidationException (.getCause ex)))))
(is (instance? ValidationException (.getCause ^Exception ex)))))

(testing "Causing ExceptionInfo when validation fails"
(let [schema {:$schema "http://json-schema.org/draft-07/schema#"
Expand Down

0 comments on commit 9985a14

Please sign in to comment.