-
Notifications
You must be signed in to change notification settings - Fork 44
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
base: main
Are you sure you want to change the base?
x-ms-identifiers alternatives #1983
Conversation
All changed packages have been documented.
Show changes
|
You can try these changes here
|
There was a problem hiding this 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" |
There was a problem hiding this comment.
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": [ |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 }, |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 = ( |
There was a problem hiding this comment.
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.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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` | |||
|
There was a problem hiding this comment.
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", () => { |
There was a problem hiding this comment.
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.
issue: #1473