Skip to content

Commit

Permalink
doc: fix enforce option handling
Browse files Browse the repository at this point in the history
  • Loading branch information
fahchen committed Nov 28, 2024
1 parent 3262457 commit 192e346
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions guides/plugins/doc_fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ accessible information.
Below is the final code generated by the plugin, which includes comprehensive
documentation for the `User` struct:

```
```elixir
defmodule User do
@typedoc """
@type t(age) :: %User{age: age | nil, name: String.t() | nil}
Expand All @@ -33,6 +33,7 @@ end
```

## Implement

```elixir
defmodule Guides.Plugins.DocFields do
@moduledoc """
Expand Down Expand Up @@ -115,11 +116,12 @@ defmodule Guides.Plugins.DocFields do
fields =
Enum.map(definition.fields, fn field ->
name = Keyword.fetch!(field, :name)

type = Keyword.fetch!(field, :type)

enforce = Keyword.get(definition.options, :enforce, false)

type =
if Keyword.get(field, :enforce, false) or Keyword.has_key?(field, :default) do
if Keyword.get(field, :enforce, enforce) or Keyword.has_key?(field, :default) do
Macro.to_string(type)
else
# escape `|`
Expand Down Expand Up @@ -164,6 +166,7 @@ end
```

## Usage

```elixir
defmodule User do
@moduledoc false
Expand Down

0 comments on commit 192e346

Please sign in to comment.