Skip to content

Commit

Permalink
:octocat: Update docs for #605
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Oct 28, 2024
1 parent a794a7b commit 770811f
Show file tree
Hide file tree
Showing 11 changed files with 1,636 additions and 1,542 deletions.
2 changes: 1 addition & 1 deletion api/search.js

Large diffs are not rendered by default.

678 changes: 345 additions & 333 deletions api/serde.html

Large diffs are not rendered by default.

2,434 changes: 1,232 additions & 1,202 deletions api/serde/de.html

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions guide/en/class-attributes.html
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,19 @@ <h3 id="serialize_class_var"><a class="header" href="#serialize_class_var"><stro
<div class="footnote-definition" id="1"><sup class="footnote-definition-label">1</sup>
<p><a href="https://docs.python.org/3/library/dataclasses.html#dataclasses.fields">dataclasses.fields</a></p>
</div>
<h3 id="deny_unknown_fields"><a class="header" href="#deny_unknown_fields"><strong><code>deny_unknown_fields</code></strong></a></h3>
<p>New in v0.22.0, the <code>deny_unknown_fields</code> option in the pyserde decorator allows you to enforce strict field validation during deserialization. When this option is enabled, any fields in the input data that are not defined in the target class will cause deserialization to fail with a <code>SerdeError</code>.</p>
<p>Consider the following example:</p>
<pre><code class="language-python">@serde(deny_unknown_fields=True)
class Foo:
a: int
b: str
</code></pre>
<p>With <code>deny_unknown_fields=True</code>, attempting to deserialize data containing fields beyond those defined (a and b in this case) will raise an error. For instance:</p>
<pre><code>from_json(Foo, '{"a": 10, "b": "foo", "c": 100.0, "d": true}')
</code></pre>
<p>This will raise a <code>SerdeError</code> since fields c and d are not recognized members of Foo.</p>
<p>See <a href="https://github.com/yukinarit/pyserde/blob/main/examples/deny_unknown_fields.py">examples/deny_unknown_fields.py</a> for complete example.</p>

</main>

Expand Down
13 changes: 13 additions & 0 deletions guide/en/print.html
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,19 @@ <h3 id="serialize_class_var"><a class="header" href="#serialize_class_var"><stro
<div class="footnote-definition" id="1"><sup class="footnote-definition-label">1</sup>
<p><a href="https://docs.python.org/3/library/dataclasses.html#dataclasses.fields">dataclasses.fields</a></p>
</div>
<h3 id="deny_unknown_fields"><a class="header" href="#deny_unknown_fields"><strong><code>deny_unknown_fields</code></strong></a></h3>
<p>New in v0.22.0, the <code>deny_unknown_fields</code> option in the pyserde decorator allows you to enforce strict field validation during deserialization. When this option is enabled, any fields in the input data that are not defined in the target class will cause deserialization to fail with a <code>SerdeError</code>.</p>
<p>Consider the following example:</p>
<pre><code class="language-python">@serde(deny_unknown_fields=True)
class Foo:
a: int
b: str
</code></pre>
<p>With <code>deny_unknown_fields=True</code>, attempting to deserialize data containing fields beyond those defined (a and b in this case) will raise an error. For instance:</p>
<pre><code>from_json(Foo, '{"a": 10, "b": "foo", "c": 100.0, "d": true}')
</code></pre>
<p>This will raise a <code>SerdeError</code> since fields c and d are not recognized members of Foo.</p>
<p>See <a href="https://github.com/yukinarit/pyserde/blob/main/examples/deny_unknown_fields.py">examples/deny_unknown_fields.py</a> for complete example.</p>
<div style="break-before: page; page-break-before: always;"></div><h1 id="field-attributes"><a class="header" href="#field-attributes">Field Attributes</a></h1>
<p>Field attributes are options to customize (de)serialization behaviour for a field of a dataclass.</p>
<h2 id="attributes-offered-by-dataclasses-1"><a class="header" href="#attributes-offered-by-dataclasses-1">Attributes offered by dataclasses</a></h2>
Expand Down
2 changes: 1 addition & 1 deletion guide/en/searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion guide/en/searchindex.json

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion guide/ja/class-attributes.html
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,23 @@ <h3 id="serialize_class_var"><a class="header" href="#serialize_class_var"><stro
class Foo:
a: ClassVar[int] = 10
</code></pre>
<p>完全な例については、<a href="https://github.com/yukinarit/pyserde/blob/main/examples/class_var.py">examples/class_var.py</a> を参照してください。</p>
<p>完全な例については、<a href="https://github.com/yukinarit/pyserde/blob/main/examples/class_var.py">examples/class_var.py</a>を参照してください。</p>
<div class="footnote-definition" id="1"><sup class="footnote-definition-label">1</sup>
<p><a href="https://docs.python.org/3/library/dataclasses.html#dataclasses.fields">dataclasses.fields</a></p>
</div>
<h3 id="deny_unknown_fields"><a class="header" href="#deny_unknown_fields"><strong><code>deny_unknown_fields</code></strong></a></h3>
<p>バージョン0.22.0で新規追加。 pyserdeデコレータの<code>deny_unknown_fields</code>オプションはデシリアライズ時のより厳格なフィールドチェックを制御できます。このオプションをTrueにするとデシリアライズ時に宣言されていないフィールドが見つかると<code>SerdeError</code>を投げることができます。</p>
<p>以下の例を考えてください。</p>
<pre><code class="language-python">@serde(deny_unknown_fields=True)
class Foo:
a: int
b: str
</code></pre>
<p><code>deny_unknown_fields=True</code>が指定されていると、 宣言されているフィールド(この場合aとb)以外がインプットにあると例外を投げます。例えば、</p>
<pre><code>from_json(Foo, '{"a": 10, "b": "foo", "c": 100.0, "d": true}')
</code></pre>
<p>上記のコードはフィールドcとdという宣言されていないフィールドがあるためエラーとなります。</p>
<p>完全な例については、<a href="https://github.com/yukinarit/pyserde/blob/main/examples/deny_unknown_fields.py">examples/deny_unknown_fields.py</a>を参照してください。</p>

</main>

Expand Down
15 changes: 14 additions & 1 deletion guide/ja/print.html
Original file line number Diff line number Diff line change
Expand Up @@ -820,10 +820,23 @@ <h3 id="serialize_class_var"><a class="header" href="#serialize_class_var"><stro
class Foo:
a: ClassVar[int] = 10
</code></pre>
<p>完全な例については、<a href="https://github.com/yukinarit/pyserde/blob/main/examples/class_var.py">examples/class_var.py</a> を参照してください。</p>
<p>完全な例については、<a href="https://github.com/yukinarit/pyserde/blob/main/examples/class_var.py">examples/class_var.py</a>を参照してください。</p>
<div class="footnote-definition" id="1"><sup class="footnote-definition-label">1</sup>
<p><a href="https://docs.python.org/3/library/dataclasses.html#dataclasses.fields">dataclasses.fields</a></p>
</div>
<h3 id="deny_unknown_fields"><a class="header" href="#deny_unknown_fields"><strong><code>deny_unknown_fields</code></strong></a></h3>
<p>バージョン0.22.0で新規追加。 pyserdeデコレータの<code>deny_unknown_fields</code>オプションはデシリアライズ時のより厳格なフィールドチェックを制御できます。このオプションをTrueにするとデシリアライズ時に宣言されていないフィールドが見つかると<code>SerdeError</code>を投げることができます。</p>
<p>以下の例を考えてください。</p>
<pre><code class="language-python">@serde(deny_unknown_fields=True)
class Foo:
a: int
b: str
</code></pre>
<p><code>deny_unknown_fields=True</code>が指定されていると、 宣言されているフィールド(この場合aとb)以外がインプットにあると例外を投げます。例えば、</p>
<pre><code>from_json(Foo, '{"a": 10, "b": "foo", "c": 100.0, "d": true}')
</code></pre>
<p>上記のコードはフィールドcとdという宣言されていないフィールドがあるためエラーとなります。</p>
<p>完全な例については、<a href="https://github.com/yukinarit/pyserde/blob/main/examples/deny_unknown_fields.py">examples/deny_unknown_fields.py</a>を参照してください。</p>
<div style="break-before: page; page-break-before: always;"></div><h1 id="field-attributes"><a class="header" href="#field-attributes">Field Attributes</a></h1>
<p>フィールド属性は、データクラスのフィールドの(デ)シリアライズ動作をカスタマイズするためのオプションです。</p>
<h2 id="dataclassesによって提供される属性"><a class="header" href="#dataclassesによって提供される属性">dataclassesによって提供される属性</a></h2>
Expand Down
2 changes: 1 addition & 1 deletion guide/ja/searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion guide/ja/searchindex.json

Large diffs are not rendered by default.

0 comments on commit 770811f

Please sign in to comment.