| 99 | ): |
| 100 | |
| 101 | class PokemonDict(BaseModel): |
| 102 | root: dict[str, Pokemon] |
| 103 | model_config = ConfigDict(from_attributes=True) |
| 104 | |
| 105 | @root_validator(pre=True) |
| 106 | @classmethod |
| 107 | def populate_root(cls, values): |
| 108 | return {'root': values} |
| 109 | |
| 110 | @model_serializer(mode='wrap') |
| 111 | def _serialize(self, handler, info): |
| 112 | data = handler(self) |
| 113 | if info.mode == 'json': |
| 114 | return data['root'] |
| 115 | else: |
| 116 | return data |
| 117 | |
| 118 | @classmethod |
| 119 | def model_modify_json_schema(cls, json_schema): |
| 120 | return json_schema['properties']['root'] |
| 121 | |
| 122 | pokemons = deprecated_from_orm(PokemonDict, {'pika': pika, 'bulbi': bulbi}) |
| 123 | assert pokemons.root == { |