Skip to content

Commit 192e346

Browse files
committed
doc: fix enforce option handling
1 parent 3262457 commit 192e346

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

guides/plugins/doc_fields.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ accessible information.
88
Below is the final code generated by the plugin, which includes comprehensive
99
documentation for the `User` struct:
1010

11-
```
11+
```elixir
1212
defmodule User do
1313
@typedoc """
1414
@type t(age) :: %User{age: age | nil, name: String.t() | nil}
@@ -33,6 +33,7 @@ end
3333
```
3434

3535
## Implement
36+
3637
```elixir
3738
defmodule Guides.Plugins.DocFields do
3839
@moduledoc """
@@ -115,11 +116,12 @@ defmodule Guides.Plugins.DocFields do
115116
fields =
116117
Enum.map(definition.fields, fn field ->
117118
name = Keyword.fetch!(field, :name)
118-
119119
type = Keyword.fetch!(field, :type)
120120

121+
enforce = Keyword.get(definition.options, :enforce, false)
122+
121123
type =
122-
if Keyword.get(field, :enforce, false) or Keyword.has_key?(field, :default) do
124+
if Keyword.get(field, :enforce, enforce) or Keyword.has_key?(field, :default) do
123125
Macro.to_string(type)
124126
else
125127
# escape `|`
@@ -164,6 +166,7 @@ end
164166
```
165167

166168
## Usage
169+
167170
```elixir
168171
defmodule User do
169172
@moduledoc false

0 commit comments

Comments
 (0)