{"id":28941398,"url":"https://github.com/metosin/schema-tools","last_synced_at":"2025-09-25T15:33:09.952Z","repository":{"id":24785374,"uuid":"28199037","full_name":"metosin/schema-tools","owner":"metosin","description":"Clojure(Script) tools for Plumatic Schema","archived":false,"fork":false,"pushed_at":"2025-01-01T13:39:17.000Z","size":650,"stargazers_count":108,"open_issues_count":15,"forks_count":16,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-06-15T23:28:40.182Z","etag":null,"topics":["clojure","clojurescript","metosin-stable","schema","swagger"],"latest_commit_sha":null,"homepage":"http://metosin.github.io/schema-tools/","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/metosin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-12-18T19:51:49.000Z","updated_at":"2025-06-05T18:08:48.000Z","dependencies_parsed_at":"2024-12-24T13:05:20.376Z","dependency_job_id":"3adbfbd4-43b6-4d4b-bf87-e22c8dcdb8f1","html_url":"https://github.com/metosin/schema-tools","commit_stats":{"total_commits":331,"total_committers":15,"mean_commits":"22.066666666666666","dds":0.3987915407854985,"last_synced_commit":"991dd1b725d953688f23e95197d110d0d2b3d8a3"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"purl":"pkg:github/metosin/schema-tools","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metosin%2Fschema-tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metosin%2Fschema-tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metosin%2Fschema-tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metosin%2Fschema-tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/metosin","download_url":"https://codeload.github.com/metosin/schema-tools/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metosin%2Fschema-tools/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260134579,"owners_count":22963940,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clojure","clojurescript","metosin-stable","schema","swagger"],"created_at":"2025-06-23T02:10:28.441Z","updated_at":"2025-09-25T15:33:09.940Z","avatar_url":"https://github.com/metosin.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Schema-tools ![Build status](https://github.com/metosin/schema-tools/actions/workflows/clojure.yml/badge.svg) [![cljdoc badge](https://cljdoc.org/badge/metosin/schema-tools)](https://cljdoc.org/d/metosin/schema-tools/CURRENT)\n\nCommon utilities for [Prismatic Schema](https://github.com/Prismatic/schema) for Clojure/Script. Big sister to [spec-tools](https://github.com/metosin/spec-tools).\n\n* common Schema definitions: `any-keys`, `any-keyword-keys`, `open-schema`, `optional-keys-schema`\n* schema-aware selectors: `get-in`, `select-keys`, `select-schema`\n* schema-aware transformers: `assoc`, `dissoc`, `assoc-in`, `update-in`, `update`, `dissoc-in`, `merge`, `optional-keys`, `required-keys`\n  * removes the schema name and ns if the schema (value) has changed.\n* handle schema default values via `default` \u0026 `default-coercion-matcher`\n* meta-data helpers: `schema-with-description` `schema-description`, `resolve-schema` (clj only), `resolve-schema-description` (clj only)\n* coercion tools: `or-matcher`, `map-filter-matcher`, `multi-matcher`, `coercer`, `coerce`\n* tuned JSON \u0026 String matchers: from keywords, Java8 dates etc.\n* Protocol-based walker for manipulating Schemas in `schema-tools.walk`: `walk`, `prewalk` and `postwalk`.\n* Swagger2 generation\n* Coercion tools\n\n[API Docs](https://cljdoc.org/d/metosin/schema-tools/CURRENT).\n\n## Latest version\n\n[![Clojars Project](http://clojars.org/metosin/schema-tools/latest-version.svg)](http://clojars.org/metosin/schema-tools)\n\nRequires Java 1.8.\n\n## Examples\n\nNormal `clojure.core` functions don't work well with Schemas:\n\n```clojure\n(require '[schema.core :as s])\n\n(s/defschema Address {:street s/Str\n                      (s/optional-key :city) s/Str\n                      (s/required-key :country) {:name s/Str}})\n\n;; where's my city?\n(select-keys Address [:street :city])\n; {:street java.lang.String}\n\n; this should not return the original Schema name...\n(s/schema-name (select-keys Address [:street :city]))\n; Address\n```\n\nWith schema-tools:\n\n```clojure\n(require '[schema-tools.core :as st])\n\n(st/select-keys Address [:street :city])\n; {:street java.lang.String, #schema.core.OptionalKey{:k :city} java.lang.String}\n\n(s/schema-name (st/select-keys Address [:street :city]))\n; nil\n```\n\n### Coercion\n\nIf a given value can't be coerced to match a schema, ex-info is thrown (like `schema.core/validate`):\n\n```clojure\n(require '[schema-tools.coerce :as stc])\n\n(def matcher (constantly nil))\n(def coercer (stc/coercer String matcher))\n\n(coercer 123)\n; clojure.lang.ExceptionInfo: Could not coerce value to schema: (not (instance? java.lang.String 123))\n;      error: (not (instance? java.lang.String 123))\n;     schema: java.lang.String\n;       type: :schema-tools.coerce/error\n;      value: 123\n\n(coercer \"123\")\n; \"123\"\n\n; same behavior with coerce (creates coercer on each invocation, slower)\n(stc/coerce 123 String matcher)\n(stc/coerce \"123\" String matcher)\n```\n\nCoercion error `:type` can be overridden in both cases with an extra argument.\n\n```clojure\n(stc/coerce 123 String matcher :domain/horror)\n; clojure.lang.ExceptionInfo: Could not coerce value to schema: (not (instance? java.lang.String 123))\n;      error: (not (instance? java.lang.String 123))\n;     schema: java.lang.String\n;       type: :domain/horror\n;      value: 123\n```\n\n### Select Schema\n\nFiltering out illegal schema keys (using coercion):\n\n```clojure\n(st/select-schema {:street \"Keskustori 8\"\n                   :city \"Tampere\"\n                   :description \"Metosin HQ\" ; disallowed-key\n                   :country {:weather \"-18\" ; disallowed-key\n                             :name \"Finland\"}}\n                  Address)\n; {:city \"Tampere\", :street \"Keskustori 8\", :country {:name \"Finland\"}}\n```\n\nFiltering out illegal schema map keys using coercion with additional Json-coercion - in a single sweep:\n\n```clojure\n(s/defschema Beer {:beer (s/enum :ipa :apa)})\n\n(def ipa {:beer \"ipa\" :taste \"good\"})\n\n(st/select-schema ipa Beer)\n; clojure.lang.ExceptionInfo: Could not coerce value to schema: {:beer (not (#{:ipa :apa} \"ipa\"))}\n;     data: {:type :schema.core/error,\n;            :schema {:beer {:vs #{:ipa :apa}}},\n;            :value {:beer \"ipa\", :taste \"good\"},\n;            :error {:beer (not (#{:ipa :apa} \"ipa\"))}}\n\n(require '[schema.coerce :as sc])\n\n(st/select-schema ipa Beer sc/json-coercion-matcher)\n; {:beer :ipa}\n```\n\n## Usage\n\nSee the [tests](https://github.com/metosin/schema-tools/tree/master/test/).\n\n## License\n\nCopyright © 2014-2019 [Metosin Oy](http://www.metosin.fi)\n\nDistributed under the Eclipse Public License 2.0.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetosin%2Fschema-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmetosin%2Fschema-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetosin%2Fschema-tools/lists"}