Skip to content

Documenting use of [contract] midl attribute for API versioning#406

Open
ChrisGuzak wants to merge 1 commit intoMicrosoftDocs:docsfrom
ChrisGuzak:docs
Open

Documenting use of [contract] midl attribute for API versioning#406
ChrisGuzak wants to merge 1 commit intoMicrosoftDocs:docsfrom
ChrisGuzak:docs

Conversation

@ChrisGuzak
Copy link
Contributor

This attribute is used for API versioning and is not specific to Windows SDK use. Document this fact.

@prmerger-automator
Copy link

@ChrisGuzak : Thanks for your contribution! The author(s) and reviewer(s) have been notified to review your proposed change.

@learn-build-service-prod
Copy link
Contributor

Learn Build status updates of commit e8239c5:

✅ Validation status: passed

File Status Preview URL Details
winrt-related-src/midl-3/predefined-attributes.md ✅Succeeded

For more details, please refer to the build report.

The `contract` attribute is used to version APIs; for example when creating a
Software Development Kit where strong contracts are needed. It indicates the API contract
name and two decimal values; `[contract(ContractName, LeftNumber.RightNumber)]`
with `RightNumber` being optional.
Copy link

Choose a reason for hiding this comment

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

Did you want to call these "Major" and "Minor" instead of left/right here, since you mention that's what they mean below? With this documentation there should probably be an "examples of use" conceptual page...

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 the paragraph is too much "inside baseball". Maybe

The contract attribute can be used to specify which version of an API contract the attributed type belongs to. The attribute takes the form [contract(ContractName, MajorVersion.MinorVersion)]. The MIDL compiler enforces some rules on contracts. Note that this list is not exhaustive.

  • The MajorVersion.MinorVersion may not be greater than the major and minor version specified in the [contractversion] attribute of the referenced apicontract.
  • A member of a runtimeclass may not have a lower contract number than the class itself.
  • A member of a runtimeclass may not refer to types from contracts lower than that of the member itself. (A member without an explicit contract is assumed to belong to the same contract as the containing runtimeclass.)

It appears before the item to which it applies and can apply to several artifacts
by using braces (`{}`) to group those parts of the API.

Designs that don't need versioning should not use this attribute, or should keep the
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 this is already covered in the opening paragraphs of this page.

If you're a component developer and/or a library author, then you may wish to use these attributes to ensure that your components remain binary-stable from one version to the next.

If you're an application developer, then in general you won't need to use these attributes because you'll recompile your application after revisioning your types.

The `contract` attribute is used to version APIs; for example when creating a
Software Development Kit where strong contracts are needed. It indicates the API contract
name and two decimal values; `[contract(ContractName, LeftNumber.RightNumber)]`
with `RightNumber` being optional.
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 the paragraph is too much "inside baseball". Maybe

The contract attribute can be used to specify which version of an API contract the attributed type belongs to. The attribute takes the form [contract(ContractName, MajorVersion.MinorVersion)]. The MIDL compiler enforces some rules on contracts. Note that this list is not exhaustive.

  • The MajorVersion.MinorVersion may not be greater than the major and minor version specified in the [contractversion] attribute of the referenced apicontract.
  • A member of a runtimeclass may not have a lower contract number than the class itself.
  • A member of a runtimeclass may not refer to types from contracts lower than that of the member itself. (A member without an explicit contract is assumed to belong to the same contract as the containing runtimeclass.)

@stevewhims
Copy link
Member

Thanks for this PR, it looks good! Once the feedback is actioned, I'll be ready to Merge. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants