06: spec-gen
(ns reifyhealth.specmonstah-tutorial.06
(:require [reifyhealth.specmonstah.core :as sm]
[clojure.spec.alpha :as s]
[clojure.spec.gen.alpha :as gen]
[reifyhealth.specmonstah.spec-gen :as sg]))
(s/def ::id (s/and pos-int? #(< % 100)))
(s/def ::not-empty-string (s/and string? not-empty #(< (count %) 10)))
(s/def ::username ::not-empty-string)
(s/def ::user (s/keys :req-un [::id ::username]))
(s/def ::name ::not-empty-string)
(s/def ::topic (s/keys :req-un [::id ::name ::owner-id]))
(s/def ::owner-id ::id)
(s/def ::topic-id ::id)
(s/def ::content ::not-empty-string)
(s/def ::post (s/keys :req-un [::id ::owner-id ::topic-id ::content]))
(def schema
{:user {:prefix :u
:spec ::user}
:topic {:prefix :t
:spec ::topic
:relations {:owner-id [:user :id]}}
:post {:prefix :p
:spec ::todo
:relations {:topic-id [:topic :id]}}})
(defn ex-01
[]
{:user (gen/generate (s/gen ::user))
:topic (gen/generate (s/gen ::topic))
:post (gen/generate (s/gen ::post))})Last updated