Skip to content

fix(versioning): Preserve optionality changed from its declaration - #11968

Draft
Timothee Guerin (timotheeguerin) wants to merge 2 commits into
microsoft:mainfrom
timotheeguerin:fix/versioning-optionality-provenance
Draft

Timothee Guerin (timotheeguerin) wants to merge 2 commits into
microsoft:mainfrom
timotheeguerin:fix/versioning-optionality-provenance

Conversation

@timotheeguerin

@timotheeguerin Timothee Guerin (timotheeguerin) commented Sep 15, 2026

Copy link
Copy Markdown
Member

An optionality transformation can leave copied properties carrying versioning history that no longer describes them. This causes OptionalProperties<T> to reject @madeRequired properties, and spreading the result can make those properties required again in version snapshots.

This is the simple declaration-comparison alternative for #11592, independent of the structural-override prototype in #11969. These are alternatives, not stacked changes.

Versioning compares property.optional with property.node.optional. When they differ, it skips optionality diagnostics and preserves the transformed optionality when computing snapshots from the original graph. There is no helper-name special case, provenance tracking, extra state, or change to metadata getters.

model Source {
  @madeRequired(Versions.v2)
  foo: string;
}

model Patch {
  ...OptionalProperties<Source>;
}

Source.foo retains its version history; Patch.foo stays optional in every version. Property addition, removal, rename, and type history remain intact. Invalid optionality annotations on unchanged original declarations still diagnose.

Limitations: same-value transforms and transforms that restore the declared optionality are undetectable. New optionality augments on transformed copies are ignored for validation and snapshots too, because this rule cannot distinguish them from inherited annotations. Properties without a model-property declaration node cannot be identified as transformed. This draft intentionally demonstrates a bounded heuristic rather than a general transformation contract.

@pkg-pr-new

pkg-pr-new Bot commented Sep 15, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/versioning@11968

commit: 823e7f0

@github-actions

github-actions Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/versioning
Show changes

@typespec/versioning - fix ✏️

Preserve transformed property optionality in version snapshots and skip incompatible optionality diagnostics when the property differs from its original declaration, without special-casing transformation helpers.

@azure-sdk-automation

azure-sdk-automation Bot commented Sep 15, 2026

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@timotheeguerin Timothee Guerin (timotheeguerin) changed the title fix(versioning): Honor derived property optionality changes fix(versioning): Preserve optionality changed from its declaration Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant