Skip to content

Remove resource must reference common types rule #525

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft.azure/openapi-validator-rulesets",
"comment": "Remove the ResourceMustReferenceCommonTypes rule",
"type": "patch"
}
],
"packageName": "@microsoft.azure/openapi-validator-rulesets"
}
17 changes: 0 additions & 17 deletions docs/resource-must-reference-common-types.md

This file was deleted.

8 changes: 1 addition & 7 deletions docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ Please refer to [operations-api-schema-uses-common-types.md](./operations-api-sc

### OperationsApiTenantLevelOnly

The get operation endpoint for the operations API must be scoped tenant-wide. Operations should _not_ vary per subscription.
The get operation endpoint for the operations API must be scoped tenant-wide. Operations **must not** vary per subscription.

Please refer to [operations-api-tenant-level-only.md](./operations-api-tenant-level-only.md) for details.

Expand Down Expand Up @@ -1046,12 +1046,6 @@ A 'Resource' definition must have x-ms-azure-resource extension enabled and set

Please refer to [resource-has-x-ms-resource-enabled.md](./resource-has-x-ms-resource-enabled.md) for details.

### ResourceMustReferenceCommonTypes

Validates that any resource definitions use the definitions for ProxyResource or TrackedResource already defined in the common types.

Please refer to [resource-must-reference-common-types.md](./resource-must-reference-common-types.md) for details.

### ResourceNameRestriction

This rule ensures that the authors explicitly define these restrictions as a regex on the resource name. If a team does not have custom rules then the ARM's default rule should get applied.
Expand Down
42 changes: 0 additions & 42 deletions packages/rulesets/generated/spectral/az-arm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2192,37 +2192,6 @@ const PutResponseSchemaDescription = (putResponseSchema, opts, ctx) => {
return errors;
};

const RESOURCE_COMMON_TYPES_REGEX = /.*common-types\/resource-management\/v\d+\/types.json#\/definitions\/(Proxy|Tracked)Resource/;
const resourceMustReferenceCommonTypes = (ref, _opts, ctx) => {
var _a, _b, _c, _d;
if (!ref) {
return [];
}
const swagger = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.documentInventory) === null || _a === void 0 ? void 0 : _a.resolved;
const definitions = swagger === null || swagger === void 0 ? void 0 : swagger.definitions;
if (!definitions) {
return [];
}
const resourceName = ref.toString().split("/").pop();
const allOfRef = (_c = (_b = definitions[resourceName]) === null || _b === void 0 ? void 0 : _b.properties) === null || _c === void 0 ? void 0 : _c.allOf;
const path = ["definitions", resourceName];
const error = [
{
message: `Resource definition '${resourceName}' must reference the common types resource definition for ProxyResource or TrackedResource.`,
path: path,
},
];
if (!allOfRef) {
return error;
}
for (const refObj of allOfRef) {
if ((_d = refObj.$ref) === null || _d === void 0 ? void 0 : _d.match(RESOURCE_COMMON_TYPES_REGEX)) {
return [];
}
}
return error;
};

const resourceNameRestriction = (paths, _opts, ctx) => {
if (paths === null || typeof paths !== "object") {
return [];
Expand Down Expand Up @@ -3064,17 +3033,6 @@ const ruleset = {
function: operationsApiTenantLevelOnly,
},
},
ResourceMustReferenceCommonTypes: {
description: "Resource definitions must use the common types TrackedResource or ProxyResource definitions.",
message: "{{error}}",
severity: "off",
resolved: false,
formats: [oas2],
given: ["$.paths.*.[get,put,patch].responses.200.schema.$ref"],
then: {
function: resourceMustReferenceCommonTypes,
},
},
ProvisioningStateMustBeReadOnly: {
description: "This is a rule introduced to validate if provisioningState property is set to readOnly or not.",
message: "{{error}}",
Expand Down
12 changes: 0 additions & 12 deletions packages/rulesets/src/spectral/az-arm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import { provisioningStateMustBeReadOnly } from "./functions/provisioning-state-
import putGetPatchScehma from "./functions/put-get-patch-schema"
import { putRequestResponseScheme } from "./functions/put-request-response-scheme"
import { PutResponseSchemaDescription } from "./functions/put-response-schema-description"
import { resourceMustReferenceCommonTypes } from "./functions/resource-must-reference-common-types"
import resourceNameRestriction from "./functions/resource-name-restriction"
import responseSchemaSpecifiedForSuccessStatusCode from "./functions/response-schema-specified-for-success-status-code"
import { securityDefinitionsStructure } from "./functions/security-definitions-structure"
Expand Down Expand Up @@ -744,17 +743,6 @@ const ruleset: any = {
/// ARM rules without an RPC code
///

ResourceMustReferenceCommonTypes: {
description: "Resource definitions must use the common types TrackedResource or ProxyResource definitions.",
message: "{{error}}",
severity: "off", // See https://github.com/Azure/azure-sdk-tools/issues/6071#issuecomment-1535560188
resolved: false,
formats: [oas2],
given: ["$.paths.*.[get,put,patch].responses.200.schema.$ref"],
then: {
function: resourceMustReferenceCommonTypes,
},
},
ProvisioningStateMustBeReadOnly: {
description: "This is a rule introduced to validate if provisioningState property is set to readOnly or not.",
message: "{{error}}",
Expand Down

This file was deleted.

This file was deleted.