From 1f6de3c370351b05e455bf24cf7ba011a5b2bda7 Mon Sep 17 00:00:00 2001 From: Ikuru K Date: Sat, 1 Jun 2019 07:15:07 -0700 Subject: [PATCH] Prevent default spec names overwriting the :name provided in st/spec --- src/spec_tools/json_schema.cljc | 5 ++++- test/cljc/spec_tools/json_schema_test.cljc | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/spec_tools/json_schema.cljc b/src/spec_tools/json_schema.cljc index d7d59ffe..a02daf7f 100644 --- a/src/spec_tools/json_schema.cljc +++ b/src/spec_tools/json_schema.cljc @@ -282,7 +282,10 @@ json-schema-meta (impl/unlift-keys data "json-schema") extra-info (-> (select-keys data [:description]) (cond-> (and name (not synthetic?)) - (assoc :title (impl/qualified-name name))))] + (assoc :title (or (when-let [name-use (:name data)] + (when (string? name-use) + name-use)) + (impl/qualified-name name)))))] (merge (impl/unwrap children) extra-info json-schema-meta))) (defmethod accept-spec ::default [_ _ _ _] diff --git a/test/cljc/spec_tools/json_schema_test.cljc b/test/cljc/spec_tools/json_schema_test.cljc index d99117fb..81f8b78e 100644 --- a/test/cljc/spec_tools/json_schema_test.cljc +++ b/test/cljc/spec_tools/json_schema_test.cljc @@ -250,3 +250,11 @@ (s/and (s/keys :req-un [::bar]) (s/keys :req-un [::foo]))))) "allOf properties are merged into properties and required")) + +(s/def ::spec-with-explicit-name + (st/spec {:spec ::keys-no-req + :name "specific-name"})) + +(deftest name-is-respected-test + (is (= (:title (jsc/transform ::spec-with-explicit-name)) + "specific-name")))