Commit 2e69e37
authored
refactor: jq middleware improvements from gojq module review (#3026)
## Summary
Implements the quick-win improvements identified in the gojq module
review (#2985).
## Changes
### 1. Remove duplicate test helper
Deleted `integrationPayloadMetadataToMap` from
`jqschema_integration_test.go` — it was byte-for-byte identical to
`payloadMetadataToMap` in `jqschema_test.go`. Both files are in `package
middleware`, so the shared helper is directly usable.
### 2. Document custom `walk` vs built-in
Added a comment block explaining why `jqSchemaFilter` defines its own
`walk` function instead of using gojq's built-in `walk(f)`:
- Built-in `walk(f)` applies `f` post-recursion but preserves structure
- Our custom walk replaces leaf values with type names AND collapses
arrays to first element
- These behaviors are incompatible with standard `walk(f)` semantics
### 3. Document single-result iterator contract
Added comment explaining why `iter.Next()` is called only once — the
`walk(.)` filter produces exactly one output value.
### 4. UTF-8 safety comment on preview truncation
Documented why byte-level slicing at `PayloadPreviewSize` is safe:
`json.Marshal` escapes non-ASCII runes as `\uXXXX`, so every byte
boundary is a valid UTF-8 boundary.
### 5. Skip redundant JSON unmarshal
Added a type-switch in `WrapToolHandler` that skips the `json.Unmarshal`
step when `data` is already `map[string]interface{}` or `[]interface{}`.
This avoids a needless marshal→unmarshal round-trip on hot paths.
Closes #29852 files changed
Lines changed: 33 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
57 | 67 | | |
58 | 68 | | |
59 | 69 | | |
| |||
143 | 153 | | |
144 | 154 | | |
145 | 155 | | |
| 156 | + | |
| 157 | + | |
146 | 158 | | |
147 | 159 | | |
148 | 160 | | |
| |||
331 | 343 | | |
332 | 344 | | |
333 | 345 | | |
334 | | - | |
| 346 | + | |
| 347 | + | |
335 | 348 | | |
336 | | - | |
337 | | - | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
338 | 356 | | |
339 | 357 | | |
340 | 358 | | |
| |||
356 | 374 | | |
357 | 375 | | |
358 | 376 | | |
359 | | - | |
| 377 | + | |
360 | 378 | | |
361 | | - | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
362 | 384 | | |
363 | 385 | | |
364 | 386 | | |
365 | 387 | | |
366 | | - | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
367 | 393 | | |
368 | 394 | | |
369 | 395 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | 16 | | |
32 | 17 | | |
33 | 18 | | |
| |||
214 | 199 | | |
215 | 200 | | |
216 | 201 | | |
217 | | - | |
| 202 | + | |
218 | 203 | | |
219 | 204 | | |
220 | 205 | | |
| |||
0 commit comments