feat: tests that the generated fields in the oneOf parser have unique names and applies the same logic to the anyOf parser

This commit is contained in:
2025-11-23 22:09:55 -03:00
parent f80a1bbda3
commit f15913c58e
2 changed files with 13 additions and 13 deletions

View File

@@ -3,6 +3,7 @@ from jambo.exceptions import InvalidSchemaException, UnsupportedSchemaException
from jambo.types import JSONSchema
from pydantic import AnyUrl, BaseModel, ValidationError
from typing_extensions import get_args
from ipaddress import IPv4Address, IPv6Address
from unittest import TestCase
@@ -826,15 +827,12 @@ class TestSchemaConverter(TestCase):
schema_type = SchemaConverter.build(schema)
_ = schema_type.model_validate(
{"operating_system": {"name": "Ubuntu", "version": "20.04"}}
)
# check for me that the types generated by the oneOf in the typing.Annotated have different names
operating_system_field = schema_type.model_fields["operating_system"]
_ = schema_type.model_validate(
{
"operating_system": {
"creation": {"name": "Ubuntu", "version": "20.04"},
"reinstallation": {"name": "Ubuntu", "version": "22.04"},
}
}
)
arg1, arg2 = get_args(operating_system_field.annotation)
first_type = get_args(arg1)[0]
second_type = get_args(arg2)[0]
self.assertNotEqual(first_type.__name__, second_type.__name__)