Skip to content
Draft
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion docs/body-top-level-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ARM OpenAPI(swagger) specs
## Description

Top level properties should be one of `name`, `type`, `id`, `location`, `properties`, `tags`, `plan`, `sku`, `etag`,
`managedBy`, `identity`, `systemData`, `extendedlocation`. Per [ARM guidelines](https://github.com/cloud-and-ai-microsoft/resource-provider-contract/blob/master/v1.0/resource-api-reference.md),
`managedBy`, `managedByExtended`, `identity`, `kind`, `zones`, `systemData`, `extendedLocation`. Per [ARM guidelines](https://github.com/cloud-and-ai-microsoft/resource-provider-contract/blob/master/v1.0/resource-api-reference.md),
top level properties of a resource should be only ones from the allowed set.

## How to fix
Expand Down
2 changes: 1 addition & 1 deletion docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Please refer to [body-properties-names-camel-case.md](./body-properties-names-ca
### BodyTopLevelProperties

Top level properties should be one of `name`, `type`, `id`, `location`, `properties`, `tags`, `plan`, `sku`, `etag`,
`managedBy`, `identity`, `systemData`, `extendedlocation`. Per [ARM guidelines](https://github.com/cloud-and-ai-microsoft/resource-provider-contract/blob/master/v1.0/resource-api-reference.md),
`managedBy`, `managedByExtended`, `identity`, `kind`, `zones`, `systemData`, `extendedLocation`. Per [ARM guidelines](https://github.com/cloud-and-ai-microsoft/resource-provider-contract/blob/master/v1.0/resource-api-reference.md),
top level properties of a resource should be only ones from the allowed set.

Please refer to [body-top-level-properties.md](./body-top-level-properties.md) for details.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export function* armResourcePropertiesBag(openapiSection: any, options: {}, ctx:
"sku",
"etag",
"managedby",
"managedbyextended",
"identity",
"kind",
"zones",
Expand Down Expand Up @@ -144,6 +145,7 @@ export function* bodyTopLevelProperties(openapiSection: any, options: {}, ctx: R
"sku",
"etag",
"managedby",
"managedbyextended",
"identity",
"kind",
"zones",
Expand All @@ -155,7 +157,7 @@ export function* bodyTopLevelProperties(openapiSection: any, options: {}, ctx: R
if (!allowedBodyTopLevelProperties.includes(propName.toLowerCase())) {
yield {
location: ["definitions", re.modelName],
message: `Top level properties should be one of name, type, id, location, properties, tags, plan, sku, etag, managedBy, identity, zones. Model definition '${re.modelName}' has extra properties ['${propName}'].`,
message: `Top level properties should be one of name, type, id, location, properties, tags, plan, sku, etag, managedBy, managedByExtended, identity, kind, zones, systemData, extendedLocation. Model definition '${re.modelName}' has extra properties ['${propName}'].`,
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions packages/rulesets/src/native/tests/migrated-arm-rule-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ describe("IndividualAzureTests", () => {
assertValidationRuleCount(messages, ruleName, 1)
})

test("body top level resource with managedByExtended should pass", async () => {
const fileNames = ["body-top-level-properties-managedByExtended.json"]
const ruleName = "BodyTopLevelProperties"
const messages: LintResultMessage[] = await collectTestMessagesFromValidator(fileNames, OpenApiTypes.arm, ruleName)
assertValidationRuleCount(messages, ruleName, 0)
})

test("tracked resource must have patch", async () => {
const fileNames = ["armResource/trackedResourceNoPatch.json", "armResource/trackedResourceCommon.json"]
const ruleName = "TrackedResourcePatchOperation"
Expand Down
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot instead of creating a new json file for the test , can you just update one of the existing files to include these tests ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated! I've added the managedByExtended property to the existing body-top-level-properties-real-swagger.json file instead of creating a new test file. The separate test file has been removed and the test case now uses the updated existing file. All tests pass. (commit 90d4543)

Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
{
"swagger": "2.0",
"info": {
"title": "Test managedByExtended is allowed as a top level property",
"description": "Test case for managedByExtended property.",
"version": "2024-01-01"
},
"host": "management.azure.com",
"schemes": [
"https"
],
"basePath": "/",
"produces": [
"application/json"
],
"consumes": [
"application/json"
],
"paths": {
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Test/testResources/{resourceName}": {
"put": {
"operationId": "TestResources_CreateOrUpdate",
"summary": "Create or update test resource",
"description": "Creates or updates a test resource with managedByExtended property.",
"parameters": [
{
"name": "subscriptionId",
"in": "path",
"required": true,
"type": "string",
"description": "Subscription ID"
},
{
"name": "resourceGroupName",
"in": "path",
"required": true,
"type": "string",
"description": "Resource group name"
},
{
"name": "resourceName",
"in": "path",
"required": true,
"type": "string",
"description": "Resource name"
},
{
"name": "parameters",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/TestResource"
},
"description": "The parameters to provide for the test resource."
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/TestResource"
}
},
"201": {
"description": "Created",
"schema": {
"$ref": "#/definitions/TestResource"
}
}
}
},
"get": {
"operationId": "TestResources_Get",
"summary": "Get test resource",
"description": "Gets a test resource.",
"parameters": [
{
"name": "subscriptionId",
"in": "path",
"required": true,
"type": "string",
"description": "Subscription ID"
},
{
"name": "resourceGroupName",
"in": "path",
"required": true,
"type": "string",
"description": "Resource group name"
},
{
"name": "resourceName",
"in": "path",
"required": true,
"type": "string",
"description": "Resource name"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/TestResource"
}
}
}
},
"delete": {
"operationId": "TestResources_Delete",
"summary": "Delete test resource",
"description": "Deletes a test resource.",
"parameters": [
{
"name": "subscriptionId",
"in": "path",
"required": true,
"type": "string",
"description": "Subscription ID"
},
{
"name": "resourceGroupName",
"in": "path",
"required": true,
"type": "string",
"description": "Resource group name"
},
{
"name": "resourceName",
"in": "path",
"required": true,
"type": "string",
"description": "Resource name"
}
],
"responses": {
"200": {
"description": "OK"
},
"204": {
"description": "No Content"
}
}
},
"patch": {
"operationId": "TestResources_Update",
"summary": "Update test resource",
"description": "Updates a test resource.",
"parameters": [
{
"name": "subscriptionId",
"in": "path",
"required": true,
"type": "string",
"description": "Subscription ID"
},
{
"name": "resourceGroupName",
"in": "path",
"required": true,
"type": "string",
"description": "Resource group name"
},
{
"name": "resourceName",
"in": "path",
"required": true,
"type": "string",
"description": "Resource name"
},
{
"name": "parameters",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/TestResource"
},
"description": "The parameters to provide for the test resource."
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/TestResource"
}
}
}
}
},
"/providers/Microsoft.Test/operations": {
"get": {
"operationId": "Operations_List",
"summary": "List operations",
"description": "Lists all operations.",
"responses": {
"200": {
"description": "OK"
}
}
}
}
},
"definitions": {
"TestResource": {
"description": "Test resource with managedByExtended property",
"properties": {
"location": {
"type": "string",
"description": "Resource location"
},
"tags": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"description": "Resource tags"
},
"managedByExtended": {
"type": "array",
"items": {
"type": "string"
},
"description": "The fully qualified resource IDs of the resources that manage this resource"
},
"properties": {
"$ref": "#/definitions/TestResourceProperties"
}
},
"required": [
"location"
],
"allOf": [
{
"$ref": "#/definitions/Resource"
}
]
},
"TestResourceProperties": {
"description": "Properties of the test resource",
"properties": {
"provisioningState": {
"type": "string",
"description": "Provisioning state",
"readOnly": true
}
}
},
"Resource": {
"properties": {
"id": {
"readOnly": true,
"type": "string",
"description": "Resource Id"
},
"name": {
"readOnly": true,
"type": "string",
"description": "Resource name"
},
"type": {
"readOnly": true,
"type": "string",
"description": "Resource type"
}
},
"x-ms-azure-resource": true
}
},
"parameters": {
"SubscriptionIdParameter": {
"name": "subscriptionId",
"in": "path",
"required": true,
"type": "string",
"description": "test subscription id"
},
"ApiVersion": {
"name": "api-version",
"in": "path",
"required": true,
"type": "string",
"description": "test api version"
}
}
}