Skip to content

Commit

Permalink
Specify the fully qualified name of @OpenAPI.extension decorator in…
Browse files Browse the repository at this point in the history
… `missing-x-ms-identifiers` linter warning.

Signed-off-by: Michael Shen <[email protected]>
  • Loading branch information
mjlshen committed Apr 5, 2024
1 parent 19a31f7 commit ab3ae6d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .chronus/changes/604-2024-3-5-16-44-59.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@azure-tools/typespec-azure-resource-manager"
---

Specify the fully qualified name of `@OpenAPI.extension` decorator in `missing-x-ms-identifiers` linter warning.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export const missingXmsIdentifiersRule = createRule({
severity: "warning",
url: "https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/missing-x-ms-identifiers",
messages: {
default: `Missing identifying properties of objects in the array item, please add @extension("x-ms-identifiers", [<prop>]) to specify it. If there are no appropriate identifying properties, please add @extension("x-ms-identifiers",[]).`,
notArray: paramMessage`Value passed to @extension("x-ms-identifiers",...) was a "${"valueType"}". Pass an array of property name.`,
default: `Missing identifying properties of objects in the array item, please add @OpenAPI.extension("x-ms-identifiers", [<prop>]) to specify it. If there are no appropriate identifying properties, please add @OpenAPI.extension("x-ms-identifiers",[]).`,
notArray: paramMessage`Value passed to @OpenAPI.extension("x-ms-identifiers",...) was a "${"valueType"}". Pass an array of property name.`,
missingProperty: paramMessage`Property "${"propertyName"}" is not found in "${"targetModelName"}". Make sure value of x-ms-identifiers extension are valid property name of the array element.`,
},
create(context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("typespec-azure-core: no-enum rule", () => {
it("emit warning for array of model without x-ms-identifiers", async () => {
await tester
.expect(
`
`
model Foo {
bar: Bar[];
}
Expand All @@ -35,14 +35,14 @@ describe("typespec-azure-core: no-enum rule", () => {
)
.toEmitDiagnostics({
code: "@azure-tools/typespec-azure-resource-manager/missing-x-ms-identifiers",
message: `Missing identifying properties of objects in the array item, please add @extension("x-ms-identifiers", [<prop>]) to specify it. If there are no appropriate identifying properties, please add @extension("x-ms-identifiers",[]).`,
message: `Missing identifying properties of objects in the array item, please add @OpenAPI.extension("x-ms-identifiers", [<prop>]) to specify it. If there are no appropriate identifying properties, please add @OpenAPI.extension("x-ms-identifiers",[]).`,
});
});

it("emit warning if value is not a tuple", async () => {
await tester
.expect(
`
`
model Foo {
@OpenAPI.extension("x-ms-identifiers", "customName")
bar: Bar[];
Expand All @@ -55,14 +55,14 @@ describe("typespec-azure-core: no-enum rule", () => {
)
.toEmitDiagnostics({
code: "@azure-tools/typespec-azure-resource-manager/missing-x-ms-identifiers",
message: `Value passed to @extension("x-ms-identifiers",...) was a "string". Pass an array of property name.`,
message: `Value passed to @OpenAPI.extension("x-ms-identifiers",...) was a "string". Pass an array of property name.`,
});
});

it("emit diagnostic when x-ms-identifiers property names are not found in the target type", async () => {
await tester
.expect(
`
`
model Foo {
@OpenAPI.extension("x-ms-identifiers", ["not-a-prop"])
bar: Bar[];
Expand All @@ -82,7 +82,7 @@ describe("typespec-azure-core: no-enum rule", () => {
it(`doesn't emit diagnostic if @extension("x-ms-identifiers",...) is specified`, async () => {
await tester
.expect(
`
`
model Foo {
@OpenAPI.extension("x-ms-identifiers", ["customName"])
bar: Bar[];
Expand All @@ -98,7 +98,7 @@ describe("typespec-azure-core: no-enum rule", () => {
it(`doesn't emit diagnostic if element is a primitive type`, async () => {
await tester
.expect(
`
`
model Foo {
bar: Bar[];
}
Expand Down

0 comments on commit ab3ae6d

Please sign in to comment.