Skip to content

Commit

Permalink
README
Browse files Browse the repository at this point in the history
  • Loading branch information
ikitommi committed Feb 28, 2021
1 parent de3ff9d commit daeef5a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,8 @@ Schema Types are described using `m/IntoSchema` protocol, which has a factory me
`(-into-schema [this properties children options])` to create the actual Schema instances.
See `malli.core` for example implementations.

### Simple Schema

For simple cases, there is `m/-simple-schema`:

```clj
Expand Down Expand Up @@ -1545,6 +1547,30 @@ register the types:
; => {:type "integer", :format "int64", :minimum 6, :example 42}
```

### Content Dependent Simple Schema

You can also build content-dependent schemas by using a callback function of `properties children -> opts` instead of static `opts`:

```clj
(def Over
(m/-simple-schema
(fn [{:keys [value]} _]
(assert (int? value))
{:type :user/over
:pred #(and (int? %) (> % value))
:type-properties {:error/fn (fn [error _] (str "should be over " value ", was " (:value error)))
:decode/string mt/-string->long
:json-schema/type "integer"
:json-schema/format "int64"
:json-schema/minimum value
:gen/gen (gen/large-integer* {:min (inc value)})}})))

(-> [Over {:value 12}]
(m/explain 10)
(me/humanize))
; => ["should be over 12, was 10"]
```

## Schema Registry

Schemas are looked up using a `malli.registry/Registry` protocol, which is effectively a map from schema `type` to a schema recipe (schema ast, `Schema` or `IntoSchema` instance).
Expand Down

0 comments on commit daeef5a

Please sign in to comment.