diff --git a/ninja/conf.py b/ninja/conf.py index 0be2c47e..28791191 100644 --- a/ninja/conf.py +++ b/ninja/conf.py @@ -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( @@ -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 diff --git a/ninja/openapi/schema.py b/ninja/openapi/schema.py index 616c852a..7c98b77a 100644 --- a/ninja/openapi/schema.py +++ b/ninja/openapi/schema.py @@ -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", [])) @@ -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