oas3-gen 0.26.2

A rust type generator for OpenAPI v3.1.x specification.
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
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
use oas3::spec::{ObjectSchema, SchemaType, SchemaTypeSet, Spec};
use serde_json::json;

use crate::{
  generator::{
    metrics::{GenerationStats, GenerationWarning},
    schema_registry::SchemaRegistry,
  },
  tests::common::parse_schema,
  utils::{SchemaInspect, UnionFingerprints, parse_schema_ref_path},
};

const SCHEMA_REF_PREFIX: &str = "#/components/schemas/";

#[test]
fn test_parse_ref() {
  let cases = [
    ("#/components/schemas/Corgi", Some("Corgi")),
    ("#/components/schemas/NestedCorgi", Some("NestedCorgi")),
    ("#/other/path", None),
    ("InvalidRef", None),
  ];
  for (input, expected) in cases {
    let result = parse_schema_ref_path(input);
    assert_eq!(result.as_deref(), expected, "failed for input {input:?}");
  }
}

fn spec_with_schemas(schemas_json: &serde_json::Value) -> Spec {
  let spec_json = json!({
    "openapi": "3.0.0",
    "info": {"title": "Test", "version": "1.0.0"},
    "components": {"schemas": schemas_json}
  });
  serde_json::from_value(spec_json).expect("failed to parse spec from JSON")
}

#[test]
fn test_ref_collector() {
  let spec = spec_with_schemas(&json!({}));
  let mut stats = GenerationStats::default();
  let registry = SchemaRegistry::new(&spec, &mut stats);
  let union_fingerprints = UnionFingerprints::new();

  let schema = parse_schema(json!({
    "properties": {
      "related": {"$ref": "#/components/schemas/Corgi"}
    }
  }));
  let refs = registry.collect(&schema, &union_fingerprints);
  assert_eq!(refs.len(), 1, "simple ref: expected 1 ref");
  assert!(refs.contains("Corgi"), "simple ref: should contain Corgi");

  let schema = parse_schema(json!({
    "properties": {
      "waddler": {"$ref": "#/components/schemas/Corgi"},
      "sploot": {"$ref": "#/components/schemas/Sploot"}
    }
  }));
  let refs = registry.collect(&schema, &union_fingerprints);
  assert_eq!(refs.len(), 2, "multiple refs: expected 2 refs");
  assert!(refs.contains("Corgi"), "multiple refs: should contain Corgi");
  assert!(refs.contains("Sploot"), "multiple refs: should contain Sploot");

  let schema = parse_schema(json!({
    "oneOf": [{"$ref": "#/components/schemas/Corgi"}],
    "anyOf": [{"$ref": "#/components/schemas/Bark"}],
    "allOf": [{"$ref": "#/components/schemas/Frappe"}]
  }));
  let refs = registry.collect(&schema, &union_fingerprints);
  assert_eq!(refs.len(), 3, "combinators: expected 3 refs");
  assert!(refs.contains("Corgi"), "combinators: should contain Corgi");
  assert!(refs.contains("Bark"), "combinators: should contain Bark");
  assert!(refs.contains("Frappe"), "combinators: should contain Frappe");
}

#[test]
fn test_schema_registry() {
  let spec = spec_with_schemas(&json!({
    "Corgi": {"type": "object"},
    "Bark": {"type": "object"}
  }));
  let mut stats = GenerationStats::default();
  let registry = SchemaRegistry::new(&spec, &mut stats);

  assert!(registry.get("Corgi").is_some(), "should have Corgi schema");
  assert!(registry.get("Bark").is_some(), "should have Bark schema");
  assert!(registry.get("NonExistent").is_none(), "should not have NonExistent");
  assert_eq!(registry.keys().len(), 2, "should have 2 schemas");

  let spec = spec_with_schemas(&json!({
    "Corgi": {"type": "object"},
    "Bark": {
      "type": "object",
      "properties": {
        "related": {"$ref": "#/components/schemas/Corgi"}
      }
    }
  }));
  let mut stats = GenerationStats::default();
  let mut graph = SchemaRegistry::new(&spec, &mut stats);
  let union_fingerprints = UnionFingerprints::new();
  graph.build_dependencies(&union_fingerprints);

  assert_eq!(graph.keys().len(), 2, "build deps: should have 2 schemas");
  assert!(graph.get("Corgi").is_some(), "build deps: should have Corgi");
  assert!(graph.get("Bark").is_some(), "build deps: should have Bark");
}

#[test]
fn test_schema_graph_cycle_detection() {
  {
    let spec = spec_with_schemas(&json!({
      "A": {"type": "object"},
      "B": {
        "type": "object",
        "properties": {
          "a": {"$ref": "#/components/schemas/A"}
        }
      },
      "C": {
        "type": "object",
        "properties": {
          "b": {"$ref": "#/components/schemas/B"}
        }
      }
    }));
    let mut stats = GenerationStats::default();
    let mut graph = SchemaRegistry::new(&spec, &mut stats);
    let union_fingerprints = UnionFingerprints::new();
    graph.build_dependencies(&union_fingerprints);
    let cycles = graph.detect_cycles();

    assert!(cycles.is_empty(), "linear deps: should have no cycles");
    assert!(!graph.is_cyclic("A"), "linear deps: A should not be cyclic");
    assert!(!graph.is_cyclic("B"), "linear deps: B should not be cyclic");
    assert!(!graph.is_cyclic("C"), "linear deps: C should not be cyclic");
  }

  {
    let spec = spec_with_schemas(&json!({
      "A": {
        "type": "object",
        "properties": {
          "b": {"$ref": "#/components/schemas/B"}
        }
      },
      "B": {
        "type": "object",
        "properties": {
          "a": {"$ref": "#/components/schemas/A"}
        }
      }
    }));
    let mut stats = GenerationStats::default();
    let mut graph = SchemaRegistry::new(&spec, &mut stats);
    let union_fingerprints = UnionFingerprints::new();
    graph.build_dependencies(&union_fingerprints);
    let cycles = graph.detect_cycles();

    assert_eq!(cycles.len(), 1, "simple cycle: should detect 1 cycle");
    assert!(!cycles[0].is_empty(), "simple cycle: cycle should not be empty");
    assert!(graph.is_cyclic("A"), "simple cycle: A should be cyclic");
    assert!(graph.is_cyclic("B"), "simple cycle: B should be cyclic");
  }

  {
    let spec = spec_with_schemas(&json!({
      "A": {
        "type": "object",
        "properties": {
          "self_ref": {"$ref": "#/components/schemas/A"}
        }
      }
    }));
    let mut stats = GenerationStats::default();
    let mut graph = SchemaRegistry::new(&spec, &mut stats);
    let union_fingerprints = UnionFingerprints::new();
    graph.build_dependencies(&union_fingerprints);
    let cycles = graph.detect_cycles();

    assert_eq!(cycles.len(), 1, "self-ref: should detect 1 cycle");
    assert!(graph.is_cyclic("A"), "self-ref: A should be cyclic");
  }

  {
    let spec = spec_with_schemas(&json!({
      "User": {
        "type": "object",
        "properties": {
          "posts": {"$ref": "#/components/schemas/Post"}
        }
      },
      "Post": {
        "type": "object",
        "properties": {
          "author": {"$ref": "#/components/schemas/User"}
        }
      }
    }));
    let mut stats = GenerationStats::default();
    let mut graph = SchemaRegistry::new(&spec, &mut stats);
    let union_fingerprints = UnionFingerprints::new();
    graph.build_dependencies(&union_fingerprints);
    let cycles = graph.detect_cycles();

    assert!(!cycles.is_empty(), "user-post cycle: should detect cycles");
    assert!(graph.is_cyclic("User"), "user-post cycle: User should be cyclic");
    assert!(graph.is_cyclic("Post"), "user-post cycle: Post should be cyclic");
  }
}

#[test]
fn test_schema_registry_merges_all_of_properties_and_required() {
  let spec = spec_with_schemas(&json!({
    "Loaf": {
      "type": "object",
      "required": ["tag_id"],
      "properties": {
        "tag_id": {"type": "integer"}
      },
      "additionalProperties": true
    },
    "Nugget": {
      "type": "object",
      "required": ["name"],
      "properties": {
        "name": {"type": "string"}
      },
      "allOf": [{"$ref": "#/components/schemas/Loaf"}]
    }
  }));

  let mut stats = GenerationStats::default();
  let mut graph = SchemaRegistry::new(&spec, &mut stats);
  let union_fingerprints = UnionFingerprints::new();
  graph.build_dependencies(&union_fingerprints);
  graph.detect_cycles();

  let merged = graph.merged("Nugget").expect("merged schema should exist for Nugget");

  assert!(merged.schema.properties.contains_key("tag_id"));
  assert!(merged.schema.properties.contains_key("name"));
  assert!(merged.schema.required.contains(&"tag_id".to_string()));
  assert!(merged.schema.required.contains(&"name".to_string()));
  assert!(merged.schema.additional_properties.is_some());
}

#[test]
fn test_schema_registry_merges_and_tracks_discriminator_parents() {
  let spec = spec_with_schemas(&json!({
    "Loaf": {
      "type": "object",
      "properties": {
        "kind": {"type": "string"}
      },
      "discriminator": {
        "propertyName": "kind",
        "mapping": {
          "nugget": "#/components/schemas/Nugget"
        }
      }
    },
    "Nugget": {
      "type": "object",
      "properties": {
        "nugget_prop": {"type": "integer"}
      },
      "allOf": [{"$ref": "#/components/schemas/Loaf"}]
    }
  }));

  let mut stats = GenerationStats::default();
  let mut graph = SchemaRegistry::new(&spec, &mut stats);
  let union_fingerprints = UnionFingerprints::new();
  graph.build_dependencies(&union_fingerprints);
  graph.detect_cycles();

  let merged_nugget = graph.merged("Nugget").expect("merged schema should exist for Nugget");

  assert_eq!(merged_nugget.discriminator_parent.as_deref(), Some("Loaf"));
  assert!(merged_nugget.schema.properties.contains_key("kind"));
  assert!(merged_nugget.schema.properties.contains_key("nugget_prop"));

  let parent_name = graph.parent("Nugget").expect("discriminator parent should be tracked");

  assert_eq!(parent_name, "Loaf");

  let effective = graph.resolved("Nugget").unwrap();
  assert_eq!(effective.properties.len(), merged_nugget.schema.properties.len());
}

#[test]
fn schema_merger_conflict_resolution() {
  let spec = spec_with_schemas(&json!({
    "Loaf": {
      "type": "object",
      "properties": {
        "prop": {"type": "string"}
      }
    },
    "Nugget": {
      "type": "object",
      "properties": {
        "prop": {"type": "integer"}
      },
      "allOf": [{"$ref": "#/components/schemas/Loaf"}]
    }
  }));

  let mut stats = GenerationStats::default();
  let mut graph = SchemaRegistry::new(&spec, &mut stats);
  let union_fingerprints = UnionFingerprints::new();
  graph.build_dependencies(&union_fingerprints);
  graph.detect_cycles();

  let merged = graph.merged("Nugget").expect("merged schema should exist for Nugget");

  let prop = merged.schema.properties.get("prop").unwrap();
  let schema = prop.as_inline().expect("Expected Object schema");
  assert_eq!(
    schema.schema_type,
    Some(SchemaTypeSet::Single(SchemaType::Integer)),
    "nugget property should override loaf"
  );
}

#[test]
fn schema_merger_merge_multiple_all_of() {
  let spec = spec_with_schemas(&json!({
    "Corgi": {
      "type": "object",
      "required": ["corgi_prop"],
      "properties": {
        "corgi_prop": {"type": "string"}
      }
    },
    "Fluff": {
      "type": "object",
      "properties": {
        "fluff_prop": {"type": "integer"}
      }
    },
    "Composite": {
      "type": "object",
      "allOf": [
        {"$ref": "#/components/schemas/Corgi"},
        {"$ref": "#/components/schemas/Fluff"}
      ],
      "properties": {
        "own_prop": {"type": "boolean"}
      }
    }
  }));

  let mut stats = GenerationStats::default();
  let mut graph = SchemaRegistry::new(&spec, &mut stats);
  let union_fingerprints = UnionFingerprints::new();
  graph.build_dependencies(&union_fingerprints);
  graph.detect_cycles();

  let merged = graph
    .merged("Composite")
    .expect("merged schema should exist for Composite");

  assert!(
    merged.schema.properties.contains_key("corgi_prop"),
    "should have corgi_prop"
  );
  assert!(
    merged.schema.properties.contains_key("fluff_prop"),
    "should have fluff_prop"
  );
  assert!(
    merged.schema.properties.contains_key("own_prop"),
    "should have own_prop"
  );
  assert!(
    merged.schema.required.contains(&"corgi_prop".to_string()),
    "corgi_prop should be required"
  );
}

#[test]
fn implicit_discriminator_mapping_from_const_values() {
  let spec = spec_with_schemas(&json!({
    "Allergies": {
      "type": "object",
      "properties": {
        "type": {"type": "string", "const": "allergies"}
      },
      "required": ["type"]
    },
    "Diet": {
      "type": "object",
      "properties": {
        "type": {"type": "string", "const": "diet"}
      },
      "required": ["type"]
    },
    "Health": {
      "type": "object",
      "oneOf": [
        {"$ref": "#/components/schemas/Allergies"},
        {"$ref": "#/components/schemas/Diet"}
      ],
      "discriminator": {"propertyName": "type"}
    }
  }));

  let mut stats = GenerationStats::default();
  let registry = SchemaRegistry::new(&spec, &mut stats);

  let allergies_mapping = registry.mapping("Allergies");
  assert!(
    allergies_mapping.is_some(),
    "Allergies should have a synthesized mapping"
  );
  let am = allergies_mapping.unwrap();
  assert_eq!(am.field_name, "type", "field_name should be 'type'");
  assert_eq!(am.field_value, "allergies", "field_value should be 'allergies'");

  let diet_mapping = registry.mapping("Diet");
  assert!(diet_mapping.is_some(), "Diet should have a synthesized mapping");
  let dm = diet_mapping.unwrap();
  assert_eq!(dm.field_name, "type", "field_name should be 'type'");
  assert_eq!(dm.field_value, "diet", "field_value should be 'diet'");

  assert!(stats.warnings.is_empty(), "should have no warnings");
}

#[test]
fn implicit_discriminator_mapping_warns_on_missing_const() {
  let spec = spec_with_schemas(&json!({
    "Allergies": {
      "type": "object",
      "properties": {
        "type": {"type": "string", "const": "allergies"}
      },
      "required": ["type"]
    },
    "Diet": {
      "type": "object",
      "properties": {
        "type": {"type": "string"}
      }
    },
    "Health": {
      "type": "object",
      "oneOf": [
        {"$ref": "#/components/schemas/Allergies"},
        {"$ref": "#/components/schemas/Diet"}
      ],
      "discriminator": {"propertyName": "type"}
    }
  }));

  let mut stats = GenerationStats::default();
  let registry = SchemaRegistry::new(&spec, &mut stats);

  assert!(
    registry.mapping("Allergies").is_none(),
    "no mapping should be synthesized"
  );
  assert!(registry.mapping("Diet").is_none(), "no mapping should be synthesized");
  assert_eq!(stats.warnings.len(), 1, "should have one warning");
  assert!(
    matches!(&stats.warnings[0], GenerationWarning::DiscriminatorMappingFailed { schema_name, message }
      if schema_name == "Health" && message.contains("Diet") && message.contains("no string const")),
    "warning should mention Diet missing const: {:?}",
    stats.warnings[0]
  );
}

#[test]
fn implicit_discriminator_mapping_warns_on_duplicate_const() {
  let spec = spec_with_schemas(&json!({
    "Allergies": {
      "type": "object",
      "properties": {
        "type": {"type": "string", "const": "same_value"}
      },
      "required": ["type"]
    },
    "Diet": {
      "type": "object",
      "properties": {
        "type": {"type": "string", "const": "same_value"}
      },
      "required": ["type"]
    },
    "Health": {
      "type": "object",
      "oneOf": [
        {"$ref": "#/components/schemas/Allergies"},
        {"$ref": "#/components/schemas/Diet"}
      ],
      "discriminator": {"propertyName": "type"}
    }
  }));

  let mut stats = GenerationStats::default();
  let registry = SchemaRegistry::new(&spec, &mut stats);

  assert!(
    registry.mapping("Allergies").is_none(),
    "no mapping should be synthesized"
  );
  assert!(registry.mapping("Diet").is_none(), "no mapping should be synthesized");
  assert_eq!(stats.warnings.len(), 1, "should have one warning");
  assert!(
    matches!(&stats.warnings[0], GenerationWarning::DiscriminatorMappingFailed { schema_name, message }
      if schema_name == "Health" && message.contains("duplicate")),
    "warning should mention duplicate: {:?}",
    stats.warnings[0]
  );
}

#[test]
fn explicit_mapping_takes_precedence_over_const() {
  let spec = spec_with_schemas(&json!({
    "Allergies": {
      "type": "object",
      "properties": {
        "type": {"type": "string", "const": "allergies"}
      },
      "required": ["type"]
    },
    "Diet": {
      "type": "object",
      "properties": {
        "type": {"type": "string", "const": "diet"}
      },
      "required": ["type"]
    },
    "Health": {
      "type": "object",
      "oneOf": [
        {"$ref": "#/components/schemas/Allergies"},
        {"$ref": "#/components/schemas/Diet"}
      ],
      "discriminator": {
        "propertyName": "type",
        "mapping": {
          "allergy_override": "#/components/schemas/Allergies",
          "diet_override": "#/components/schemas/Diet"
        }
      }
    }
  }));

  let mut stats = GenerationStats::default();
  let registry = SchemaRegistry::new(&spec, &mut stats);

  let am = registry.mapping("Allergies").expect("Allergies should have a mapping");
  assert_eq!(
    am.field_value, "allergy_override",
    "explicit mapping should take precedence"
  );

  let dm = registry.mapping("Diet").expect("Diet should have a mapping");
  assert_eq!(
    dm.field_value, "diet_override",
    "explicit mapping should take precedence"
  );

  assert!(stats.warnings.is_empty(), "should have no warnings");
}

#[test]
fn test_ref_collector_additional_properties() {
  let spec = spec_with_schemas(&json!({}));
  let mut stats = GenerationStats::default();
  let registry = SchemaRegistry::new(&spec, &mut stats);
  let union_fingerprints = UnionFingerprints::new();

  let schema = parse_schema(json!({
    "additionalProperties": {
      "$ref": "#/components/schemas/VaccineRecord"
    }
  }));
  let refs = registry.collect(&schema, &union_fingerprints);
  assert_eq!(refs.len(), 1, "direct additional_properties ref: expected 1 ref");
  assert!(refs.contains("VaccineRecord"), "should contain VaccineRecord");

  let schema = parse_schema(json!({
    "additionalProperties": {
      "type": "array",
      "items": {
        "$ref": "#/components/schemas/VaccineRecord"
      }
    }
  }));
  let refs = registry.collect(&schema, &union_fingerprints);
  assert_eq!(refs.len(), 1, "nested additional_properties array ref: expected 1 ref");
  assert!(refs.contains("VaccineRecord"), "should contain VaccineRecord via items");

  let schema = parse_schema(json!({
    "properties": {
      "name": {"type": "string"}
    },
    "additionalProperties": {
      "type": "array",
      "items": {
        "$ref": "#/components/schemas/Metric"
      }
    }
  }));
  let refs = registry.collect(&schema, &union_fingerprints);
  assert_eq!(refs.len(), 1, "properties + additional_properties: expected 1 ref");
  assert!(
    refs.contains("Metric"),
    "should contain Metric from additional_properties"
  );

  let schema = parse_schema(json!({
    "additionalProperties": true
  }));
  let refs = registry.collect(&schema, &union_fingerprints);
  assert!(refs.is_empty(), "boolean additional_properties: expected 0 refs");
}

#[test]
fn test_additional_properties_reachability() {
  let spec = spec_with_schemas(&json!({
    "VaccineRecord": {
      "type": "object",
      "required": ["date_administered"],
      "properties": {
        "date_administered": {"type": "string", "format": "date"},
        "veterinarian": {"type": "string"}
      }
    },
    "PetVaccinations": {
      "type": "object",
      "additionalProperties": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/VaccineRecord"
        }
      }
    }
  }));
  let mut stats = GenerationStats::default();
  let mut registry = SchemaRegistry::new(&spec, &mut stats);
  let union_fingerprints = UnionFingerprints::new();
  registry.build_dependencies(&union_fingerprints);

  let pet_vaccinations_deps = registry.collect(registry.get("PetVaccinations").unwrap(), &union_fingerprints);
  assert!(
    pet_vaccinations_deps.contains("VaccineRecord"),
    "PetVaccinations should depend on VaccineRecord via additionalProperties"
  );
}

#[test]
fn effective_mapping_synthesizes_from_cache() {
  let health_json = json!({
    "type": "object",
    "oneOf": [
      {"$ref": "#/components/schemas/Allergies"},
      {"$ref": "#/components/schemas/Diet"}
    ],
    "discriminator": {"propertyName": "type"}
  });
  let spec = spec_with_schemas(&json!({
    "Allergies": {
      "type": "object",
      "properties": {
        "type": {"type": "string", "const": "allergies"}
      },
      "required": ["type"]
    },
    "Diet": {
      "type": "object",
      "properties": {
        "type": {"type": "string", "const": "diet"}
      },
      "required": ["type"]
    },
    "Health": health_json.clone()
  }));

  let mut stats = GenerationStats::default();
  let registry = SchemaRegistry::new(&spec, &mut stats);

  let health: ObjectSchema = serde_json::from_value(health_json).expect("failed to parse health schema");
  let effective = registry.effective_mapping(&health);
  assert!(effective.is_some(), "effective mapping should be available");

  let mapping = effective.unwrap();
  assert_eq!(mapping.len(), 2, "should have 2 entries");
  assert_eq!(
    mapping.get("allergies").map(std::string::String::as_str),
    Some(format!("{SCHEMA_REF_PREFIX}Allergies").as_str()),
    "allergies value should map to Allergies ref"
  );
  assert_eq!(
    mapping.get("diet").map(std::string::String::as_str),
    Some(format!("{SCHEMA_REF_PREFIX}Diet").as_str()),
    "diet value should map to Diet ref"
  );
}