I'm trying to create a schema for a CSV data structure with defined, case insensitive headers. It must also be able to generate a legal data structure. I'm using the same pattern as clojure.data.csv
, a vector of vectors with the first vector representing the headers and the remaining vectors representing the rows. I can create a schema for the headers that checks validity fairly simply
(def headers
[:cat
[:re "(?i)header1"]
[:re "(?i)header2"]
...
[:re "(?i)headerN"]])
But test.chunk
doesn't handle flags (the (?i)
bit), so I don't have a generator.
My next guess is to create a schema that can match a given string case-insensitively and then a generator that will generate a randomly cased version of that string. I can write these two functions, but can't work out how to create a schema with them. Any thoughts or docs you can point me to?@hugh336 maybe a custom generator? [:re {:gen/gen gen/alphanumric} "(?i)header1"]
Aha! Awesome, thanks for the quick reply :thumbsup:
here a {:gen/elements ["header1"]}
would be good, just data and always correct.
@ikitommi I also have several malli schemas that need to verify for [:fn (complement str/blank)]
and I saw an open discussion from some years ago in Malli about adding validation of stripped strings to [:string]
base schema
is this still desired?
not some years.. last year, sorry. thought was 2019 https://github.com/metosin/malli/pull/205
is the [:string {:min 1}]
bad?
maybe (def NonEmptyString [:string {:min 1}])
liike we would do in Schema?
or:
[:map {:registry {::non-blank-string [:string {:min 1}]}}
[:name ::non-blank-string]
[:address [:map [:street ::non-blank-string]]]]
(m/validate [:string {:min 1}] " ")
;; => true but I expect false if no blank is allowed
I like the idea of using {:trim true :min 1 :max 99}
.. looks very clean and we dont need to add custom registries