mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-21 19:07:08 +00:00
[PYTHON] generate code based on pydantic v2 (#16685)
* [python] replace validator with field_validator
* [python] replace parse_obj with model_validate
* [python] replace dict with model_dump
* [python] replace construct with model_construct
* [python] replace __fields_set__ with model_fields_set
* [python] replace __fields_set__ in the test cases with model_fields_set
* [python] replace validate_arguments with validate_call
* [python] replace max_items, min_items with max_length, min_length
* [python] replace Config class with model_config
* [python] replace allow_population_by_field_name with populate_by_name
* [python] remove {{{classname}}}_ONE_OF_SCHEMAS
* [python] update test cases
* [python] update samples
* [python] fix typos in test cases
This commit is contained in:
@@ -49,18 +49,19 @@ class ApiExceptionTests(unittest.TestCase):
|
||||
def test_required_param_validation(self):
|
||||
try:
|
||||
self.pet_api.get_pet_by_id()
|
||||
except TypeError as e:
|
||||
self.assertIn("missing 1 required positional argument: 'pet_id'", str(e))
|
||||
except ValidationError as e:
|
||||
self.assertIn("1 validation error for get_pet_by_id", str(e))
|
||||
self.assertIn("Missing required argument", str(e))
|
||||
|
||||
def test_integer_validation(self):
|
||||
try:
|
||||
self.pet_api.get_pet_by_id("123")
|
||||
except ValidationError as e:
|
||||
# 1 validation error for GetPetById
|
||||
# 1 validation error for get_pet_by_id
|
||||
# pet_id
|
||||
# Input should be a valid integer [type=int_type, input_value='123', input_type=str]
|
||||
# For further information visit https://errors.pydantic.dev/2.3/v/int_type
|
||||
self.assertIn("1 validation error for GetPetById", str(e))
|
||||
self.assertIn("1 validation error for get_pet_by_id", str(e))
|
||||
self.assertIn("Input should be a valid integer", str(e))
|
||||
|
||||
def test_string_enum_validation(self):
|
||||
|
||||
@@ -367,9 +367,9 @@ class ModelTests(unittest.TestCase):
|
||||
d4 = petstore_api.OuterObjectWithEnumProperty(value=petstore_api.OuterEnumInteger.NUMBER_1, str_value=None)
|
||||
self.assertEqual(d4.to_json(), '{"value": 1, "str_value": null}')
|
||||
d5 = petstore_api.OuterObjectWithEnumProperty(value=petstore_api.OuterEnumInteger.NUMBER_1)
|
||||
self.assertEqual(d5.__fields_set__, {'value'})
|
||||
self.assertEqual(d5.model_fields_set, {'value'})
|
||||
d5.str_value = None # set None explicitly
|
||||
self.assertEqual(d5.__fields_set__, {'value', 'str_value'})
|
||||
self.assertEqual(d5.model_fields_set, {'value', 'str_value'})
|
||||
self.assertEqual(d5.to_json(), '{"value": 1, "str_value": null}')
|
||||
|
||||
def test_valdiator(self):
|
||||
|
||||
Reference in New Issue
Block a user