Skip to content
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

x-ms-identifiers alternatives #1983

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

AlitzelMendez
Copy link
Member

issue: #1473

@azure-sdk
Copy link
Collaborator

azure-sdk commented Dec 12, 2024

All changed packages have been documented.

  • @azure-tools/typespec-autorest
  • @azure-tools/typespec-azure-resource-manager
Show changes

@azure-tools/typespec-autorest - feature ✏️

Use the @Identifiers decorator to identify and utilize identifiers for x-ms-identifiers. Additionally, use the @key decorator to identify identifiers.

@azure-tools/typespec-azure-resource-manager - feature ✏️

Use the @Identifiers decorator to identify and utilize identifiers for x-ms-identifiers. Additionally, use the @key decorator to identify identifiers.

@azure-sdk
Copy link
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 📚 Next docs

@AlitzelMendez AlitzelMendez changed the title [WIP] x-ms-identifiers alternatives x-ms-identifiers alternatives Dec 17, 2024
@AlitzelMendez AlitzelMendez marked this pull request as ready for review December 17, 2024 17:46
Copy link
Member

@markcowl markcowl left a comment

Choose a reason for hiding this comment

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

A few changes - there is a subtlety that 'name' and 'id' properties remove the need for x-ms-identifiers.

Also, should have an up-to-date PR showing the changes this creates in azure-rest-api-specs repos

}
},
"x-ms-identifiers": [
"id"
Copy link
Member

Choose a reason for hiding this comment

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

We do not need to write x-ms-identifiers if there is an "id" or "name" property

@@ -1210,7 +1213,9 @@
"items": {
"$ref": "#/definitions/Widget"
},
"x-ms-identifiers": []
"x-ms-identifiers": [
Copy link
Member

Choose a reason for hiding this comment

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

See above. if the property is named "id" or "name", we should not add x-ms-identifiers

if (!ifArrayItemContainsIdentifier(program, typespecType as any)) {

const armIdentifiers = getArmIdentifiers(program, typespecType);
if (armIdentifiers !== undefined && armIdentifiers.length > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Here you should filter out "name" and "id" and ensure that no extension is written if one of those key properties exist

if (element === undefined || element.kind !== "Model") {
context.reportDiagnostic({
messageId: "missingProperty",
format: { propertyName: prop, targetModelName: element?.name },
Copy link
Member

Choose a reason for hiding this comment

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

"name" and "id" properties shoudll not cause this to execute, but should cause x-ms-identifiers to be omitted.

);
};

export function getArmIdentifiers(program: Program, entity: ArrayModelType): string[] | undefined {
Copy link
Member

Choose a reason for hiding this comment

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

Need documentation comments to generate docs for this accessor, and describe the parameters and return type

@@ -373,6 +376,93 @@ export const $armProviderNameValue: ArmProviderNameValueDecorator = (
}
};

export const $identifiers: IdentifiersDecorator = (
Copy link
Member

Choose a reason for hiding this comment

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

Need documentation comments to describe the use of the decorator and parameters

armIdentifiersIncorrectEntity:
"The @identifiers decorator must be applied to a property that is an array of objects",
armIdentifiersProperties:
"The @identifiers decorator expects a parameter that is an array of strings or an empty array as a parameter.",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"The @identifiers decorator expects a parameter that is an array of strings or an empty array as a parameter.",
"The @identifiers decorator expects a parameter that is an array of strings or an empty array.",

@@ -353,6 +354,22 @@ See more details on [different Azure Resource Manager resource type here.](https

None

#### `@identifiers`

Copy link
Member

Choose a reason for hiding this comment

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

See comments below - need jsdoc comment to generate this data

@@ -823,6 +823,161 @@ describe("typespec-autorest: extension decorator", () => {
});
});

describe("typespec-azure: identifiers decorator", () => {
Copy link
Member

Choose a reason for hiding this comment

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

Should add a test to verify that no extension is created when the object type contains a 'name' or 'id' property.

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