[python] Fixes additional_properties_type for models (#8802)

* Fixes additionalProperties values for models, updates docs, adds tag test of it, fixes frit and gmfruit tests

* Moves this.setDisallowAdditionalPropertiesIfNotPresent higher

* Makes setting additional_properties_model_instances contingent on the presence of addprosp in schema, updates sample spec composed schemas to remove addprops False form two

* Fixes oneOf anyOf allOf instantiation logic

* Removes Address from Cat definition

* Adds required vars for apple and banana, removes required vars from composed schema init sig

* Updates composed schema vars to be set on self and all composed instances

* Removes get_unused_args, get_var_name_to_model_instances, and get_additional_properties_model_instances

* Fixes fruit + deserilization tests, creates ComposedSchemaWithPropsAndNoAddProps

* Fixes FruitReq tests

* Fixes GmFruit tests

* Fixes discard_unknown_keys tests

* Samples updated

* Removes additionalproperties False in Child

* Samples updated

* Improves handling of v2 and v3 specs for isFreeFormObject, v2 sample spec updated with link to bug

* Adds cli option disallowAdditionalPropertiesIfNotPresent to python

* Adds getAdditionalProperties method so the value for addProps will be correct

* Reverts file

* Reverts file

* Updates python doc

* Reverted anytype_3 definition

* Updates test_deserialize_lizard

* Updates test_deserialize_dict_str_dog

* Updates testDog

* Updates testChild

* Adds v2 python_composition sample

* Adds needed files for python testing

* Adds existing tests into the new python sample

* Fixes test_dog

* Removes addProps false form Dog

* Fixes testChild

* Updates how additionalProperties are set

* Fixes empty_map type

* Type generation fixed for v2 and v3 specs

* Refactors getTypeString, updates artifactids in pom.xml files

* Adds new python sample to CI testing I think

* Fixes artifactId collision, regenrates docs
This commit is contained in:
Justin Black
2021-03-31 08:48:12 -07:00
committed by GitHub
parent 3973d4c831
commit 6cc270633b
539 changed files with 32476 additions and 1617 deletions

View File

@@ -0,0 +1,45 @@
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501
The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech
"""
import sys
import unittest
import petstore_api
from petstore_api.model.tag import Tag
globals()['Tag'] = Tag
from petstore_api.model.composed_schema_with_props_and_no_add_props import ComposedSchemaWithPropsAndNoAddProps
class TestComposedSchemaWithPropsAndNoAddProps(unittest.TestCase):
"""ComposedSchemaWithPropsAndNoAddProps unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def testComposedSchemaWithPropsAndNoAddProps(self):
"""Test ComposedSchemaWithPropsAndNoAddProps"""
inst = ComposedSchemaWithPropsAndNoAddProps(color='red')
# ComposedSchemaWithPropsAndNoAddProps should only allow in the color property
# once https://github.com/OpenAPITools/openapi-generator/pull/8816 lands
# this will no longer work
# TODO update the test then
inst = ComposedSchemaWithPropsAndNoAddProps(color='red', id=1, name='foo')
with self.assertRaises(petstore_api.ApiAttributeError):
inst = ComposedSchemaWithPropsAndNoAddProps(color='red', id=1, name='foo', additional=5)
if __name__ == '__main__':
unittest.main()

View File

@@ -118,12 +118,7 @@ class DeserializationTests(unittest.TestCase):
)
assert isinstance(inst, apple.Apple)
inst = apple.Apple(
origin="cHiLe"
)
assert isinstance(inst, apple.Apple)
# Test with invalid regex pattern.
# Test with invalid regex pattern in cultivar
err_msg = ("Invalid value for `{}`, must match regular expression `{}`$")
with self.assertRaisesRegex(
petstore_api.ApiValueError,
@@ -133,12 +128,14 @@ class DeserializationTests(unittest.TestCase):
cultivar="!@#%@$#Akane"
)
# Test with invalid regex pattern in origin
err_msg = ("Invalid value for `{}`, must match regular expression `{}` with flags")
with self.assertRaisesRegex(
petstore_api.ApiValueError,
err_msg.format("origin", "[^`]*")
):
inst = apple.Apple(
cultivar="Akane",
origin="!@#%@$#Chile"
)

View File

@@ -16,7 +16,7 @@ import re
import unittest
import petstore_api
from petstore_api.model import cat, dog, isosceles_triangle, banana_req
from petstore_api.model import cat, dog, isosceles_triangle, banana_req, fruit_req
from petstore_api import Configuration, signing
from petstore_api.model_utils import (
@@ -54,17 +54,17 @@ class DiscardUnknownPropertiesTests(unittest.TestCase):
'Exception message: {0}'.format(str(cm.exception)))
def test_deserialize_isosceles_triangle_do_not_discard_unknown_properties(self):
def test_deserialize_fruit_req_do_not_discard_unknown_properties(self):
"""
deserialize IsoscelesTriangle with unknown properties.
deserialize FruitReq with unknown properties.
Strict validation is enabled.
Composed schema scenario.
"""
config = Configuration(discard_unknown_keys=False)
api_client = petstore_api.ApiClient(config)
data = {
'shape_type': 'Triangle',
'triangle_type': 'EquilateralTriangle',
'lengthCm': 21.3,
'sweet': False,
# Below is an unknown property not explicitly declared in the OpenAPI document.
# It should not be in the payload because additional properties (undeclared) are
# not allowed in the schema (additionalProperties: false).
@@ -74,10 +74,29 @@ class DiscardUnknownPropertiesTests(unittest.TestCase):
# Deserializing with strict validation raises an exception because the 'unknown_property'
# is undeclared.
with self.assertRaises(petstore_api.ApiValueError) as cm:
deserialized = api_client.deserialize(response, ((isosceles_triangle.IsoscelesTriangle),), True)
self.assertTrue(re.match('.*Not all inputs were used.*unknown_property.*', str(cm.exception)),
'Exception message: {0}'.format(str(cm.exception)))
with self.assertRaisesRegex(petstore_api.ApiValueError, "Invalid inputs given to generate an instance of FruitReq. None of the oneOf schemas matched the input data."):
deserialized = api_client.deserialize(response, ((fruit_req.FruitReq),), True)
def test_deserialize_fruit_req_discard_unknown_properties(self):
"""
deserialize FruitReq with unknown properties.
Strict validation is enabled.
Composed schema scenario.
"""
config = Configuration(discard_unknown_keys=True)
api_client = petstore_api.ApiClient(config)
data = {
'lengthCm': 21.3,
'sweet': False,
# Below is an unknown property not explicitly declared in the OpenAPI document.
# It should not be in the payload because additional properties (undeclared) are
# not allowed in BananaReq
'unknown_property': 'a-value'
}
response = MockResponse(data=json.dumps(data))
deserialized = api_client.deserialize(response, ((fruit_req.FruitReq),), True)
self.assertNotIn("unknown_property", deserialized.to_dict().keys())
def test_deserialize_banana_req_discard_unknown_properties(self):
@@ -145,13 +164,10 @@ class DiscardUnknownPropertiesTests(unittest.TestCase):
# Below are additional (undeclared) properties.
"my_additional_property": 123,
}
# The 'my_additional_property' is undeclared, but 'Cat' has a 'Address' type through
# the allOf: [ $ref: '#/components/schemas/Address' ].
# The 'my_additional_property' is undeclared
response = MockResponse(data=json.dumps(data))
deserialized = api_client.deserialize(response, ((cat.Cat),), True)
self.assertTrue(isinstance(deserialized, cat.Cat))
# Check the 'unknown_property' and 'more-unknown' properties are not present in the
# output.
self.assertIn("declawed", deserialized.to_dict().keys())
# Check the 'my_additional_property' is present
self.assertIn("my_additional_property", deserialized.to_dict().keys())

View File

@@ -14,56 +14,70 @@ import sys
import unittest
import petstore_api
try:
from petstore_api.model import apple
except ImportError:
apple = sys.modules[
'petstore_api.model.apple']
try:
from petstore_api.model import banana
except ImportError:
banana = sys.modules[
'petstore_api.model.banana']
from petstore_api.model import apple
from petstore_api.model import banana
from petstore_api.model.fruit import Fruit
class TestFruit(unittest.TestCase):
"""Fruit unit test stubs"""
length_cm = 20.3
color = 'yellow'
def setUp(self):
pass
def tearDown(self):
pass
def testFruit(self):
"""Test Fruit"""
def test_fruit_with_additional_props(self):
# including extra parameters works because the oneOf models include additionalProperties
some_value = 'some_value'
some_fruit = Fruit(
color=self.color,
length_cm=self.length_cm,
unknown_property=some_value
)
assert some_fruit['unknown_property'] == some_value
def test_fruit_assigning_additional_props_in_client(self):
# setting a value that doesn't exist works because additional_properties_type allows any type
other_fruit = Fruit(length_cm=self.length_cm, color=self.color)
blah = 'blah'
other_fruit['a'] = blah
assert other_fruit.a == blah
# with setattr
setattr(other_fruit, 'b', blah)
assert other_fruit.b == blah
# make an instance of Fruit, a composed schema oneOf model
# banana test
length_cm = 20.3
color = 'yellow'
fruit = Fruit(length_cm=length_cm, color=color)
# check its properties
self.assertEqual(fruit.length_cm, length_cm)
self.assertEqual(fruit['length_cm'], length_cm)
self.assertEqual(fruit.get('length_cm'), length_cm)
self.assertEqual(getattr(fruit, 'length_cm'), length_cm)
self.assertEqual(fruit.color, color)
self.assertEqual(fruit['color'], color)
self.assertEqual(getattr(fruit, 'color'), color)
# check the dict representation
self.assertEqual(
fruit.to_dict(),
other_fruit.to_dict(),
{
'length_cm': length_cm,
'color': color
'a': 'blah',
'b': 'blah',
'length_cm': self.length_cm,
'color': self.color
}
)
# setting a value that doesn't exist raises an exception
def test_fruit_access_errors(self):
fruit = Fruit(length_cm=self.length_cm, color=self.color)
# getting a value that doesn't exist raises an exception
# with a key
with self.assertRaises(AttributeError):
fruit['invalid_variable'] = 'some value'
invalid_variable = fruit['cultivar']
# Per Python doc, if the named attribute does not exist,
# default is returned if provided, otherwise AttributeError is raised.
with self.assertRaises(AttributeError):
getattr(fruit, 'cultivar')
def test_fruit_attribute_access(self):
fruit = Fruit(length_cm=self.length_cm, color=self.color)
# Assert that we can call the builtin hasattr() function.
# hasattr should return False for non-existent attribute.
@@ -74,14 +88,6 @@ class TestFruit(unittest.TestCase):
# hasattr should return True for existent attribute.
self.assertTrue(hasattr(fruit, 'color'))
# with setattr
with self.assertRaises(AttributeError):
setattr(fruit, 'invalid_variable', 'some value')
# getting a value that doesn't exist raises an exception
# with a key
with self.assertRaises(AttributeError):
invalid_variable = fruit['cultivar']
# with getattr
# Per Python doc, if the named attribute does not exist,
# default is returned if provided.
@@ -89,10 +95,28 @@ class TestFruit(unittest.TestCase):
self.assertEqual(fruit.get('cultivar'), None)
self.assertEqual(fruit.get('cultivar', 'some value'), 'some value')
# Per Python doc, if the named attribute does not exist,
# default is returned if provided, otherwise AttributeError is raised.
with self.assertRaises(AttributeError):
getattr(fruit, 'cultivar')
def test_banana_fruit(self):
"""Test Fruit"""
# make an instance of Fruit, a composed schema oneOf model
# banana test
fruit = Fruit(length_cm=self.length_cm, color=self.color)
# check its properties
self.assertEqual(fruit.length_cm, self.length_cm)
self.assertEqual(fruit['length_cm'], self.length_cm)
self.assertEqual(fruit.get('length_cm'), self.length_cm)
self.assertEqual(getattr(fruit, 'length_cm'), self.length_cm)
self.assertEqual(fruit.color, self.color)
self.assertEqual(fruit['color'], self.color)
self.assertEqual(getattr(fruit, 'color'), self.color)
# check the dict representation
self.assertEqual(
fruit.to_dict(),
{
'length_cm': self.length_cm,
'color': self.color
}
)
# make sure that the ModelComposed class properties are correct
# model._composed_schemas stores the anyOf/allOf/oneOf info
@@ -109,6 +133,7 @@ class TestFruit(unittest.TestCase):
)
# model._composed_instances is a list of the instances that were
# made from the anyOf/allOf/OneOf classes in model._composed_schemas
self.assertEqual(len(fruit._composed_instances), 1)
for composed_instance in fruit._composed_instances:
if composed_instance.__class__ == banana.Banana:
banana_instance = composed_instance
@@ -118,19 +143,16 @@ class TestFruit(unittest.TestCase):
)
# model._var_name_to_model_instances maps the variable name to the
# model instances which store that variable
print(fruit._var_name_to_model_instances)
self.assertEqual(
fruit._var_name_to_model_instances,
{
'color': [fruit],
'color': [fruit, banana_instance],
'length_cm': [fruit, banana_instance],
'cultivar': [fruit],
'origin': [fruit],
}
)
# model._additional_properties_model_instances stores a list of
# models which have the property additional_properties_type != None
self.assertEqual(
fruit._additional_properties_model_instances, []
fruit._additional_properties_model_instances, [fruit]
)
# if we modify one of the properties owned by multiple
@@ -140,21 +162,15 @@ class TestFruit(unittest.TestCase):
with self.assertRaises(petstore_api.ApiValueError):
some_length_cm = fruit.length_cm
# including extra parameters raises an exception
with self.assertRaises(petstore_api.ApiValueError):
fruit = Fruit(
color=color,
length_cm=length_cm,
unknown_property='some value'
)
# including input parameters for two oneOf instances raise an exception
with self.assertRaises(petstore_api.ApiValueError):
fruit = Fruit(
length_cm=length_cm,
length_cm=self.length_cm,
cultivar='granny smith'
)
def test_apple_fruit(self):
# make an instance of Fruit, a composed schema oneOf model
# apple test
color = 'red'
@@ -190,19 +206,15 @@ class TestFruit(unittest.TestCase):
self.assertEqual(
fruit._var_name_to_model_instances,
{
'color': [fruit],
'length_cm': [fruit],
'color': [fruit, apple_instance],
'cultivar': [fruit, apple_instance],
'origin': [fruit, apple_instance],
}
)
# model._additional_properties_model_instances stores a list of
# models which have the property additional_properties_type != None
self.assertEqual(
fruit._additional_properties_model_instances, []
fruit._additional_properties_model_instances, [fruit]
)
def testFruitNullValue(self):
def test_null_fruit(self):
# Since 'apple' is nullable, validate we can create an apple with the 'null' value.
fruit = apple.Apple(None)
self.assertIsNone(fruit)
@@ -220,5 +232,16 @@ class TestFruit(unittest.TestCase):
fruit = Fruit(apple.Apple(None))
self.assertIsNone(fruit)
def test_fruit_with_invalid_input_type(self):
"""
color must be a str, color's str type is only defined at the Fruit level
Banana + Apple would allow color to be assigned with any type of value
"""
invalid_value = 1
with self.assertRaises(petstore_api.ApiTypeError):
fruit = Fruit(color=invalid_value, length_cm=self.length_cm)
if __name__ == '__main__':
unittest.main()

View File

@@ -14,21 +14,14 @@ import sys
import unittest
import petstore_api
try:
from petstore_api.model import apple_req
except ImportError:
apple_req = sys.modules[
'petstore_api.model.apple_req']
try:
from petstore_api.model import banana_req
except ImportError:
banana_req = sys.modules[
'petstore_api.model.banana_req']
from petstore_api.model import apple_req
from petstore_api.model import banana_req
from petstore_api.model.fruit_req import FruitReq
class TestFruitReq(unittest.TestCase):
"""FruitReq unit test stubs"""
length_cm = 20.3
def setUp(self):
pass
@@ -36,24 +29,9 @@ class TestFruitReq(unittest.TestCase):
def tearDown(self):
pass
def testFruitReq(self):
"""Test FruitReq"""
def test_fruit_access_errors(self):
fruit = FruitReq(length_cm=self.length_cm)
# make an instance of Fruit, a composed schema oneOf model
# banana test
length_cm = 20.3
fruit = FruitReq(length_cm=length_cm)
# check its properties
self.assertEqual(fruit.length_cm, length_cm)
self.assertEqual(fruit['length_cm'], length_cm)
self.assertEqual(getattr(fruit, 'length_cm'), length_cm)
# check the dict representation
self.assertEqual(
fruit.to_dict(),
{
'length_cm': length_cm,
}
)
# setting a value that doesn't exist raises an exception
# with a key
with self.assertRaises(AttributeError):
@@ -66,12 +44,31 @@ class TestFruitReq(unittest.TestCase):
# with a key
with self.assertRaises(AttributeError):
invalid_variable = fruit['cultivar']
# with getattr
self.assertEqual(getattr(fruit, 'cultivar', 'some value'), 'some value')
with self.assertRaises(AttributeError):
getattr(fruit, 'cultivar')
def test_FruitReq_banana(self):
"""Test FruitReq"""
# make an instance of Fruit, a composed schema oneOf model
# banana test
fruit = FruitReq(length_cm=self.length_cm)
# check its properties
self.assertEqual(fruit.length_cm, self.length_cm)
self.assertEqual(fruit['length_cm'], self.length_cm)
self.assertEqual(getattr(fruit, 'length_cm'), self.length_cm)
# check the dict representation
self.assertEqual(
fruit.to_dict(),
{
'length_cm': self.length_cm,
}
)
# with getattr
self.assertEqual(getattr(fruit, 'cultivar', 'some value'), 'some value')
# make sure that the ModelComposed class properties are correct
# model._composed_schemas stores the anyOf/allOf/oneOf info
self.assertEqual(
@@ -101,15 +98,10 @@ class TestFruitReq(unittest.TestCase):
fruit._var_name_to_model_instances,
{
'length_cm': [fruit, banana_instance],
'cultivar': [fruit],
'mealy': [fruit],
'sweet': [fruit, banana_instance],
}
)
# model._additional_properties_model_instances stores a list of
# models which have the property additional_properties_type != None
self.assertEqual(
fruit._additional_properties_model_instances, []
fruit._additional_properties_model_instances, [fruit]
)
# if we modify one of the properties owned by multiple
@@ -119,21 +111,24 @@ class TestFruitReq(unittest.TestCase):
with self.assertRaises(petstore_api.ApiValueError):
some_length_cm = fruit.length_cm
def test_invalid_inputs(self):
# including extra parameters raises an exception
with self.assertRaises(petstore_api.ApiValueError):
fruit = FruitReq(
length_cm=length_cm,
length_cm=self.length_cm,
unknown_property='some value'
)
# including input parameters for two oneOf instances raise an exception
with self.assertRaises(petstore_api.ApiValueError):
fruit = FruitReq(
length_cm=length_cm,
length_cm=self.length_cm,
cultivar='granny smith'
)
# make an instance of Fruit, a composed schema oneOf model
def test_FruitReq_apple(self):
"""Test FruitReq"""
# apple test
cultivar = 'golden delicious'
fruit = FruitReq(cultivar=cultivar)
@@ -163,21 +158,18 @@ class TestFruitReq(unittest.TestCase):
self.assertEqual(
fruit._var_name_to_model_instances,
{
'length_cm': [fruit],
'cultivar': [fruit, apple_instance],
'mealy': [fruit, apple_instance],
'sweet': [fruit],
}
)
# model._additional_properties_model_instances stores a list of
# models which have the property additional_properties_type != None
self.assertEqual(
fruit._additional_properties_model_instances, []
fruit._additional_properties_model_instances, [fruit]
)
def test_null_fruit(self):
# we can pass in None
fruit = FruitReq(None)
assert fruit is None
if __name__ == '__main__':
unittest.main()

View File

@@ -14,21 +14,15 @@ import sys
import unittest
import petstore_api
try:
from petstore_api.model import apple
except ImportError:
apple = sys.modules[
'petstore_api.model.apple']
try:
from petstore_api.model import banana
except ImportError:
banana = sys.modules[
'petstore_api.model.banana']
from petstore_api.model import apple
from petstore_api.model import banana
from petstore_api.model.gm_fruit import GmFruit
class TestGmFruit(unittest.TestCase):
"""GmFruit unit test stubs"""
length_cm = 20.3
color = 'yellow'
def setUp(self):
pass
@@ -36,36 +30,48 @@ class TestGmFruit(unittest.TestCase):
def tearDown(self):
pass
def testGmFruit(self):
def test_set_addprop_attributes(self):
# setting a value that doesn't exist works because additional_properties_type allows any type
other_fruit = GmFruit(length_cm=self.length_cm, color=self.color)
blah = 'blah'
other_fruit['a'] = blah
assert other_fruit.a == blah
# with setattr
setattr(other_fruit, 'b', blah)
assert other_fruit.b == blah
self.assertEqual(
other_fruit.to_dict(),
{
'a': 'blah',
'b': 'blah',
'length_cm': self.length_cm,
'color': self.color
}
)
def test_banana_fruit(self):
"""Test GmFruit"""
# make an instance of GmFruit, a composed schema anyOf model
# banana test
length_cm = 20.3
color = 'yellow'
fruit = GmFruit(length_cm=length_cm, color=color)
fruit = GmFruit(length_cm=self.length_cm, color=self.color)
# check its properties
self.assertEqual(fruit.length_cm, length_cm)
self.assertEqual(fruit['length_cm'], length_cm)
self.assertEqual(getattr(fruit, 'length_cm'), length_cm)
self.assertEqual(fruit.color, color)
self.assertEqual(fruit['color'], color)
self.assertEqual(getattr(fruit, 'color'), color)
self.assertEqual(fruit.length_cm, self.length_cm)
self.assertEqual(fruit['length_cm'], self.length_cm)
self.assertEqual(getattr(fruit, 'length_cm'), self.length_cm)
self.assertEqual(fruit.color, self.color)
self.assertEqual(fruit['color'], self.color)
self.assertEqual(getattr(fruit, 'color'), self.color)
# check the dict representation
self.assertEqual(
fruit.to_dict(),
{
'length_cm': length_cm,
'color': color
'length_cm': self.length_cm,
'color': self.color
}
)
# setting a value that doesn't exist raises an exception
# with a key
with self.assertRaises(AttributeError):
fruit['invalid_variable'] = 'some value'
# with setattr
with self.assertRaises(AttributeError):
setattr(fruit, 'invalid_variable', 'some value')
# getting a value that doesn't exist raises an exception
# with a key
@@ -104,40 +110,22 @@ class TestGmFruit(unittest.TestCase):
self.assertEqual(
fruit._var_name_to_model_instances,
{
'color': [fruit],
'color': [fruit, banana_instance],
'length_cm': [fruit, banana_instance],
'cultivar': [fruit],
'origin': [fruit],
}
)
# model._additional_properties_model_instances stores a list of
# models which have the property additional_properties_type != None
self.assertEqual(
fruit._additional_properties_model_instances, []
fruit._additional_properties_model_instances, [fruit]
)
# if we modify one of the properties owned by multiple
# model_instances we get an exception when we try to access that
# property because the retrieved values are not all the same
banana_instance.length_cm = 4.56
with self.assertRaises(petstore_api.ApiValueError):
some_length_cm = fruit.length_cm
# including extra parameters raises an exception
with self.assertRaises(petstore_api.ApiValueError):
fruit = GmFruit(
color=color,
length_cm=length_cm,
unknown_property='some value'
)
def test_combo_fruit(self):
# including input parameters for both anyOf instances works
cultivar = 'banaple'
color = 'orange'
fruit = GmFruit(
color=color,
cultivar=cultivar,
length_cm=length_cm
length_cm=self.length_cm
)
self.assertEqual(fruit.color, color)
self.assertEqual(fruit['color'], color)
@@ -145,9 +133,9 @@ class TestGmFruit(unittest.TestCase):
self.assertEqual(fruit.cultivar, cultivar)
self.assertEqual(fruit['cultivar'], cultivar)
self.assertEqual(getattr(fruit, 'cultivar'), cultivar)
self.assertEqual(fruit.length_cm, length_cm)
self.assertEqual(fruit['length_cm'], length_cm)
self.assertEqual(getattr(fruit, 'length_cm'), length_cm)
self.assertEqual(fruit.length_cm, self.length_cm)
self.assertEqual(fruit['length_cm'], self.length_cm)
self.assertEqual(getattr(fruit, 'length_cm'), self.length_cm)
# model._composed_instances is a list of the instances that were
# made from the anyOf/allOf/OneOf classes in model._composed_schemas
@@ -165,14 +153,16 @@ class TestGmFruit(unittest.TestCase):
self.assertEqual(
fruit._var_name_to_model_instances,
{
'color': [fruit],
'length_cm': [fruit, banana_instance],
'cultivar': [fruit, apple_instance],
'origin': [fruit, apple_instance],
'color': [fruit, apple_instance, banana_instance],
'length_cm': [fruit, apple_instance, banana_instance],
'cultivar': [fruit, apple_instance, banana_instance],
}
)
self.assertEqual(
fruit._additional_properties_model_instances, [fruit]
)
# make an instance of GmFruit, a composed schema anyOf model
def test_apple_fruit(self):
# apple test
color = 'red'
cultivar = 'golden delicious'
@@ -214,16 +204,13 @@ class TestGmFruit(unittest.TestCase):
self.assertEqual(
fruit._var_name_to_model_instances,
{
'color': [fruit],
'length_cm': [fruit],
'color': [fruit, apple_instance],
'cultivar': [fruit, apple_instance],
'origin': [fruit, apple_instance],
}
)
# model._additional_properties_model_instances stores a list of
# models which have the property additional_properties_type != None
self.assertEqual(
fruit._additional_properties_model_instances, []
fruit._additional_properties_model_instances, [fruit]
)
if __name__ == '__main__':

View File

@@ -0,0 +1,35 @@
# coding: utf-8
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501
The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech
"""
import sys
import unittest
import petstore_api
from petstore_api.model.tag import Tag
class TestTag(unittest.TestCase):
"""Tag unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def test_can_ingest_additional_properties_in_tag(self):
t = Tag(a='abc')
assert t.a == 'abc'
if __name__ == '__main__':
unittest.main()