Skip to content

Fix API catalog $ref dereferencing and add $defs deduplication#1

Closed
jpage-godaddy wants to merge 2 commits into
rust-portfrom
fix-refs
Closed

Fix API catalog $ref dereferencing and add $defs deduplication#1
jpage-godaddy wants to merge 2 commits into
rust-portfrom
fix-refs

Conversation

@jpage-godaddy
Copy link
Copy Markdown
Owner

Summary

  • Fixes broken API catalog schemas: the committed rust/schemas/api/*.json had 587 unresolved external $refs across 16 of 20 domains, making godaddy api describe return broken schema references. The TypeScript generator produced zero external refs; now the Rust generator matches.
  • Adds $defs deduplication: instead of fully inlining every referenced schema at each use site, repeated schemas are lifted into a top-level $defs section and replaced with local {"$ref": "#/$defs/Name"} pointers. This is standard JSON Schema — any compliant reader resolves local refs. orders.json shrinks from ~60K lines to ~4K lines (−94%).

Root causes fixed

  • Local refs resolving to nodes that themselves contained $ref were never recursively dereferenced
  • Some spec repos store models at v2/models/ not v2/schemas/models/; added sibling-directory fallback
  • Spec files authored on macOS had wrong-case filenames (Bulkingestion.yaml vs BulkIngestion.yaml); added case-insensitive path fallback
  • Invalid YAML escape (\.) in double-quoted strings; added preprocessing on parse retry
  • Submodule content (transaction-models) was absent because clone used --depth 1 without --recurse-submodules; fixed

Size reduction from $defs deduplication

File Before (TS original) After Reduction
orders.json 59,837 lines 3,888 lines −94%
bulk-operations.json 17,592 lines 2,512 lines −86%
transactions.json 31,562 lines 4,122 lines −87%
metafields.json 11,939 lines 1,753 lines −85%

Schemas are include_str!'d at compile time, so smaller files mean a smaller binary.

Test plan

  • cargo test — 114 tests pass
  • cargo clippy -- -D warnings — clean
  • cargo fmt --check — clean
  • CI static check: grep -r '"[$]ref"' rust/schemas/api/*.json | grep -v '"#/' | wc -l returns 0
  • godaddy api describe orders list-orders — returns schemas with $ref: "#/$defs/..." local references (no broken file-path refs)

🤖 Generated with Claude Code

jpage-godaddy and others added 2 commits June 2, 2026 13:05
**Fix: unresolved external $refs (was: 587 broken refs across 16 domains)**

The generator was silently preserving unresolved $refs on failure. Root
causes fixed:
- Local refs resolving to nodes that themselves contained $ref were never
  recursively dereferenced; now a second dereference pass is applied
- Some spec repos store models at v2/models/ not v2/schemas/models/; added
  sibling-directory fallback in resolve_ref()
- Spec files authored on macOS had wrong-case filenames (e.g.
  Bulkingestion.yaml vs BulkIngestion.yaml); added case-insensitive path
  resolution fallback
- Invalid YAML escape (\.) in double-quoted strings; added preprocessing
  on parse retry
- Submodule content (transaction-models) was absent because clone used
  --depth 1 without --recurse-submodules; fixed

Added collect_unresolved_refs() post-generation validator that fails the
build loudly with a full list of unresolved refs instead of silently
producing broken output.

Added CI static check in cicd.yml that greps committed schemas for
unresolved external $refs on every PR.

**Improvement: $defs deduplication (was: Metafield inlined 167×, Error 136×)**

External file refs and local #/components/schemas/ refs are now lifted into
a top-level $defs section instead of being fully inlined at every use site.
The same ref URL produces one $defs entry; all occurrences become local
{"$ref": "#/$defs/Name"} pointers. This is standard JSON Schema — any
compliant reader resolves local refs.

Result: orders.json 59,837 → 3,888 lines (-94%), bulk-operations.json
17,592 → 2,512 lines (-86%). Smaller catalog files mean a smaller binary
(schemas are include_str!'d at compile time).

Added indexmap dependency for stable $defs insertion order.
Added 8 regression tests covering all new behaviors.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Escape $defs keys as JSON Pointer segments (RFC 6901) when formatting
  $ref strings; keys containing ~ or / would otherwise resolve incorrectly
- Handle \" inside YAML double-quoted scalars in fix_yaml_invalid_dot_escapes
  so an escaped quote doesn't prematurely terminate the scalar
- Rewrite CI $ref check using `if grep | grep -v; then exit 1; fi` to avoid
  pipefail triggering on zero matches (grep exits 1 when nothing matches)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jpage-godaddy
Copy link
Copy Markdown
Owner Author

Closing; real PR is godaddy#50

@jpage-godaddy jpage-godaddy deleted the fix-refs branch June 3, 2026 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant