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

Specify the fully qualified name of @OpenAPI.extension decorator in missing-x-ms-identifiers linter warning #605

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -11,13 +11,13 @@ Check that array properties have `x-ms-identifiers` specified with `@OpenAPI.ext
#### ❌ Incorrect

```tsp
model Address [] {
model Address {
city: string;
street: string;
}

model ResourceProperties {
array: Address[]
array: Address[];
}
```

Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ Check that array properties have `x-ms-identifiers` specified with `@OpenAPI.ext
#### ❌ Incorrect

```tsp
model Address [] {
model Address {
city: string;
street: string;
}

model ResourceProperties {
array: Address[]
array: Address[];
}
```

Expand Down
Loading