Skip to content

[http] WIP, merge-patch implementation #7121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

witemple-msft
Copy link
Member

This work-in-progress PR implements the proposal for JSON merge-patch support in the HTTP core library.

Still to-do:

  • Make the resulting models immune from implicit optionality.
  • Add ability to track merge-patch source.
  • Add ability to check if a model is a merge-patch instance easily.
  • Documentation.

Copy link
Contributor

github-actions bot commented Apr 24, 2025

All changed packages have been documented.

  • @typespec/compiler
  • @typespec/http
Show changes

@typespec/compiler - fix ✏️

Weakened rules around @mediaTypeHint decorator, allowing media type hints with suffixes like "application/merge-patch+json".

@typespec/http - feature ✏️

Implemented JSON Merge-Patch wrappers. This allows converting a type to a JSON Merge-Patch compatible update record using the MergePatchUpdate and MergePatchCreateOrUpdate templates.

@typespec/compiler - feature ✏️

Exposed experimental function isMutableType as unsafe_isMutableType.

@azure-sdk
Copy link
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

if (isMutableType(member.type)) {
const variant: UnionVariant = {
...member,
type: mutateSubgraph(program, [self], member.type).type,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to apply CreateOrUpdate visibility to variants in the Update case, so feels like the optional mutator should be applied.

} else if ($(realm).record.is(model) && isMutableType(model.indexer!.value)) {
clone.indexer = {
key: model.indexer!.key,
value: mutateSubgraph(program, [self], model.indexer!.value).type,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For record types, we also want to apply CreateOrUpdate, so I think the optional mutator, because any key could exist or not in the resource.

@witemple-msft
Copy link
Member Author

Superseded by #7207

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.

3 participants