Skip to content

Commit

Permalink
Merge pull request #23 from eadwinCode/extra_config_parameter
Browse files Browse the repository at this point in the history
fix:Extra config dict parameter for new schema generation
  • Loading branch information
eadwinCode authored Dec 30, 2024
2 parents d547755 + d223f96 commit 74b6b47
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ninja_schema/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Django Schema - Builds Pydantic Schemas from Django Models with default field type validations"""

__version__ = "0.14.0"
__version__ = "0.14.1"

from .orm.factory import SchemaFactory
from .orm.model_schema import ModelSchema
Expand Down
2 changes: 2 additions & 0 deletions ninja_schema/orm/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def create_schema(
exclude: Optional[List[str]] = None,
skip_registry: bool = False,
optional_fields: Optional[Union[str, List[str]]] = None,
**model_config_options: DictStrAny,
) -> Union[Type["ModelSchema"], Type["Schema"], None]:
from .model_schema import ModelSchema

Expand All @@ -59,6 +60,7 @@ def create_schema(
"depth": depth,
"registry": registry,
"optional": optional_fields,
**model_config_options,
}
cls.get_model_config(**model_config_kwargs) # type: ignore
new_schema = (
Expand Down
18 changes: 18 additions & 0 deletions tests/test_v2_pydantic/test_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest

from ninja_schema.orm.factory import SchemaFactory
from ninja_schema.pydanticutils import IS_PYDANTIC_V1
from tests.models import Event


@pytest.mark.skipif(IS_PYDANTIC_V1, reason="requires pydantic == 2.1.x")
def test_create_schema_with_model_config_options():
schema = SchemaFactory.create_schema(
Event,
skip_registry=True,
from_attributes=True, # model_config_option
title="Custom Title", # model_config_option
)

assert schema.model_config["from_attributes"] is True
assert schema.model_config["title"] == "Custom Title"

0 comments on commit 74b6b47

Please sign in to comment.