Skip to content

Commit 4478b1e

Browse files
committed
docs: Update documentation for Types, Wrappers, and Configuration
This commit updates several guide files to reflect recent API additions and improvements across the library. Types and DSL: - Documented Types.type/1, Types.validate/2, and Types.coerce/2 helpers. - Added documentation for the optional coerce_rule/0 and custom_rules/0 callbacks when defining custom type modules. Wrappers and Adapters: - Documented the create_wrapper_factory/2 function which allows for the creation of reusable wrapper templates. Configuration and Settings: - Added documentation for error_format and allow_population_by_field_name fields in the settings schema. Error Reporting: - Updated formatting and descriptions for the reporting APIs to improve readability and detail coverage.
1 parent cdd74e3 commit 4478b1e

4 files changed

Lines changed: 23 additions & 10 deletions

guides/02_schema_dsl_and_types.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,14 @@ email_type =
149149
Key helpers:
150150

151151
- `Types.string/0`, `Types.integer/0`, `Types.float/0`, `Types.boolean/0`
152+
- `Types.type/1` generic constructor (e.g., `Types.type(:string)`)
152153
- `Types.array/1`, `Types.map/2`, `Types.object/1`, `Types.union/1`, `Types.tuple/1`
153154
- `Types.ref/1`, `Types.normalize_type/1`
154155
- `Types.with_constraints/2`
155156
- `Types.with_error_message/3`, `Types.with_error_messages/2`
156157
- `Types.with_validator/2` for custom value-level checks
158+
- `Types.validate/2` for direct type checking (e.g., `Types.validate(:string, value)`)
159+
- `Types.coerce/2` for standalone type coercion (e.g., `Types.coerce(:integer, "123")`)
157160

158161
## Custom Type Modules with `Exdantic.Type`
159162

@@ -180,6 +183,11 @@ defmodule MyApp.Types.Email do
180183
end
181184
```
182185

186+
Optional callbacks:
187+
188+
- `coerce_rule/0` — returns a coercion function or `{module, function}` tuple (default `nil`)
189+
- `custom_rules/0` — returns a list of additional validation function names defined in the module (default `[]`)
190+
183191
Then use it as a field type:
184192

185193
```elixir

guides/05_type_adapter_wrapper_root_schema.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,18 @@ wrappers = Exdantic.Wrapper.create_multiple_wrappers([
9999
- map with atom key
100100
- map with string key
101101

102+
### Reusable wrapper factory
103+
104+
`create_wrapper_factory/2` returns a function that creates pre-configured wrappers:
105+
106+
```elixir
107+
factory = Exdantic.Wrapper.create_wrapper_factory(:integer, constraints: [gt: 0], coerce: true)
108+
wrapper = factory.(:score)
109+
```
110+
102111
Wrapper helpers:
103112

113+
- `create_wrapper_factory/2`
104114
- `to_json_schema/2`
105115
- `unwrap_result/2`
106116
- `wrapper_schema?/1`

guides/08_configuration_and_settings.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ Key fields:
2525
- `frozen`: immutable config guard
2626
- `validate_assignment`
2727
- `case_sensitive`
28+
- `error_format`: `:detailed | :simple | :minimal`
2829
- `use_enum_values`
30+
- `allow_population_by_field_name`: support field name aliases (default `true`)
2931
- `max_anyof_union_len`
3032
- optional generator functions (`title_generator`, `description_generator`)
3133

guides/09_errors_reports_and_operations.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,15 @@ Type-only:
6666

6767
## Reporting APIs
6868

69-
## Quick report
69+
### Quick report
7070

7171
```elixir
7272
report = Exdantic.EnhancedValidator.validation_report(target, input)
7373
```
7474

75-
Includes:
75+
Returns a lightweight summary: validation result, generated JSON Schema, target and input analysis, timing metrics, and config summary.
7676

77-
- validation result
78-
- generated JSON Schema
79-
- target analysis
80-
- input analysis
81-
- timing metrics
82-
- config summary
83-
84-
## Comprehensive report
77+
### Comprehensive report
8578

8679
```elixir
8780
report =

0 commit comments

Comments
 (0)