Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
changeKind: feature
packages:
- "@azure-tools/typespec-azure-resource-manager"
- "@azure-tools/typespec-azure-rulesets"
---

Add the `request-body-must-be-object` ARM lint rule, migrated from the Swagger `ParametersSchemaAsTypeObject` validator rule and disabled by default in the resource-manager ruleset.
Comment thread
msyyc marked this conversation as resolved.
Outdated
1 change: 1 addition & 0 deletions packages/typespec-azure-resource-manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Available ruleSets:
| [`@azure-tools/typespec-azure-resource-manager/missing-operations-endpoint`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/missing-operations-endpoint) | Check for missing Operations interface. |
| [`@azure-tools/typespec-azure-resource-manager/patch-envelope`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/patch-envelope) | Patch envelope properties should match the resource properties. |
| [`@azure-tools/typespec-azure-resource-manager/arm-resource-patch`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/arm-resource-patch) | Validate ARM PATCH operations. |
| [`@azure-tools/typespec-azure-resource-manager/request-body-must-be-object`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/request-body-must-be-object) | Request bodies must resolve to object schemas. |
| [`@azure-tools/typespec-azure-resource-manager/resource-name`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/resource-name) | Check the resource name. |
| [`@azure-tools/typespec-azure-resource-manager/retry-after`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/retry-after) | Check if retry-after header appears in response body. |
| [`@azure-tools/typespec-azure-resource-manager/unsupported-type`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/unsupported-type) | Check for unsupported ARM types. |
Expand Down
2 changes: 2 additions & 0 deletions packages/typespec-azure-resource-manager/src/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { deleteOperationMissingRule } from "./rules/no-resource-delete-operation
import { noResponseBodyRule } from "./rules/no-response-body.js";
import { operationsInterfaceMissingRule } from "./rules/operations-interface-missing.js";
import { patchEnvelopePropertiesRules } from "./rules/patch-envelope-properties.js";
import { requestBodyMustBeObjectRule } from "./rules/request-body-must-be-object.js";
import { resourceNameRule } from "./rules/resource-name.js";
import { retryAfterRule } from "./rules/retry-after.js";
import { secretProprule } from "./rules/secret-prop.js";
Expand Down Expand Up @@ -83,6 +84,7 @@ const rules = [
operationsInterfaceMissingRule,
patchEnvelopePropertiesRules,
patchOperationsRule,
requestBodyMustBeObjectRule,
Comment thread
msyyc marked this conversation as resolved.
Outdated
resourceNameRule,
retryAfterRule,
unsupportedTypeRule,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Use an object model for every Azure Resource Manager request body that has an explicit schema type.

## Impact

- **Area:** API, SDK

Object request bodies can evolve by adding optional properties without changing the top-level wire shape. Primitive and array bodies cannot gain new fields without a breaking API and generated-SDK change.

Schemas without an explicit type, such as `unknown` and unsupported model unions, are outside this rule's scope. Nullable and singleton unions use their effective emitted schema type, while unions emitted as string or number enums are rejected. Operations without a request body are also allowed.

## Incorrect

```tsp
@post
op submit(@body body: string): void;

model ItemList is Array<string>;

@post
op submitItems(@body body: ItemList): void;

union ActionMode {
"fast",
"safe",
}

@post
op runAction(@body body: ActionMode): void;
```

## Correct

```tsp
model SubmitRequest {
value: string;
}

@post
op submit(@body body: SubmitRequest): void;

model SubmitItemsRequest {
items: string[];
}

@post
op submitItems(@body body: SubmitItemsRequest): void;

@post
op submitNullable(@body body: SubmitRequest | null): void;
```

## Suppression

Suppress only when required to preserve an existing API; otherwise replace the request body with an object model.

## LintDiff Equivalent

This rule corresponds to the Swagger validator rule [ParametersSchemaAsTypeObject](https://github.com/Azure/azure-openapi-validator/blob/main/docs/parameters-schema-as-type-object.md).
Comment thread
msyyc marked this conversation as resolved.
Outdated
Loading
Loading