Closed jacksmith15 closed 4 years ago
Auto-naming of schemas means that all schemas declared in an array are given the name Items. This naturally leads to conflicts when declaring the classes.
Items
Generate models for the following schema:
title: Autoname type: object description: Test schema for checking auto-naming logic for anonymous schemas. required: - list_of_strings - list_of_integers properties: list_of_integers: items: properties: integer_property: type: integer type: object type: array list_of_strings: items: properties: string_property: type: string type: object type: array
Three models are generated, one for the outer schema, and one for each schema with the lists.
Only two schemas are generated. The schema for the integer wrapping object is overwritten.
from typing import ClassVar, List, Union from attr import attrs, attrib from statham import converters as con, validators as val from statham.validators import NotPassed @attrs(kw_only=True) class Items: """items""" _required: ClassVar[List[str]] = [] string_property: Union[str, NotPassed] = attrib( validator=[ val.instance_of(str), ], default=NotPassed(), ) @attrs(kw_only=True) class Autoname: """Test schema for checking auto-naming logic for anonymous schemas.""" _required: ClassVar[List[str]] = ['list_of_strings', 'list_of_integers'] list_of_strings: List[Union[Items, NotPassed]] = attrib( validator=[ val.instance_of(list), ], converter=con.map_instantiate(Items), # type: ignore ) list_of_integers: List[Union[Items, NotPassed]] = attrib( validator=[ val.instance_of(list), ], converter=con.map_instantiate(Items), # type: ignore )
Background
Auto-naming of schemas means that all schemas declared in an array are given the name
Items
. This naturally leads to conflicts when declaring the classes.Steps to reproduce
Generate models for the following schema:
Expected outcome
Three models are generated, one for the outer schema, and one for each schema with the lists.
Actual outcome
Only two schemas are generated. The schema for the integer wrapping object is overwritten.
Full output