Skip to content

Commit

Permalink
extract type description spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick Scherer committed Dec 2, 2016
1 parent 6c0d41e commit 81c7e82
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
20 changes: 2 additions & 18 deletions src/alumbra/spec/analyzed_schema.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns alumbra.spec.analyzed-schema
(:require [clojure.spec :as s]
[clojure.spec.gen :as gen]
[alumbra.spec common]))
[alumbra.spec type-description common]))

;; ## Names

Expand Down Expand Up @@ -90,23 +90,7 @@
;; value is nested.
(s/keys :req-un [:alumbra/type-name
:alumbra/non-null?
::type-description]))

(s/def ::type-description
(s/with-gen
(s/or :unnested ::unnested
:nested ::nested)
#(gen/frequency
[[9 (s/gen ::unnested)]
[1 (gen/bind (gen/return nil) (fn [_] (s/gen ::nested)))]])))

(s/def ::nested
(s/keys :req-un [:alumbra/non-null?
::type-description]))

(s/def ::unnested
(s/keys :req-un [:alumbra/non-null?
:alumbra/type-name]))
:alumbra/type-description]))

;; ### Interfaces

Expand Down
20 changes: 20 additions & 0 deletions src/alumbra/spec/type_description.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(ns alumbra.spec.type-description
(:require [clojure.spec :as s]
[clojure.spec.gen :as gen]
[alumbra.spec common]))

(s/def :alumbra/type-description
(s/with-gen
(s/or :unnested ::unnested
:nested ::nested)
#(gen/frequency
[[9 (s/gen ::unnested)]
[1 (gen/bind (gen/return nil) (fn [_] (s/gen ::nested)))]])))

(s/def ::nested
(s/keys :req-un [:alumbra/non-null?
:alumbra/type-description]))

(s/def ::unnested
(s/keys :req-un [:alumbra/non-null?
:alumbra/type-name]))
2 changes: 1 addition & 1 deletion src/alumbra/spec/validation_errors.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns alumbra.spec.validation-errors
(:require [clojure.spec :as s]
[alumbra.spec common]))
[alumbra.spec common type-description]))

;; ## Error Container

Expand Down

0 comments on commit 81c7e82

Please sign in to comment.