UNPKG

@azure-tools/typespec-azure-resource-manager

Version:

TypeSpec Azure Resource Manager library

45 lines 2.12 kB
import { createRule, isKey, paramMessage } from "@typespec/compiler"; import { getArmResource } from "../resource.js"; import { getNamespaceName, getSourceModel } from "./utils.js"; export const armResourceEnvelopeProperties = createRule({ name: "arm-resource-invalid-envelope-property", severity: "warning", description: "Check for invalid resource envelope properties.", messages: { default: paramMessage `Property "${"propertyName"}" is not valid in the resource envelope. Please remove this property, or add it to the resource-specific property bag.`, }, create(context) { return { model: (model) => { const resourceModel = getArmResource(context.program, model); if (resourceModel !== undefined) { for (const property of getProperties(model)) { if (property.name !== "name" && !isKey(context.program, property)) { const sourceModel = getSourceModel(property); const sourceNamespace = getNamespaceName(context.program, sourceModel); if (sourceModel === undefined || sourceNamespace === undefined || !sourceNamespace.startsWith("Azure.ResourceManager")) { context.reportDiagnostic({ format: { propertyName: property.name }, target: property, }); } } } } }, }; function getProperties(model) { const result = []; let current = model; while (current !== undefined) { if (current.properties.size > 0) result.push(...current.properties.values()); current = current.baseModel; } return result; } }, }); //# sourceMappingURL=arm-resource-invalid-envelope-property.js.map