Commit 72154fd
authored
RPC peers: emit empty arrays for descriptor collections, never omit them (#7546)
* RPC peers: emit empty arrays for descriptor collections, never omit them
`Recipe.getDescriptor()` on the Java side always returns a descriptor
whose collection-valued getters (`tags`, `options`, `preconditions`,
`recipeList`, `dataTables`, `maintainers`, `contributors`, `examples`)
are non-null. Callers across the ecosystem rely on that and iterate the
getters without null checks.
When a `RecipeDescriptor` is produced by a polyglot RPC peer, however,
the JSON those peers emit can omit empty collections — Jackson then
deserializes the corresponding fields as `null`, breaking every
downstream caller (e.g. `descriptor.getPreconditions().iterator()`).
Fix the Python and TypeScript peers to always emit every collection key,
even when empty. The C# peer was already correct: `RecipeDescriptorDto`
declares each list/set property with an `= []` initializer and
Newtonsoft serializes empty collections as `[]`, so the JSON it produces
already matches the contract.
Python (`rewrite/src/rewrite/rpc/server.py`):
Add `preconditions`, `maintainers`, `contributors`, `examples` as
empty lists in `_recipe_descriptor_to_dict`. (The Python `RecipeDescriptor`
dataclass doesn't model these fields yet, so they're hardcoded.)
TypeScript (`rewrite/src/recipe.ts`):
Extend the `RecipeDescriptor` interface with the four missing fields
and have `Recipe.descriptor()` populate them. Updates the existing
`recipe.test.ts` snapshot.
* Update recipe.ts
* Update server.py
* Update test_server.py1 parent b9b436f commit 72154fd
4 files changed
Lines changed: 44 additions & 5 deletions
File tree
- rewrite-javascript/rewrite
- src
- test
- rewrite-python/rewrite
- src/rewrite/rpc
- tests/rpc
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
100 | 99 | | |
101 | 100 | | |
102 | 101 | | |
103 | 102 | | |
104 | 103 | | |
105 | 104 | | |
106 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
107 | 111 | | |
108 | 112 | | |
109 | 113 | | |
| |||
135 | 139 | | |
136 | 140 | | |
137 | 141 | | |
138 | | - | |
139 | 142 | | |
| 143 | + | |
| 144 | + | |
140 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
141 | 149 | | |
142 | 150 | | |
143 | 151 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
49 | 53 | | |
50 | 54 | | |
51 | 55 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
971 | 971 | | |
972 | 972 | | |
973 | 973 | | |
974 | | - | |
| 974 | + | |
975 | 975 | | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
976 | 980 | | |
977 | 981 | | |
978 | 982 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
0 commit comments