All Projects → metosin → schema-tools

metosin / schema-tools

Licence: EPL-2.0 license
Clojure(Script) tools for Plumatic Schema

Programming Languages

clojure
4091 projects
shell
77523 projects

Projects that are alternatives of or similar to schema-tools

Mail
RiiConnect24 Mail Scripts. OSS.
Stars: ✭ 11 (-88.66%)
Mutual labels:  schema
spark-hats
Nested array transformation helper extensions for Apache Spark
Stars: ✭ 21 (-78.35%)
Mutual labels:  schema
xsdata
Naive XML & JSON Bindings for python
Stars: ✭ 144 (+48.45%)
Mutual labels:  schema
to-json-schema
Converts JS objects to JSON Schema
Stars: ✭ 83 (-14.43%)
Mutual labels:  schema
hcl-lang
Schema and decoder to be used as building blocks for an HCL2-based language server.
Stars: ✭ 44 (-54.64%)
Mutual labels:  schema
gdelt2HeaderRows
A file that contains the schema for GDELT 2.0 Header rows for the Events Database.
Stars: ✭ 28 (-71.13%)
Mutual labels:  schema
sf-java-ui
Json Schema Form java based library allow developers to define schema and form using field annotations
Stars: ✭ 23 (-76.29%)
Mutual labels:  schema
shared-row
This is an open data specification for describing the right-of-way (ROW) for street centerline networks. It is intended to establish a common set of attributes (schema) to describe how space is allocated along a streets right of way from sidewalk edge to sidewalk edge.
Stars: ✭ 16 (-83.51%)
Mutual labels:  schema
shex.js
shex.js javascript package
Stars: ✭ 45 (-53.61%)
Mutual labels:  schema
ballade
For unidirectional data flow.
Stars: ✭ 44 (-54.64%)
Mutual labels:  schema
schema.tl
📜 Easy-to-use TL-Schema viewer
Stars: ✭ 55 (-43.3%)
Mutual labels:  schema
storage
Mongoose-like schema validation, collections and documents on browser (client-side)
Stars: ✭ 17 (-82.47%)
Mutual labels:  schema
avro ex
An Avro Library that emphasizes testability and ease of use.
Stars: ✭ 47 (-51.55%)
Mutual labels:  schema
querymen
Querystring parser middleware for MongoDB, Express and Nodejs (MEN)
Stars: ✭ 128 (+31.96%)
Mutual labels:  schema
php-binary
A PHP library for parsing structured binary streams.
Stars: ✭ 30 (-69.07%)
Mutual labels:  schema
graphql-directive-sql
Unify your SQL schema and your GraphQL Schema. Use GraphQL SDL as the lingua franca to define your data requirements.
Stars: ✭ 28 (-71.13%)
Mutual labels:  schema
hodur-lacinia-schema
Hodur is a domain modeling approach and collection of libraries to Clojure. By using Hodur you can define your domain model as data, parse and validate it, and then either consume your model via an API or use one of the many plugins to help you achieve mechanical results faster and in a purely functional manner.
Stars: ✭ 20 (-79.38%)
Mutual labels:  schema
transferdb
TransferDB 支持异构数据库 schema 转换、全量数据导出导入以及增量数据同步功能( Oracle 数据库 -> MySQL/TiDB 数据库)
Stars: ✭ 30 (-69.07%)
Mutual labels:  schema
awesome-csv
Awesome Comma-Separated Values (CSV) - What's Next? - Frequently Asked Questions (F.A.Q.s) - Libraries & Tools
Stars: ✭ 46 (-52.58%)
Mutual labels:  schema
txbox
Elixir Bitcoin transaction storage schema, built on Ecto.
Stars: ✭ 14 (-85.57%)
Mutual labels:  schema

Schema-tools Build status cljdoc badge

Common utilities for Prismatic Schema for Clojure/Script. Big sister to spec-tools.

  • common Schema definitions: any-keys, any-keyword-keys, open-schema, optional-keys-schema
  • schema-aware selectors: get-in, select-keys, select-schema
  • schema-aware transformers: assoc, dissoc, assoc-in, update-in, update, dissoc-in, merge, optional-keys, required-keys
    • removes the schema name and ns if the schema (value) has changed.
  • handle schema default values via default & default-coercion-matcher
  • meta-data helpers: schema-with-description schema-description, resolve-schema (clj only), resolve-schema-description (clj only)
  • coercion tools: or-matcher, map-filter-matcher, multi-matcher, coercer, coerce
  • tuned JSON & String matchers: from keywords, Java8 dates etc.
  • Protocol-based walker for manipulating Schemas in schema-tools.walk: walk, prewalk and postwalk.
  • Swagger2 generation
  • Coercion tools

API Docs.

Latest version

Clojars Project

Requires Java 1.8.

Examples

Normal clojure.core functions don't work well with Schemas:

(require '[schema.core :as s])

(s/defschema Address {:street s/Str
                      (s/optional-key :city) s/Str
                      (s/required-key :country) {:name s/Str}})

;; where's my city?
(select-keys Address [:street :city])
; {:street java.lang.String}

; this should not return the original Schema name...
(s/schema-name (select-keys Address [:street :city]))
; Address

With schema-tools:

(require '[schema-tools.core :as st])

(st/select-keys Address [:street :city])
; {:street java.lang.String, #schema.core.OptionalKey{:k :city} java.lang.String}

(s/schema-name (st/select-keys Address [:street :city]))
; nil

Coercion

If a given value can't be coerced to match a schema, ex-info is thrown (like schema.core/validate):

(require '[schema-tools.coerce :as stc])

(def matcher (constantly nil))
(def coercer (stc/coercer String matcher))

(coercer 123)
; clojure.lang.ExceptionInfo: Could not coerce value to schema: (not (instance? java.lang.String 123))
;      error: (not (instance? java.lang.String 123))
;     schema: java.lang.String
;       type: :schema-tools.coerce/error
;      value: 123

(coercer "123")
; "123"

; same behavior with coerce (creates coercer on each invocation, slower)
(stc/coerce 123 String matcher)
(stc/coerce "123" String matcher)

Coercion error :type can be overridden in both cases with an extra argument.

(stc/coerce 123 String matcher :domain/horror)
; clojure.lang.ExceptionInfo: Could not coerce value to schema: (not (instance? java.lang.String 123))
;      error: (not (instance? java.lang.String 123))
;     schema: java.lang.String
;       type: :domain/horror
;      value: 123

Select Schema

Filtering out illegal schema keys (using coercion):

(st/select-schema {:street "Keskustori 8"
                   :city "Tampere"
                   :description "Metosin HQ" ; disallowed-key
                   :country {:weather "-18" ; disallowed-key
                             :name "Finland"}}
                  Address)
; {:city "Tampere", :street "Keskustori 8", :country {:name "Finland"}}

Filtering out illegal schema map keys using coercion with additional Json-coercion - in a single sweep:

(s/defschema Beer {:beer (s/enum :ipa :apa)})

(def ipa {:beer "ipa" :taste "good"})

(st/select-schema ipa Beer)
; clojure.lang.ExceptionInfo: Could not coerce value to schema: {:beer (not (#{:ipa :apa} "ipa"))}
;     data: {:type :schema.core/error,
;            :schema {:beer {:vs #{:ipa :apa}}},
;            :value {:beer "ipa", :taste "good"},
;            :error {:beer (not (#{:ipa :apa} "ipa"))}}

(require '[schema.coerce :as sc])

(st/select-schema ipa Beer sc/json-coercion-matcher)
; {:beer :ipa}

Usage

See the tests.

License

Copyright © 2014-2019 Metosin Oy

Distributed under the Eclipse Public License 2.0.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].