Skip to content

Commit 33909eb

Browse files
authored
Merge pull request #200 from machow/feat-pydantic-no-extra
feat: do not accept extra fields in pydantic
2 parents af7191a + f17eaab commit 33909eb

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

quartodoc/layout.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import logging
55

66
from enum import Enum
7-
from pydantic import BaseModel, Field
7+
from pydantic import BaseModel, Field, Extra
88

99
from typing_extensions import Annotated
1010
from typing import Literal, Union, Optional
@@ -16,6 +16,9 @@
1616
class _Base(BaseModel):
1717
"""Any data class that might appear in the quartodoc config."""
1818

19+
class Config:
20+
extra = Extra.forbid
21+
1922

2023
class _Structural(_Base):
2124
"""A structural element, like an index Section or Page of docs."""
@@ -245,6 +248,7 @@ class Link(_Docable):
245248

246249
class Config:
247250
arbitrary_types_allowed = True
251+
extra = Extra.forbid
248252

249253

250254
class Doc(_Docable):
@@ -275,6 +279,7 @@ class Doc(_Docable):
275279

276280
class Config:
277281
arbitrary_types_allowed = True
282+
extra = Extra.forbid
278283

279284
@classmethod
280285
def from_griffe(
@@ -374,6 +379,7 @@ class Item(BaseModel):
374379

375380
class Config:
376381
arbitrary_types_allowed = True
382+
extra = Extra.forbid
377383

378384

379385
# Update forwared refs --------------------------------------------------------

quartodoc/tests/test_layout.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22

3+
from pydantic import ValidationError
34
from quartodoc.layout import Layout, Page, Text, Section # noqa
45

56

@@ -27,3 +28,10 @@ def test_layout_from_config(cfg, res):
2728

2829
layout = Layout(sections=[cfg])
2930
assert layout.sections[0] == res
31+
32+
33+
def test_layout_extra_forbidden():
34+
with pytest.raises(ValidationError) as exc_info:
35+
Section(title="abc", desc="xyz", contents=[], zzzzz=1)
36+
37+
assert "extra fields not permitted" in str(exc_info.value)

0 commit comments

Comments
 (0)