Skip to content

brydoncheyney/dspec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DynamicSpec

Build Status

Clojars Project

Dynamic data validation using registered component specs.

Usage

Components can register a spec against a keyword:

(ns example.core
  (:require [dpsec.core :as dspec]))

  (s/def ::string string?)

  (defn -main [& args]
    (dspec/register :a ::string)
    (dspec/register :b ::string))

Data can then be validated against the registered component specs:

    (dspec/validate {:a "foo" :b "bar"})

If data fails to conform to the registered component specs a RuntimeException will be thrown, with ex-data that contains the map of s/explain-data, keyed by the given component keyword.

Using a component library such as component or mount:

    (defstate a :start (dspec/register :a ::string))
    (defstate b :start (dspec/register :b ::string))
    (defstate config :start (dspec/validate data))

Configuration Files

A utility function load-config exists to load and parse a yaml configuration file:

    (config/load-config "resources/Service.yml")

This can be validated against any registered configuration specs:

    (dspec/validate (config/load-config "resources/Service.yml"))

Example

A service using mount to manage component state can be found in the simple example app. On service start, the configuration is validated against the specs defined for the component dependencies of the service.

License

Copyright © 2017 Brydon Cheyney

About

Dynamic data validation using registered component specs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published