Skip to content

fix(normalize): keep portable schema IDs stable across unrelated root edits - #131

Merged
tanmaykm merged 1 commit into
mainfrom
tan/stable-schema-ids
Oct 2, 2026
Merged

tanmaykm merged 1 commit into
mainfrom
tan/stable-schema-ids

Conversation

@tanmaykm

@tanmaykm tanmaykm commented Oct 1, 2026

Copy link
Copy Markdown
Member

Fixes #117.

The primary schema resource label was "root-" * <digest of the whole root document>. In a single-file spec, every component schema lives under that resource. External labels are seeded from their parent's label, so any unrelated root edit, such as info.version or a description, rotated every ID in _SCHEMA_RESOURCE_DATA. That produced very large diffs in committed generated code.

The primary resource is now labelled "root". The schema IDs are scoped to each generated module's Spec, and the external- and resource- prefixes cannot collide with the constant label. Determinism and uniqueness are unchanged. Already-generated modules keep working, and regenerating changes their IDs once.

Tests

  • New testset in test/references.jl. For single-file and multi-file specs, it edits info and checks that the schema IDs and the emitted source are unchanged, except for the header and the embedded root document. This test fails on main.
  • Full suites pass on Julia 1.12 and 1.10. The full corpus (OPENAPI_CORPUS_TESTS=all) passes 32/32 on 1.12.

Known limitation (reviewer note, not addressed here)

An external- label is still seeded from the parent label, the reference-site pointer and the keyword. Renaming the location that references an external file, or adding an earlier-sorting reference to it, still relabels that file and anything reachable below it. Changes to the external schema's own content do not. The issue offers seeding on the target's content digest as an alternative, which would need collision suffixes. That can be a follow-up if needed.

The primary schema resource label was derived from a digest of the whole
root document, and referenced resource labels are seeded from their parent
label, so any unrelated root edit (info.version, a description) rotated
every schema ID in generated output. Label the primary resource "root".
Generated schema IDs are scoped to one module's Spec, and the "external-"
and "resource-" prefixes cannot collide with the constant label.

An external resource label still depends on the first reference site that
reaches it in sort order, so adding a reference to it at an earlier-sorting
location can relabel it.

Fixes #117
@tanmaykm
tanmaykm marked this pull request as ready for review October 1, 2026 06:03
@tanmaykm
tanmaykm requested review from krynju and nkottary October 1, 2026 06:51
@tanmaykm
tanmaykm merged commit 1234d43 into main Oct 2, 2026
5 checks passed
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.

Portable schema IDs cascade from the root document digest, so any root edit rotates every ID in generated output

2 participants