|
32 | 32 |
|
33 | 33 | from __future__ import annotations |
34 | 34 |
|
| 35 | +from typing import get_args as _get_args |
| 36 | + |
35 | 37 | from adcp.types.generated_poc.bundled.protocol.get_adcp_capabilities_response import ( |
36 | 38 | A2ui, |
37 | 39 | Adcp, |
|
88 | 90 | from adcp.types.generated_poc.bundled.protocol.get_adcp_capabilities_response import ( |
89 | 91 | Account as CapabilitiesAccount, |
90 | 92 | ) |
| 93 | +from adcp.types.generated_poc.bundled.protocol.get_adcp_capabilities_response import ( |
| 94 | + Adcp as _Adcp, |
| 95 | +) |
91 | 96 |
|
92 | 97 | # ``Capabilities`` (line 580 of the generated module) is the SI-block's |
93 | 98 | # inner ``capabilities`` field type — modalities / components / commerce |
|
109 | 114 | from adcp.types.generated_poc.bundled.protocol.get_adcp_capabilities_response import ( |
110 | 115 | Creative as CapabilitiesCreative, |
111 | 116 | ) |
112 | | - |
113 | | -# ``Features2`` is the codegen name for the ``Signals.features`` type |
114 | | -# (numbered because ``Features`` already names the media_buy features |
115 | | -# block at line 142 of the generated module). Surface under a stable |
116 | | -# adopter-facing name so signals declarations read cleanly. |
117 | | -from adcp.types.generated_poc.bundled.protocol.get_adcp_capabilities_response import ( |
118 | | - Features2 as SignalsFeatures, |
119 | | -) |
120 | | - |
121 | | -# ``Idempotency`` ships as a ``oneOf`` on the wire (``IdempotencySupported`` |
122 | | -# vs ``IdempotencyUnsupported``) — the codegen names them ``Idempotency`` |
123 | | -# and ``Idempotency3`` (with the numbered variant covering the |
124 | | -# ``supported: false`` arm). Surface the union halves under stable |
125 | | -# semantic names so adopters can construct either side without remembering |
126 | | -# which numbered variant is which. |
127 | 117 | from adcp.types.generated_poc.bundled.protocol.get_adcp_capabilities_response import ( |
128 | 118 | Idempotency as IdempotencySupported, |
129 | 119 | ) |
130 | 120 | from adcp.types.generated_poc.bundled.protocol.get_adcp_capabilities_response import ( |
131 | | - Idempotency3 as IdempotencyUnsupported, |
| 121 | + MediaBuy as CapabilitiesMediaBuy, |
132 | 122 | ) |
133 | 123 | from adcp.types.generated_poc.bundled.protocol.get_adcp_capabilities_response import ( |
134 | | - MediaBuy as CapabilitiesMediaBuy, |
| 124 | + Signals as _Signals, |
135 | 125 | ) |
136 | 126 |
|
| 127 | +# ``Signals.features`` and the unsupported arm of the ``Adcp.idempotency`` |
| 128 | +# discriminated union are inline schemas the codegen materializes under |
| 129 | +# numbered class names (``Features<N>`` / ``Idempotency<N>``). Those |
| 130 | +# numbers are not stable across regens: ``datamodel-code-generator`` |
| 131 | +# 0.56.1 assigns them from a global counter whose traversal order shifts |
| 132 | +# with both upstream schema layout AND filesystem-iteration order |
| 133 | +# (APFS-on-macOS vs ext4-on-Linux), so the same pinned generator produces |
| 134 | +# ``Features1`` in one environment and ``Features2`` in another. Reach |
| 135 | +# the classes via their parents' field annotation — both ``Signals`` and |
| 136 | +# ``Adcp`` are stable wire-spec class names, and the field annotations |
| 137 | +# carry the union arm types directly. |
| 138 | +_signals_features_arms = [ |
| 139 | + arm for arm in _get_args(_Signals.model_fields["features"].annotation) if arm is not type(None) |
| 140 | +] |
| 141 | +if len(_signals_features_arms) != 1: |
| 142 | + raise RuntimeError( |
| 143 | + "capabilities: Signals.features annotation lost its concrete type " |
| 144 | + f"(got {_signals_features_arms!r})" |
| 145 | + ) |
| 146 | +SignalsFeatures: type = _signals_features_arms[0] |
| 147 | + |
| 148 | +_idempotency_arms = [ |
| 149 | + arm |
| 150 | + for arm in _get_args(_Adcp.model_fields["idempotency"].annotation) |
| 151 | + if arm is not IdempotencySupported and arm is not type(None) |
| 152 | +] |
| 153 | +if len(_idempotency_arms) != 1: |
| 154 | + raise RuntimeError( |
| 155 | + "capabilities: expected exactly one non-supported Idempotency arm, " |
| 156 | + f"got {_idempotency_arms!r}" |
| 157 | + ) |
| 158 | +IdempotencyUnsupported: type = _idempotency_arms[0] |
| 159 | + |
137 | 160 | __all__ = [ |
138 | 161 | "A2ui", |
139 | 162 | "Adcp", |
|
0 commit comments