(schema: Schema, cmd: dict)
| 789 | |
| 790 | |
| 791 | def build_command(schema: Schema, cmd: dict) -> CommandIR: |
| 792 | params = schema.params_for(cmd.get("params")) |
| 793 | if cmd.get("params") and params is None: |
| 794 | raise ValueError(f"command {cmd['method']} has params that cannot be expressed as a typed object") |
| 795 | params_ref = (cmd.get("params") or {}).get("ref") |
| 796 | kind = schema.type_kind(params_ref) |
| 797 | params_class = type_class_name(params_ref) if params and kind in _PARAMS_CLASS_KINDS else None |
| 798 | result_ref = (cmd.get("result") or {}).get("ref") |
| 799 | result_name = schema.structured_ref(result_ref) if result_ref else None |
| 800 | _guard_same_domain(cmd["domain"], params_ref if params_class else None, result_name, cmd["method"]) |
| 801 | result_class = type_class_name(result_name) if result_name else None |
| 802 | if result_name and schema.type_kind(result_name) == "union": |
| 803 | result_type = value_alias(result_name) |
| 804 | elif result_class: |
| 805 | result_type = result_class |
| 806 | else: |
| 807 | result_type = "Any" |
| 808 | return CommandIR( |
| 809 | wire=cmd["method"], |
| 810 | method=safe_name(camel_to_snake(cmd["name"])), |
| 811 | params=params or [], |
| 812 | params_class=params_class, |
| 813 | union_params=(kind == "union"), |
| 814 | result_class=result_class, |
| 815 | result_type=result_type, |
| 816 | spec_href=cmd.get("specHref"), |
| 817 | ) |
| 818 | |
| 819 | |
| 820 | def build_event(schema: Schema, event: dict) -> EventIR: |
no test coverage detected