| 469 | |
| 470 | |
| 471 | class ArrayField(Field): |
| 472 | def __init__(self, itemtype, dims, path, description, added, deprecated): |
| 473 | Field.__init__(self, path, description, added=added, deprecated=deprecated) |
| 474 | self.itemtype = itemtype |
| 475 | self.dims = dims |
| 476 | self.path = path |
| 477 | |
| 478 | @classmethod |
| 479 | def from_js(cls, path, js): |
| 480 | # Determine how nested we are |
| 481 | dims = 1 |
| 482 | child_js = js["items"] |
| 483 | while child_js.get("type", None) == "array": |
| 484 | dims += 1 |
| 485 | child_js = child_js["items"] |
| 486 | |
| 487 | path += "[]" * dims |
| 488 | if 'oneOf' in child_js: |
| 489 | assert('type' not in child_js) |
| 490 | itemtype = UnionField.from_js(child_js, path) |
| 491 | |
| 492 | elif child_js["type"] == "object": |
| 493 | itemtype = CompositeField.from_js(child_js, path) |
| 494 | |
| 495 | elif child_js["type"] == "string" and "enum" in child_js: |
| 496 | itemtype = EnumField.from_js(child_js, path) |
| 497 | |
| 498 | elif child_js["type"] in PrimitiveField.types: |
| 499 | itemtype = PrimitiveField( |
| 500 | child_js["type"], |
| 501 | path, |
| 502 | child_js.get("description", ""), |
| 503 | added=child_js.get("added", None), |
| 504 | deprecated=child_js.get("deprecated", None), |
| 505 | ) |
| 506 | |
| 507 | logger.debug(f"Array path={path} dims={dims}, type={itemtype}") |
| 508 | return ArrayField( |
| 509 | itemtype, dims=dims, path=path, description=js.get("description", ""), added=js.get('added', None), deprecated=js.get('deprecated', None) |
| 510 | ) |
| 511 | |
| 512 | |
| 513 | class Command: |