forked from loafle/openapi-generator-original
fix: Annotate free-form object as dict in Python (#17082)
This commit is contained in:
@@ -8,8 +8,10 @@ import time
|
||||
import unittest
|
||||
|
||||
from pydantic import ValidationError
|
||||
import pytest
|
||||
|
||||
import petstore_api
|
||||
from petstore_api import InnerDictWithProperty
|
||||
|
||||
|
||||
class ModelTests(unittest.TestCase):
|
||||
@@ -508,6 +510,19 @@ class ModelTests(unittest.TestCase):
|
||||
self.assertFalse(b is None)
|
||||
self.assertEqual(b.optional_dict["key"].a_property["a"], "b")
|
||||
|
||||
def test_freeform_object(self):
|
||||
# Allows dict[str, Any] and is nullable
|
||||
a = InnerDictWithProperty.from_dict({"aProperty": {"a": 12}})
|
||||
a = InnerDictWithProperty.from_dict({"aProperty": None})
|
||||
|
||||
# Allows no other values
|
||||
with pytest.raises(ValidationError):
|
||||
a = InnerDictWithProperty.from_dict({"aProperty": {123: 45}})
|
||||
with pytest.raises(ValidationError):
|
||||
a = InnerDictWithProperty.from_dict({"aProperty": "abc"})
|
||||
with pytest.raises(ValidationError):
|
||||
a = InnerDictWithProperty.from_dict({"aProperty": 12})
|
||||
|
||||
def test_object_with_dict_of_dict_of_object(self):
|
||||
# for https://github.com/OpenAPITools/openapi-generator/issues/15135
|
||||
d = {"optionalDict": {"a": {"b": {"aProperty": "value"}}}}
|
||||
|
||||
Reference in New Issue
Block a user