Skip to content

Commit 1df8b46

Browse files
committed
Added ninja-schema as a dependency for model controller schema generation
1 parent 252283e commit 1df8b46

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

.github/workflows/test_full.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Install core
2424
run: pip install "Django${{ matrix.django-version }}" pydantic
2525
- name: Install tests
26-
run: pip install pytest pytest-asyncio pytest-django injector>=0.19.0 django-ninja asgiref contextlib2
26+
run: pip install pytest pytest-asyncio pytest-django injector>=0.19.0 django-ninja asgiref contextlib2 ninja-schema==0.13.4
2727
- name: Test
2828
run: pytest
2929
codestyle:

ninja_extra/controllers/model/builder.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
from ninja.orm.fields import TYPES
44
from ninja.params import Body, Path
5-
from ninja_schema.errors import ConfigError
6-
from ninja_schema.orm.factory import SchemaFactory
7-
from ninja_schema.orm.model_schema import ModelSchemaConfig, ModelSchemaConfigAdapter
85

96
from ninja_extra.constants import ROUTE_FUNCTION
107

@@ -14,6 +11,17 @@
1411
from ..route import route
1512
from .schemas import ModelConfig
1613

14+
try:
15+
from ninja_schema.errors import ConfigError
16+
from ninja_schema.orm.factory import SchemaFactory
17+
from ninja_schema.orm.model_schema import (
18+
ModelSchemaConfig,
19+
ModelSchemaConfigAdapter,
20+
)
21+
except Exception: # pragma: no cover
22+
ConfigError = ModelSchemaConfig = ModelSchemaConfigAdapter = SchemaFactory = None
23+
24+
1725
if t.TYPE_CHECKING:
1826
from ..base import APIController, ModelControllerBase
1927

@@ -48,6 +56,11 @@ def __init__(
4856
self.generate_all_schema()
4957

5058
def generate_all_schema(self) -> None:
59+
if not ModelSchemaConfig: # pragma: no cover
60+
raise RuntimeError(
61+
"ninja-schema package is required for ModelControllerSchema generation.\n pip install ninja-schema"
62+
)
63+
5164
model_config = ModelSchemaConfig(
5265
"dummy",
5366
ModelSchemaConfigAdapter(

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ requires = [
4848
"contextlib2"
4949
]
5050
description-file = "README.md"
51-
requires-python = ">=3.6"
51+
requires-python = ">=3.7"
5252

5353

5454
[tool.flit.metadata.urls]
@@ -64,6 +64,7 @@ test = [
6464
"ruff ==0.0.275",
6565
"black == 23.7.0",
6666
"injector >= 0.19.0",
67+
"ninja-schema>=0.13.4",
6768
"django-stubs",
6869
]
6970
doc = [

0 commit comments

Comments
 (0)