Commit 838d5b8
committed
Support Rails-style deepObject query param
Updates the data models to capture `style` and `explode` parameters.
There was a PR outstanding that went in this direction [1]. We might
want to rebase on top of that one day, when it's merged. For now we
settle for some more targeted changes.
Updates "ModelProperty" and related templates with a `to_deep_dict()`
serialization option. This option differs from the regular `to_dict()`
in that nested dicts are flattened. It also adds a `[]` suffix for keys
that point at arrays. Finally, it takes a "prefix" argument that is the
base name of this object.
The end result of all this is that we can have a deepObject query param
named `filter` that results in some `FooFilter` model param. We can
initialize it as
```python
FooFilter.from_dict({'owner': { 'id': [12, 34] }})
```
then invoke its `to_deep_dict()` method to get
```python
{ 'filter[owner][id][]': [12, 34] }
```
which, when passed in to `httpx`, will result in a query param like
```
?filter[owner][id][]=12&filter[owner][id][]=34
```
which is exactly the format that APIv2 expects. This is not a
coincidence. We're doing this specifically to support APIv2.
Unfortunately, I don't see a straightforward way to polish and upstream
this change. The serialization conventions above are "Rails-style" [2],
one of many possible interpretations of how an OpenAPI deepObject should
act. The spec doesn't actually specify very much here.
So, while this is technically not *against* the spec, this is probably
not the interpretation that a Python generator would go with by default.
(Maybe one day it could be configurable? Or just wait and see if
OpenAPI delivers on its promise to fix all this?)
I feel like "fork" is the best option for us for now.
Since I don't expect this to be upstreamed, I haven't put much effort
into updating test suites. I expect that would only make later rebases
more difficult, without actually testing what we want most, which is
"do the generated libraries work with our API?"
[1] openapi-generators#1296
[2] OAI/OpenAPI-Specification#1706 (comment)1 parent a289533 commit 838d5b8
File tree
5 files changed
+58
-0
lines changed- openapi_python_client
- parser
- properties
- templates
- property_templates
5 files changed
+58
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
| 285 | + | |
| 286 | + | |
285 | 287 | | |
286 | 288 | | |
287 | 289 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| 150 | + | |
| 151 | + | |
150 | 152 | | |
151 | 153 | | |
152 | 154 | | |
| |||
297 | 299 | | |
298 | 300 | | |
299 | 301 | | |
| 302 | + | |
| 303 | + | |
300 | 304 | | |
301 | 305 | | |
302 | 306 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
30 | 33 | | |
31 | 34 | | |
32 | 35 | | |
| |||
46 | 49 | | |
47 | 50 | | |
48 | 51 | | |
| 52 | + | |
| 53 | + | |
49 | 54 | | |
50 | 55 | | |
51 | 56 | | |
| |||
108 | 113 | | |
109 | 114 | | |
110 | 115 | | |
| 116 | + | |
| 117 | + | |
111 | 118 | | |
112 | 119 | | |
113 | 120 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
150 | 191 | | |
151 | 192 | | |
152 | 193 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
14 | 17 | | |
| 18 | + | |
15 | 19 | | |
16 | 20 | | |
17 | 21 | | |
| |||
0 commit comments