|
7 | 7 | # Disable flake8 entirely on this file:
|
8 | 8 | # flake8: noqa
|
9 | 9 |
|
| 10 | +from __future__ import annotations |
10 | 11 | from dataclasses import dataclass
|
11 | 12 | from typing import Any, Callable, Dict, List, NoReturn, Optional, Tuple, Union
|
12 | 13 |
|
@@ -240,6 +241,40 @@ def write_nullable(x: Any) -> Any:
|
240 | 241 | from dataclasses import dataclass
|
241 | 242 |
|
242 | 243 |
|
| 244 | +@dataclass |
| 245 | +class RecursiveClass: |
| 246 | + """Original type: recursive_class = { ... }""" |
| 247 | + |
| 248 | + id: int |
| 249 | + flag: bool |
| 250 | + children: List[RecursiveClass] |
| 251 | + |
| 252 | + @classmethod |
| 253 | + def from_json(cls, x: Any) -> 'RecursiveClass': |
| 254 | + if isinstance(x, dict): |
| 255 | + return cls( |
| 256 | + id=_atd_read_int(x['id']) if 'id' in x else _atd_missing_json_field('RecursiveClass', 'id'), |
| 257 | + flag=_atd_read_bool(x['flag']) if 'flag' in x else _atd_missing_json_field('RecursiveClass', 'flag'), |
| 258 | + children=_atd_read_list(RecursiveClass.from_json)(x['children']) if 'children' in x else _atd_missing_json_field('RecursiveClass', 'children'), |
| 259 | + ) |
| 260 | + else: |
| 261 | + _atd_bad_json('RecursiveClass', x) |
| 262 | + |
| 263 | + def to_json(self) -> Any: |
| 264 | + res: Dict[str, Any] = {} |
| 265 | + res['id'] = _atd_write_int(self.id) |
| 266 | + res['flag'] = _atd_write_bool(self.flag) |
| 267 | + res['children'] = _atd_write_list((lambda x: x.to_json()))(self.children) |
| 268 | + return res |
| 269 | + |
| 270 | + @classmethod |
| 271 | + def from_json_string(cls, x: str) -> 'RecursiveClass': |
| 272 | + return cls.from_json(json.loads(x)) |
| 273 | + |
| 274 | + def to_json_string(self, **kw: Any) -> str: |
| 275 | + return json.dumps(self.to_json(), **kw) |
| 276 | + |
| 277 | + |
243 | 278 | @dataclass
|
244 | 279 | class Root_:
|
245 | 280 | """Original type: kind = [ ... | Root | ... ]"""
|
|
0 commit comments