Skip to content

Commit 74b6b47

Browse files
authored
Merge pull request #23 from eadwinCode/extra_config_parameter
fix:Extra config dict parameter for new schema generation
2 parents d547755 + d223f96 commit 74b6b47

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

ninja_schema/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Django Schema - Builds Pydantic Schemas from Django Models with default field type validations"""
22

3-
__version__ = "0.14.0"
3+
__version__ = "0.14.1"
44

55
from .orm.factory import SchemaFactory
66
from .orm.model_schema import ModelSchema

ninja_schema/orm/factory.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def create_schema(
3939
exclude: Optional[List[str]] = None,
4040
skip_registry: bool = False,
4141
optional_fields: Optional[Union[str, List[str]]] = None,
42+
**model_config_options: DictStrAny,
4243
) -> Union[Type["ModelSchema"], Type["Schema"], None]:
4344
from .model_schema import ModelSchema
4445

@@ -59,6 +60,7 @@ def create_schema(
5960
"depth": depth,
6061
"registry": registry,
6162
"optional": optional_fields,
63+
**model_config_options,
6264
}
6365
cls.get_model_config(**model_config_kwargs) # type: ignore
6466
new_schema = (
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import pytest
2+
3+
from ninja_schema.orm.factory import SchemaFactory
4+
from ninja_schema.pydanticutils import IS_PYDANTIC_V1
5+
from tests.models import Event
6+
7+
8+
@pytest.mark.skipif(IS_PYDANTIC_V1, reason="requires pydantic == 2.1.x")
9+
def test_create_schema_with_model_config_options():
10+
schema = SchemaFactory.create_schema(
11+
Event,
12+
skip_registry=True,
13+
from_attributes=True, # model_config_option
14+
title="Custom Title", # model_config_option
15+
)
16+
17+
assert schema.model_config["from_attributes"] is True
18+
assert schema.model_config["title"] == "Custom Title"

0 commit comments

Comments
 (0)