Designed to help data processing using clojure.spec
.
Provide users the ability to combine several pre-defined
clojure.spec
into some specific shape at runtime.
For now, it only supports JSON files.
Leiningen/Boot
[meta-schema "0.1.0-SNAPSHOT"]
Clojure CLI/deps.edn
meta-schema {:mvn/version "0.1.0-SNAPSHOT"}
In your project you need to define EDN files inside a folder
and provide a list of java.io.File
s to the (setup! ..)
function. These files are simple and provides the location
and intent of your pre-defined specs.
{:zipcode {:intent "Validation to ZipCodes in Brazil"
:location :my-project.spec/zipcode-br}
:money {:intent "How we understand money around here? Anything >= 0 either long, float, double, or decimal"
:location :my-project.other-spec/money-br}
}
Make sure that all this namespaces are loaded before invoke
meta-schema.core/setup!
.
Example of specification provided to the library at runtime.
(require '[meta-schema.core :as ms])
(require '[clojure.alpha.spec :as s])
(require '[clojure.java.io :as io])
(ms/setup! (-> (io/resources "specs")
(io/file)
(file-seq)))
(def file-spec {:spec-name :my-project.client/payload
:zip [{:spec :zipcode
:optional? false
:nullable? false}
{:house-price {:spec :money
:nullable? true}}]
:rent {:spec :money
:optional? false
:nullable? false}
:university {:departments [{:zip {:address {:spec :zipcode
:optional? false}}}]}})
(def my-parser (ms/create-parser file-spec))
(def my-data-1 {:zip ["my zipcode is text"]
:rent 10
:university {:departments [{:zip {:address "deep structures"}}]}})
(s/valid? my-parser my-data-1) ;; => true
(s/valid? my-parser {:zip [{:house-price 230} "either or both here.."]
:rent 10
:university {:departments [{:zip {:address "deep structures"}}]}}) ;; => true
The DSL is simple:
or
operatoroptional
, it means that may or may not be present at coersion timenullable
, it means that nil
is a valid input.sets
and enums
(?)Copyright © 2020 Wanderson Ferreira (@bartuka)
This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0.
This Source Code may also be made available under the following Secondary Licenses when the conditions for such availability set forth in the Eclipse Public License, v. 2.0 are satisfied: GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version, with the GNU Classpath Exception which is available at https://www.gnu.org/software/classpath/license.html.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close