Skip to content

Commit

Permalink
Add docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjprescott committed Feb 27, 2024
1 parent 4ced4e4 commit eb94be6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@azure-tools/typespec-azure-resource-manager"
---

Add `arm-avoid-additional-properties` rule.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: avoid-additional-properties
---

```text title=- Full name-
@azure-tools/typespec-azure-resource-manager/avoid-additional-properties
```

ARM requires Resource provider teams to define types explicitly. This is to ensure good customer experience in terms of the discoverability of concrete type definitions.

#### ❌ Incorrect

```tsp
model Address extends Record<string> {}
```

#### ✅ Correct

```tsp
model Address {
street: string;
city: string;
state: string;
country: string;
postalCode: string;
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ export const armAvoidAdditionalPropertiesRule = createRule({
name: "arm-avoid-additional-properties",
severity: "warning",
description: "Avoid use of additional properties in ARM resources.",
url: "https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/avoid-additional-properties",
messages: {
default: "...",
default:
"Definitions must not be of type Record. ARM requires Resource provider teams to define types explicitly.",
extends:
"Definitions must not extend type Record. ARM requires Resource provider teams to define types explicitly.",
is: "Definitions must not equate to type Record. ARM requires Resource provider teams to define types explicitly.",
},
create(context): SemanticNodeListener {
return {
Expand All @@ -26,12 +31,14 @@ export const armAvoidAdditionalPropertiesRule = createRule({
context.reportDiagnostic({
code: "arm-avoid-additional-properties",
target: model,
messageId: "extends",
});
}
if (model.sourceModel !== undefined && isRecordType(model.sourceModel)) {
context.reportDiagnostic({
code: "arm-avoid-additional-properties",
target: model,
messageId: "is",
});
}
},
Expand Down

0 comments on commit eb94be6

Please sign in to comment.