Feature/oneof unique subtypes naming #58

Merged
HideyoshiNakazone merged 2 commits from feature/oneof-unique-subtypes-naming into main 2025-11-24 01:11:01 +00:00
2 changed files with 13 additions and 13 deletions
Showing only changes of commit f15913c58e - Show all commits

View File

@@ -30,8 +30,10 @@ class AnyOfTypeParser(GenericTypeParser):
sub_properties = properties["anyOf"] sub_properties = properties["anyOf"]
sub_types = [ sub_types = [
GenericTypeParser.type_from_properties(name, subProperty, **kwargs) GenericTypeParser.type_from_properties(
for subProperty in sub_properties f"{name}_sub{i}", subProperty, **kwargs
)
for i, subProperty in enumerate(sub_properties)
] ]
if not kwargs.get("required", False): if not kwargs.get("required", False):

View File

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