Add docs
This commit is contained in:
parent
53baaa050d
commit
e27a268902
|
@ -109,4 +109,4 @@ result.error?([:tags, 1])
|
|||
### Learn more
|
||||
|
||||
- [Customizing messages](docs::error-messages)
|
||||
- [Validation hints](docs::extensions/hints)
|
||||
- [Validation hints](docs::extensions/hints)
|
|
@ -6,6 +6,7 @@ sections:
|
|||
- hints
|
||||
- info
|
||||
- monads
|
||||
- json_schema
|
||||
---
|
||||
|
||||
`dry-schema` can be extended with extension. Those extensions are loaded with `Dry::Schema.load_extensions`.
|
||||
|
@ -15,3 +16,4 @@ Available extensions:
|
|||
- [Hints](docs::extensions/hints)
|
||||
- [Info](docs::extensions/info)
|
||||
- [Monads](docs::extensions/monads)
|
||||
- [JSON Schema](docs::extensions/json_schema)
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
---
|
||||
title: JSON Schema
|
||||
layout: gem-single
|
||||
name: dry-schema
|
||||
---
|
||||
|
||||
The `:json_schema` extension allows you to generate a valid [JSON Schema](https://json-schema.org/) from a `Dry::Schema`. JSON Schema is a widely used standard, so this unlocks many possibilities.
|
||||
|
||||
```ruby
|
||||
Dry::Schema.load_extensions(:json_schema)
|
||||
|
||||
UserSchema = Dry::Schema.JSON do
|
||||
required(:email).filled(:string, min_size?: 8)
|
||||
|
||||
optional(:age).filled(:integer)
|
||||
end
|
||||
|
||||
UserSchema.json_schema
|
||||
# {
|
||||
# "type": "object",
|
||||
# "properties": {
|
||||
# "email": {
|
||||
# "type": "string",
|
||||
# "minLength": 8
|
||||
# },
|
||||
# "age": {
|
||||
# "type": "integer"
|
||||
# },
|
||||
# "required": ["email"]
|
||||
# }
|
||||
```
|
||||
|
||||
### Learn more
|
||||
|
||||
- [Official JSON Schema docs](https://json-schema.org/)
|
||||
- [Auto-generate forms with React + JSON Schema](https://github.com/rjsf-team/react-jsonschema-form))
|
||||
- [Integrate with other languages more easily](https://json-schema.org/implementations.html)
|
||||
|
Loading…
Reference in New Issue