apic-cli 0.2.2

A lightweight, Git-friendly CLI tool for designing and collaborating on API contracts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
//! Read-shaped table model derived from `EditModel`.
//!
//! `flatten` emits a `Vec<Section>` that mirrors exactly what `apic read`
//! prints (see `crate::render::Printer`): a bespoke header block followed by the
//! `VARIABLE`/`QUERY`/`HEADERS`/`REQUEST`/`RESPONSE` sections, each carrying an
//! `add: Option<Field>` so the `a` key knows what to append. Every editable
//! `Cell` carries a `Field` address that the handlers in `state.rs` use to
//! locate the target in the model (including the path through nested schema
//! `properties`).

use crate::tui::model::{EditModel, EditSchema, EditUrl};

/// Where a request/response schema lives.
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum BodyLoc {
    Request,
    Response(usize),
}

/// The editable target a cell points at. `SectionHeader` is a non-editable
/// placeholder used by `Label` cells.
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum Field {
    Name,
    Description,
    Method,
    Protocol,
    Host,
    PathSeg(usize),
    PathAdd,
    QueryName(usize),
    QueryValue(usize),
    QueryDesc(usize),
    QueryRequired(usize),
    QueryAdd,
    VarName(usize),
    VarType(usize),
    VarDesc(usize),
    VarRequired(usize),
    VarAdd,
    HeaderName(usize),
    HeaderValue(usize),
    HeaderAdd,
    RequestToggle,
    BodyDtype(BodyLoc),
    ResponseCode(usize),
    ResponseDesc(usize),
    BodyExample(BodyLoc),
    SchemaName(BodyLoc, Vec<usize>),
    SchemaType(BodyLoc, Vec<usize>),
    SchemaDesc(BodyLoc, Vec<usize>),
    SchemaRequired(BodyLoc, Vec<usize>),
    SchemaAccept(BodyLoc, Vec<usize>),
    SchemaAdd(BodyLoc, Vec<usize>),
    ResponseAdd,
    SectionHeader,
}

/// How a cell is edited.
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum CellKind {
    Label, // non-editable (column-1 field labels, built-url, example prompt)
    Text,
    Enum,
    Bool,
}

/// One cell in a table row.
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct Cell {
    pub field: Field,
    pub kind: CellKind,
    pub value: String,
}

/// What kind of section this is, for drawing.
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum SectionKind {
    Header,
    Table,
    Body,
}

/// Which collapsible region (if any) is currently expanded.
#[derive(Debug, Clone, Copy, PartialEq)]
pub(crate) enum Expand {
    Url,
    Request,
    Response(usize),
}

/// Row behavior / how a row is drawn.
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum RowKind {
    Name,    // header name line (drawn uppercased)
    Desc,    // header description line (drawn only when non-empty)
    UrlLine, // collapsed ` METHOD <built-url>`; Enter expands
    Title,   // a Body section's bold title line; Enter expands code/desc/type
    Field,   // an editable table / key-value row
    Example, // inline ` Example:` + raw JSON; Enter opens the modal
}

/// One displayable table row.
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct TableRow {
    pub kind: RowKind,
    pub indent: u16,
    pub cells: Vec<Cell>,
    pub raw: String,    // example buffer for RowKind::Example; empty otherwise
    pub prefix: String, // tree prefix (`├─ `/`└─ `) shown at display time only
}

/// A titled section. `headers: Some(cols)` renders a dim column-header line and
/// aligns `Field` rows whose cell count equals `cols.len()`; `None` is a
/// key/value or header-less table. `add` is the target the `a` key appends to.
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct Section {
    pub title: String,
    pub kind: SectionKind,
    pub headers: Option<Vec<&'static str>>,
    pub rows: Vec<TableRow>,
    pub add: Option<Field>,
    pub expand: Option<Expand>,
}

fn label(text: &str) -> Cell {
    Cell {
        field: Field::SectionHeader,
        kind: CellKind::Label,
        value: text.to_string(),
    }
}
fn text(field: Field, value: String) -> Cell {
    Cell {
        field,
        kind: CellKind::Text,
        value,
    }
}
fn enum_cell(field: Field, value: String) -> Cell {
    Cell {
        field,
        kind: CellKind::Enum,
        value,
    }
}
fn bool_cell(field: Field, v: bool) -> Cell {
    Cell {
        field,
        kind: CellKind::Bool,
        value: if v { "".to_string() } else { String::new() },
    }
}
fn field_row(cells: Vec<Cell>) -> TableRow {
    TableRow {
        kind: RowKind::Field,
        indent: 0,
        cells,
        raw: String::new(),
        prefix: String::new(),
    }
}
fn field_row_i_prefixed(indent: u16, cells: Vec<Cell>, prefix: String) -> TableRow {
    TableRow {
        kind: RowKind::Field,
        indent,
        cells,
        raw: String::new(),
        prefix,
    }
}
/// A Body section's title row, drawn as the bold section title. Its single
/// non-editable `Label` cell carries the read title string.
fn title_row(title: String) -> TableRow {
    TableRow {
        kind: RowKind::Title,
        indent: 0,
        cells: vec![Cell {
            field: Field::SectionHeader,
            kind: CellKind::Label,
            value: title,
        }],
        raw: String::new(),
        prefix: String::new(),
    }
}
fn example_row(loc: BodyLoc, raw: String) -> TableRow {
    TableRow {
        kind: RowKind::Example,
        indent: 0,
        cells: vec![Cell {
            field: Field::BodyExample(loc),
            kind: CellKind::Label,
            value: String::new(),
        }],
        raw,
        prefix: String::new(),
    }
}

/// Inverse-free display URL, matching `render::build_url`'s rules over EditUrl.
fn built_url(u: &EditUrl) -> String {
    let path = u.path.join("/");
    let authority = if u.host.is_empty() {
        String::new()
    } else if u.protocol.is_empty() {
        u.host.clone()
    } else {
        format!("{}://{}", u.protocol, u.host)
    };
    match (authority.is_empty(), path.is_empty()) {
        (true, _) => format!("/{path}"),
        (false, true) => authority,
        (false, false) => format!("{}/{path}", authority.trim_end_matches('/')),
    }
}

/// True if any field at any depth declares `accept`.
fn any_accept(fields: &[EditSchema]) -> bool {
    fields
        .iter()
        .any(|f| !f.accept.trim().is_empty() || any_accept(&f.properties))
}

fn schema_columns(has_accept: bool) -> Vec<&'static str> {
    if has_accept {
        vec!["NAME", "TYPE", "REQ", "ACCEPT", "DESCRIPTION"]
    } else {
        vec!["NAME", "TYPE", "REQ", "DESCRIPTION"]
    }
}

/// Pushes schema field rows (recursively) into `rows`, with `├─`/`└─` prefixes
/// in the NAME cell for nested levels. Mirrors `render::push_field_rows`.
fn push_schema(
    rows: &mut Vec<TableRow>,
    loc: &BodyLoc,
    fields: &[EditSchema],
    path: &mut Vec<usize>,
    depth: usize,
    has_accept: bool,
) {
    for (i, f) in fields.iter().enumerate() {
        path.push(i);
        let prefix = if depth == 0 {
            String::new()
        } else {
            let branch = if i + 1 == fields.len() {
                "└─ "
            } else {
                "├─ "
            };
            format!("{}{branch}", "  ".repeat(depth - 1))
        };
        let mut cells = vec![
            text(Field::SchemaName(loc.clone(), path.clone()), f.name.clone()),
            text(
                Field::SchemaType(loc.clone(), path.clone()),
                f.dtype.clone(),
            ),
            bool_cell(Field::SchemaRequired(loc.clone(), path.clone()), f.required),
        ];
        if has_accept {
            cells.push(text(
                Field::SchemaAccept(loc.clone(), path.clone()),
                f.accept.clone(),
            ));
        }
        cells.push(text(
            Field::SchemaDesc(loc.clone(), path.clone()),
            f.description.clone(),
        ));
        rows.push(field_row_i_prefixed(depth as u16, cells, prefix));

        push_schema(rows, loc, &f.properties, path, depth + 1, has_accept);
        path.pop();
    }
}

/// Builds a body section's rows: `lead` (its Title row + any expanded editable
/// rows) followed by the schema field rows + the inline example row.
fn body_rows(
    lead: Vec<TableRow>,
    loc: BodyLoc,
    fields: &[EditSchema],
    example: &str,
) -> Vec<TableRow> {
    let has_accept = any_accept(fields);
    let mut rows = lead;
    let mut path = Vec::new();
    push_schema(&mut rows, &loc, fields, &mut path, 0, has_accept);
    rows.push(example_row(loc, example.to_string()));
    rows
}

/// Flattens the model into read-shaped display sections.
pub(crate) fn flatten(m: &EditModel, expanded: Option<Expand>) -> Vec<Section> {
    let mut out = Vec::new();

    // Header block: name, description, URL.
    let method_s = crate::json::method_str(&m.method);
    let url_expanded = expanded == Some(Expand::Url);
    let mut head_rows = vec![
        TableRow {
            kind: RowKind::Name,
            indent: 0,
            cells: vec![text(Field::Name, m.name.clone())],
            raw: String::new(),
            prefix: String::new(),
        },
        TableRow {
            kind: RowKind::Desc,
            indent: 0,
            cells: vec![text(Field::Description, m.description.clone())],
            raw: String::new(),
            prefix: String::new(),
        },
    ];
    let mut head_add = None;
    if url_expanded {
        head_rows.push(field_row(vec![
            label("method"),
            enum_cell(Field::Method, method_s.clone()),
        ]));
        head_rows.push(field_row(vec![
            label("protocol"),
            text(Field::Protocol, m.url.protocol.clone()),
        ]));
        head_rows.push(field_row(vec![
            label("host"),
            text(Field::Host, m.url.host.clone()),
        ]));
        for (i, seg) in m.url.path.iter().enumerate() {
            head_rows.push(field_row(vec![
                label("path"),
                text(Field::PathSeg(i), seg.clone()),
            ]));
        }
        head_add = Some(Field::PathAdd);
    } else {
        head_rows.push(TableRow {
            kind: RowKind::UrlLine,
            indent: 0,
            cells: vec![
                enum_cell(Field::Method, method_s),
                Cell {
                    field: Field::Protocol,
                    kind: CellKind::Label,
                    value: built_url(&m.url),
                },
            ],
            raw: String::new(),
            prefix: String::new(),
        });
    }
    out.push(Section {
        title: String::new(),
        kind: SectionKind::Header,
        headers: None,
        rows: head_rows,
        add: head_add,
        expand: Some(Expand::Url),
    });

    // VARIABLE
    let mut v_rows = vec![title_row("VARIABLE".to_string())];
    for (i, v) in m.url.variable.iter().enumerate() {
        v_rows.push(field_row(vec![
            text(Field::VarName(i), v.name.clone()),
            text(Field::VarType(i), v.dtype.clone()),
            bool_cell(Field::VarRequired(i), v.required),
            text(Field::VarDesc(i), v.description.clone()),
        ]));
    }
    out.push(Section {
        title: "VARIABLE".into(),
        kind: SectionKind::Table,
        headers: Some(vec!["NAME", "TYPE", "REQ", "DESCRIPTION"]),
        rows: v_rows,
        add: Some(Field::VarAdd),
        expand: None,
    });

    // QUERY
    let mut q_rows = vec![title_row("QUERY".to_string())];
    for (i, q) in m.url.query.iter().enumerate() {
        q_rows.push(field_row(vec![
            text(Field::QueryName(i), q.name.clone()),
            text(Field::QueryValue(i), q.value.clone()),
            bool_cell(Field::QueryRequired(i), q.required),
            text(Field::QueryDesc(i), q.description.clone()),
        ]));
    }
    out.push(Section {
        title: "QUERY".into(),
        kind: SectionKind::Table,
        headers: Some(vec!["NAME", "VALUE", "REQ", "DESCRIPTION"]),
        rows: q_rows,
        add: Some(Field::QueryAdd),
        expand: None,
    });

    // HEADERS (no column header, like read)
    let mut h_rows = vec![title_row("HEADERS".to_string())];
    for (i, h) in m.headers.iter().enumerate() {
        h_rows.push(field_row(vec![
            text(Field::HeaderName(i), h.name.clone()),
            text(Field::HeaderValue(i), h.value.clone()),
        ]));
    }
    out.push(Section {
        title: "HEADERS".into(),
        kind: SectionKind::Table,
        headers: None,
        rows: h_rows,
        add: Some(Field::HeaderAdd),
        expand: None,
    });

    // REQUEST. With no body, `a` toggles one on (RequestToggle); with a body,
    // `a` appends a top-level schema field (SchemaAdd). The title row expands
    // into an editable `type` row.
    match &m.request {
        Some(req) => {
            let title = format!("REQUEST{}", crate::render::array_marker(&req.dtype));
            let mut lead = vec![title_row(title)];
            if expanded == Some(Expand::Request) {
                lead.push(field_row(vec![
                    label("type"),
                    enum_cell(Field::BodyDtype(BodyLoc::Request), req.dtype.clone()),
                ]));
            }
            out.push(Section {
                title: String::new(),
                kind: SectionKind::Body,
                headers: Some(schema_columns(any_accept(&req.schema))),
                rows: body_rows(lead, BodyLoc::Request, &req.schema, &req.example),
                add: Some(Field::SchemaAdd(BodyLoc::Request, Vec::new())),
                expand: Some(Expand::Request),
            });
        }
        None => out.push(Section {
            title: "REQUEST".to_string(),
            kind: SectionKind::Body,
            headers: None,
            rows: vec![title_row("REQUEST".to_string())],
            add: Some(Field::RequestToggle),
            expand: Some(Expand::Request),
        }),
    }

    // RESPONSE(s)
    if m.responses.is_empty() {
        out.push(Section {
            title: "RESPONSE".into(),
            kind: SectionKind::Table,
            headers: None,
            rows: vec![title_row("RESPONSE".to_string())],
            add: Some(Field::ResponseAdd),
            expand: None,
        });
    } else {
        for (i, r) in m.responses.iter().enumerate() {
            let marker = crate::render::array_marker(&r.dtype);
            let title = format!("RESPONSE {}{}{marker}", r.code, r.description);
            let mut lead = vec![title_row(title)];
            if expanded == Some(Expand::Response(i)) {
                lead.push(field_row(vec![
                    label("code"),
                    text(Field::ResponseCode(i), r.code.clone()),
                ]));
                lead.push(field_row(vec![
                    label("description"),
                    text(Field::ResponseDesc(i), r.description.clone()),
                ]));
                lead.push(field_row(vec![
                    label("type"),
                    enum_cell(Field::BodyDtype(BodyLoc::Response(i)), r.dtype.clone()),
                ]));
            }
            out.push(Section {
                title: String::new(),
                kind: SectionKind::Body,
                headers: Some(schema_columns(any_accept(&r.schema))),
                rows: body_rows(lead, BodyLoc::Response(i), &r.schema, &r.example),
                add: Some(Field::SchemaAdd(BodyLoc::Response(i), Vec::new())),
                expand: Some(Expand::Response(i)),
            });
        }
    }

    // A trailing "+ add response" affordance so the cursor can land on it and
    // `a` appends a new response at any time (not just when there are zero).
    out.push(Section {
        title: String::new(),
        kind: SectionKind::Table,
        headers: None,
        rows: vec![field_row(vec![label("+ add response")])],
        add: Some(Field::ResponseAdd),
        expand: None,
    });

    out
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::json::json_get;

    fn model() -> EditModel {
        let c = json_get(
            r#"{ "name":"user","description":"User management","method":"GET",
                 "url":{"protocol":"https","host":"api.example.com","path":["user"],
                        "variable":[{"name":"id","type":"int","description":"User ID","required":false}]},
                 "headers":[{"name":"Content-Type","value":"application/json"}],
                 "responses":[{"code":200,"description":"ok","schema":[
                    {"name":"data","type":"object","default":null,"description":"d","required":false,
                     "properties":[{"name":"id","type":"int","default":null,"description":"d","required":true}]}
                 ],"example":{"status":200}}] }"#,
            None,
        )
        .unwrap();
        EditModel::from_contract(c)
    }

    /// The displayed title of a section: its `title` field, or for Body
    /// sections the value of the leading `Title` row.
    fn shown_title(s: &Section) -> String {
        if let Some(row) = s.rows.iter().find(|r| r.kind == RowKind::Title) {
            row.cells[0].value.clone()
        } else {
            s.title.clone()
        }
    }

    #[test]
    fn header_block_has_name_desc_and_collapsed_url() {
        let secs = flatten(&model(), None);
        let head = &secs[0];
        assert_eq!(head.kind, SectionKind::Header);
        assert!(head.rows.iter().any(|r| r.kind == RowKind::Name));
        assert!(head.rows.iter().any(|r| r.kind == RowKind::Desc));
        let url = head
            .rows
            .iter()
            .find(|r| r.kind == RowKind::UrlLine)
            .unwrap();
        // The built URL cell shows the assembled URL.
        assert!(
            url.cells
                .iter()
                .any(|c| c.value.contains("https://api.example.com/user"))
        );
    }

    #[test]
    fn url_expands_to_editable_parts() {
        let secs = flatten(&model(), Some(Expand::Url));
        let head = &secs[0];
        assert!(head.rows.iter().all(|r| r.kind != RowKind::UrlLine));
        assert!(
            head.rows
                .iter()
                .any(|r| matches!(r.cells.last().map(|c| &c.field), Some(Field::Protocol)))
        );
        assert!(
            head.rows
                .iter()
                .any(|r| matches!(r.cells.last().map(|c| &c.field), Some(Field::Host)))
        );
        assert_eq!(head.add, Some(Field::PathAdd));
    }

    #[test]
    fn section_titles_match_read() {
        let secs = flatten(&model(), None);
        let titles: Vec<String> = secs.iter().map(shown_title).collect();
        assert!(titles.iter().any(|t| t == "VARIABLE"));
        assert!(titles.iter().any(|t| t == "QUERY"));
        assert!(titles.iter().any(|t| t == "HEADERS"));
        assert!(titles.iter().any(|t| t == "REQUEST"));
        assert!(titles.iter().any(|t| t.starts_with("RESPONSE 200 — ok")));
    }

    #[test]
    fn response_title_expands_to_editable_code_desc_type() {
        let secs = flatten(&model(), Some(Expand::Response(0)));
        let resp = secs
            .iter()
            .find(|s| s.expand == Some(Expand::Response(0)))
            .unwrap();
        assert!(resp.rows.iter().any(|r| matches!(
            r.cells.last().map(|c| &c.field),
            Some(Field::ResponseCode(0))
        )));
        assert!(resp.rows.iter().any(|r| matches!(
            r.cells.last().map(|c| &c.field),
            Some(Field::ResponseDesc(0))
        )));
        assert!(resp.rows.iter().any(|r| matches!(
            r.cells.last().map(|c| &c.field),
            Some(Field::BodyDtype(BodyLoc::Response(0)))
        )));
    }

    #[test]
    fn add_targets_are_set() {
        let secs = flatten(&model(), None);
        let q = secs.iter().find(|s| s.title == "QUERY").unwrap();
        assert_eq!(q.add, Some(Field::QueryAdd));
        let h = secs.iter().find(|s| s.title == "HEADERS").unwrap();
        assert_eq!(h.add, Some(Field::HeaderAdd));
        assert!(h.headers.is_none()); // HEADERS has no column header, like read
    }

    #[test]
    fn nested_field_has_tree_prefix_and_response_has_example_row() {
        let secs = flatten(&model(), None);
        let resp = secs
            .iter()
            .find(|s| s.expand == Some(Expand::Response(0)))
            .unwrap();
        assert!(resp.rows.iter().any(|r| {
            r.kind == RowKind::Field && (r.prefix.contains("├─") || r.prefix.contains("└─"))
        }));
        assert!(
            resp.rows
                .iter()
                .any(|r| r.kind == RowKind::Example && r.raw.contains("status"))
        );
    }

    #[test]
    fn table_sections_have_selectable_title_rows() {
        let secs = flatten(&model(), None);
        for t in ["VARIABLE", "QUERY", "HEADERS"] {
            let s = secs.iter().find(|s| s.title == t).unwrap();
            assert!(
                s.rows
                    .first()
                    .map(|r| r.kind == RowKind::Title)
                    .unwrap_or(false),
                "{t} should start with a Title row"
            );
        }
    }

    #[test]
    fn trailing_add_response_affordance_present() {
        let secs = flatten(&model(), None);
        let aff = secs
            .iter()
            .find(|s| {
                s.add == Some(Field::ResponseAdd)
                    && s.rows.iter().any(|r| {
                        r.cells
                            .first()
                            .map(|c| c.value == "+ add response")
                            .unwrap_or(false)
                    })
            })
            .expect("a '+ add response' affordance section exists");
        assert_eq!(aff.add, Some(Field::ResponseAdd));
    }

    #[test]
    fn nested_name_cell_is_bare_with_prefix_on_row() {
        let secs = flatten(&model(), None);
        let resp = secs
            .iter()
            .find(|s| s.title.starts_with("RESPONSE 200") || s.expand == Some(Expand::Response(0)))
            .unwrap();
        let nested = resp
            .rows
            .iter()
            .find(|r| matches!(&r.cells.first().map(|c| &c.field), Some(Field::SchemaName(BodyLoc::Response(_), p)) if p.len()==2))
            .unwrap();
        assert!(!nested.cells[0].value.contains('') && !nested.cells[0].value.contains(''));
        assert!(nested.prefix.contains('') || nested.prefix.contains(''));
    }
}