Skip to content

Commit

Permalink
Add schema mode settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Eittipat committed Apr 8, 2024
1 parent 8e065cc commit cc7b0de
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ninja/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Settings(BaseModel):
NINJA_SCHEMA_GENERATOR_CLASS (str):
The schema generation class to use. Defaults to
`ninja.schema.NinjaGenerateJsonSchema`.
NINJA_SCHEMA_MODE (str):
The schema mode to use. Defaults to `serialization`.
"""

PAGINATION_CLASS: str = Field(
Expand All @@ -31,6 +33,9 @@ class Settings(BaseModel):
SCHEMA_GENERATOR_CLASS: str = Field(
"ninja.schema.NinjaGenerateJsonSchema", alias="NINJA_SCHEMA_GENERATOR_CLASS"
)
SCHEMA_MODE: str = Field(
"serialization", alias="NINJA_SCHEMA_MODE"
)

class Config:
from_attributes = True
Expand Down
2 changes: 2 additions & 0 deletions ninja/openapi/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def _extract_parameters(self, model: TModel) -> List[DictStrAny]:
schema = model.model_json_schema(
ref_template=REF_TEMPLATE,
schema_generator=import_string(settings.SCHEMA_GENERATOR_CLASS),
mode=settings.SCHEMA_MODE
)

required = set(schema.get("required", []))
Expand Down Expand Up @@ -217,6 +218,7 @@ def _create_schema_from_model(
ref_template=REF_TEMPLATE,
by_alias=by_alias,
schema_generator=import_string(settings.SCHEMA_GENERATOR_CLASS),
mode=settings.SCHEMA_MODE
).copy()

# move Schemas from definitions
Expand Down

0 comments on commit cc7b0de

Please sign in to comment.