json_schemas_map: dict[tuple[JsonSchemaKeyT, JsonSchemaMode], DefsRef] = {}
for key, mode, schema in inputs:
self.mode = mode
+ self.skip_null_schema = isinstance(key, ModelField) and isinstance(
+ key.field_info, Param
+ )
json_schema = self.generate_inner(schema)
json_schemas_map[(key, mode)] = definitions_remapping.remap_json_schema(
json_schema
from typing import Optional
import pytest
-from dirty_equals import IsDict
+from dirty_equals import HasRepr, IsDict
from fastapi import Depends, FastAPI
from fastapi.exceptions import ResponseValidationError
from fastapi.testclient import TestClient
"loc": ("response", "name"),
"msg": "Value error, name must end in A",
"input": "modelX",
- "ctx": {"error": "name must end in A"},
+ "ctx": {"error": HasRepr("ValueError('name must end in A')")},
"url": match_pydantic_error_url("value_error"),
}
)
"loc": ["body", 0, "age"],
"msg": "Input should be greater than 0",
"input": -1.0,
- "ctx": {"gt": 0.0},
+ "ctx": {"gt": "0"},
"url": match_pydantic_error_url("greater_than"),
}
]
"input": {"age": "five"},
"url": match_pydantic_error_url("missing"),
},
+ {
+ "ctx": {"class": "Decimal"},
+ "input": "five",
+ "loc": ["body", 0, "age", "is-instance[Decimal]"],
+ "msg": "Input should be an instance of Decimal",
+ "type": "is_instance_of",
+ "url": match_pydantic_error_url("is_instance_of"),
+ },
{
"type": "decimal_parsing",
- "loc": ["body", 0, "age"],
+ "loc": [
+ "body",
+ 0,
+ "age",
+ "function-after[to_decimal(), union[float,int,constrained-str]]",
+ ],
"msg": "Input should be a valid decimal",
"input": "five",
},
"input": {"age": "six"},
"url": match_pydantic_error_url("missing"),
},
+ {
+ "ctx": {"class": "Decimal"},
+ "input": "six",
+ "loc": ["body", 1, "age", "is-instance[Decimal]"],
+ "msg": "Input should be an instance of Decimal",
+ "type": "is_instance_of",
+ "url": match_pydantic_error_url("is_instance_of"),
+ },
{
"type": "decimal_parsing",
- "loc": ["body", 1, "age"],
+ "loc": [
+ "body",
+ 1,
+ "age",
+ "function-after[to_decimal(), union[float,int,constrained-str]]",
+ ],
"msg": "Input should be a valid decimal",
"input": "six",
},