Skip to content

Instantly share code, notes, and snippets.

@Deraen
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Deraen/ea311e6622915108f2ca to your computer and use it in GitHub Desktop.
Save Deraen/ea311e6622915108f2ca to your computer and use it in GitHub Desktop.
Clojure Schema/Validation Libs

Notes

  • Most libraries do only validation. Schema does also coercion.

Pros:

  • Schemas are represented using collections and maps etc.
    • It's easy to modify existing schemas using general fns:
    • (s/defschema NewUser (dissoc User :_id))
  • Provides coercion
    • Coerce valus from strings to anything
    • Useful when using with JSON

Cons:

  • It's easy to lose propert order when schema is defined using hash-map
  • It's hard to validate a property if validation depends on value of another property
  • Provides "machine-readable" errors, but the errors usually are lists, e.g. (not (eq "123")) it's a bit hard to read those using Clojure
    • Could be fixed by implementing a library which implements some Protocol for each Schema
    • Schemas call macros/validation-error and create list describing the error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment