@azure-tools/typespec-azure-resource-manager 0.34.0-dev.3 → 0.34.0-dev.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/dist/src/index.d.ts +1 -1
  2. package/dist/src/index.d.ts.map +1 -1
  3. package/dist/src/index.js +1 -1
  4. package/dist/src/index.js.map +1 -1
  5. package/dist/src/lib.d.ts +89 -516
  6. package/dist/src/lib.d.ts.map +1 -1
  7. package/dist/src/lib.js +78 -171
  8. package/dist/src/lib.js.map +1 -1
  9. package/dist/src/namespace.d.ts.map +1 -1
  10. package/dist/src/namespace.js +15 -15
  11. package/dist/src/namespace.js.map +1 -1
  12. package/dist/src/operations.d.ts.map +1 -1
  13. package/dist/src/operations.js +6 -7
  14. package/dist/src/operations.js.map +1 -1
  15. package/dist/src/private.decorators.d.ts.map +1 -1
  16. package/dist/src/private.decorators.js +7 -8
  17. package/dist/src/private.decorators.js.map +1 -1
  18. package/dist/src/resource.d.ts.map +1 -1
  19. package/dist/src/resource.js +12 -12
  20. package/dist/src/resource.js.map +1 -1
  21. package/dist/src/rules/arm-resource-action-no-segment.d.ts +3 -1
  22. package/dist/src/rules/arm-resource-action-no-segment.d.ts.map +1 -1
  23. package/dist/src/rules/arm-resource-action-no-segment.js +9 -6
  24. package/dist/src/rules/arm-resource-action-no-segment.js.map +1 -1
  25. package/dist/src/rules/arm-resource-duplicate-property.d.ts +4 -0
  26. package/dist/src/rules/arm-resource-duplicate-property.d.ts.map +1 -0
  27. package/dist/src/rules/arm-resource-duplicate-property.js +43 -0
  28. package/dist/src/rules/arm-resource-duplicate-property.js.map +1 -0
  29. package/dist/src/rules/arm-resource-interfaces.d.ts +4 -0
  30. package/dist/src/rules/arm-resource-interfaces.d.ts.map +1 -0
  31. package/dist/src/rules/arm-resource-interfaces.js +26 -0
  32. package/dist/src/rules/arm-resource-interfaces.js.map +1 -0
  33. package/dist/src/rules/arm-resource-invalid-action-verb.d.ts +4 -0
  34. package/dist/src/rules/arm-resource-invalid-action-verb.d.ts.map +1 -0
  35. package/dist/src/rules/arm-resource-invalid-action-verb.js +28 -0
  36. package/dist/src/rules/arm-resource-invalid-action-verb.js.map +1 -0
  37. package/dist/src/rules/arm-resource-invalid-envelope-property.d.ts +4 -0
  38. package/dist/src/rules/arm-resource-invalid-envelope-property.d.ts.map +1 -0
  39. package/dist/src/rules/{arm-resource-properties.js → arm-resource-invalid-envelope-property.js} +13 -23
  40. package/dist/src/rules/arm-resource-invalid-envelope-property.js.map +1 -0
  41. package/dist/src/rules/arm-resource-invalid-version-format.d.ts +4 -1
  42. package/dist/src/rules/arm-resource-invalid-version-format.d.ts.map +1 -1
  43. package/dist/src/rules/arm-resource-invalid-version-format.js +12 -9
  44. package/dist/src/rules/arm-resource-invalid-version-format.js.map +1 -1
  45. package/dist/src/rules/arm-resource-key-invalid-chars.d.ts +4 -0
  46. package/dist/src/rules/arm-resource-key-invalid-chars.d.ts.map +1 -0
  47. package/dist/src/rules/arm-resource-key-invalid-chars.js +30 -0
  48. package/dist/src/rules/arm-resource-key-invalid-chars.js.map +1 -0
  49. package/dist/src/rules/arm-resource-operation-response.d.ts +4 -0
  50. package/dist/src/rules/arm-resource-operation-response.d.ts.map +1 -0
  51. package/dist/src/rules/{arm-resource-operations.js → arm-resource-operation-response.js} +24 -22
  52. package/dist/src/rules/arm-resource-operation-response.js.map +1 -0
  53. package/dist/src/rules/arm-resource-patch.d.ts +6 -0
  54. package/dist/src/rules/arm-resource-patch.d.ts.map +1 -0
  55. package/dist/src/rules/arm-resource-patch.js +108 -0
  56. package/dist/src/rules/arm-resource-patch.js.map +1 -0
  57. package/dist/src/rules/arm-resource-path-invalid-chars.d.ts +4 -0
  58. package/dist/src/rules/arm-resource-path-invalid-chars.d.ts.map +1 -0
  59. package/dist/src/rules/arm-resource-path-invalid-chars.js +37 -0
  60. package/dist/src/rules/arm-resource-path-invalid-chars.js.map +1 -0
  61. package/dist/src/rules/arm-resource-provisioning-state-rule.d.ts +4 -1
  62. package/dist/src/rules/arm-resource-provisioning-state-rule.d.ts.map +1 -1
  63. package/dist/src/rules/arm-resource-provisioning-state-rule.js +13 -11
  64. package/dist/src/rules/arm-resource-provisioning-state-rule.js.map +1 -1
  65. package/dist/src/rules/beyond-nesting-levels.d.ts +3 -1
  66. package/dist/src/rules/beyond-nesting-levels.d.ts.map +1 -1
  67. package/dist/src/rules/beyond-nesting-levels.js +10 -7
  68. package/dist/src/rules/beyond-nesting-levels.js.map +1 -1
  69. package/dist/src/rules/core-operations.d.ts +5 -1
  70. package/dist/src/rules/core-operations.d.ts.map +1 -1
  71. package/dist/src/rules/core-operations.js +19 -121
  72. package/dist/src/rules/core-operations.js.map +1 -1
  73. package/dist/src/rules/delete-operation.d.ts +3 -1
  74. package/dist/src/rules/delete-operation.d.ts.map +1 -1
  75. package/dist/src/rules/delete-operation.js +10 -7
  76. package/dist/src/rules/delete-operation.js.map +1 -1
  77. package/dist/src/rules/envelope-properties.d.ts +3 -1
  78. package/dist/src/rules/envelope-properties.d.ts.map +1 -1
  79. package/dist/src/rules/envelope-properties.js +12 -31
  80. package/dist/src/rules/envelope-properties.js.map +1 -1
  81. package/dist/src/rules/list-operation.d.ts +3 -1
  82. package/dist/src/rules/list-operation.d.ts.map +1 -1
  83. package/dist/src/rules/list-operation.js +9 -6
  84. package/dist/src/rules/list-operation.js.map +1 -1
  85. package/dist/src/rules/no-response-body.d.ts +3 -1
  86. package/dist/src/rules/no-response-body.d.ts.map +1 -1
  87. package/dist/src/rules/no-response-body.js +10 -7
  88. package/dist/src/rules/no-response-body.js.map +1 -1
  89. package/dist/src/rules/operations-interface-missing.d.ts +3 -1
  90. package/dist/src/rules/operations-interface-missing.d.ts.map +1 -1
  91. package/dist/src/rules/operations-interface-missing.js +12 -10
  92. package/dist/src/rules/operations-interface-missing.js.map +1 -1
  93. package/dist/src/rules/patch-envelope-properties.d.ts +4 -0
  94. package/dist/src/rules/patch-envelope-properties.d.ts.map +1 -0
  95. package/dist/src/rules/patch-envelope-properties.js +44 -0
  96. package/dist/src/rules/patch-envelope-properties.js.map +1 -0
  97. package/dist/src/rules/resource-name.d.ts +4 -1
  98. package/dist/src/rules/resource-name.d.ts.map +1 -1
  99. package/dist/src/rules/resource-name.js +14 -11
  100. package/dist/src/rules/resource-name.js.map +1 -1
  101. package/dist/src/rules/retry-after.d.ts +3 -1
  102. package/dist/src/rules/retry-after.d.ts.map +1 -1
  103. package/dist/src/rules/retry-after.js +10 -7
  104. package/dist/src/rules/retry-after.js.map +1 -1
  105. package/dist/src/rules/unsupported-types.d.ts +3 -1
  106. package/dist/src/rules/unsupported-types.d.ts.map +1 -1
  107. package/dist/src/rules/unsupported-types.js +9 -6
  108. package/dist/src/rules/unsupported-types.js.map +1 -1
  109. package/dist/src/rules/utils.d.ts +3 -1
  110. package/dist/src/rules/utils.d.ts.map +1 -1
  111. package/dist/src/rules/utils.js +18 -0
  112. package/dist/src/rules/utils.js.map +1 -1
  113. package/dist/src/state.d.ts +13 -0
  114. package/dist/src/state.d.ts.map +1 -0
  115. package/dist/src/state.js +20 -0
  116. package/dist/src/state.js.map +1 -0
  117. package/package.json +2 -4
  118. package/dist/src/linter.d.ts +0 -3
  119. package/dist/src/linter.d.ts.map +0 -1
  120. package/dist/src/linter.js +0 -42
  121. package/dist/src/linter.js.map +0 -1
  122. package/dist/src/rules/arm-resource-invalid-chars.d.ts +0 -2
  123. package/dist/src/rules/arm-resource-invalid-chars.d.ts.map +0 -1
  124. package/dist/src/rules/arm-resource-invalid-chars.js +0 -61
  125. package/dist/src/rules/arm-resource-invalid-chars.js.map +0 -1
  126. package/dist/src/rules/arm-resource-operations.d.ts +0 -2
  127. package/dist/src/rules/arm-resource-operations.d.ts.map +0 -1
  128. package/dist/src/rules/arm-resource-operations.js.map +0 -1
  129. package/dist/src/rules/arm-resource-properties.d.ts +0 -2
  130. package/dist/src/rules/arm-resource-properties.d.ts.map +0 -1
  131. package/dist/src/rules/arm-resource-properties.js.map +0 -1
@@ -1,25 +1,28 @@
1
- import { getEffectiveModelType, isErrorType } from "@typespec/compiler";
2
- import { createRule } from "@typespec/lint";
3
- import { reportDiagnostic } from "../lib.js";
1
+ import { createRule, getEffectiveModelType, isErrorType, } from "@typespec/compiler";
4
2
  import { resolveResourceOperations } from "../operations.js";
5
3
  import { getArmResource } from "../resource.js";
6
4
  import { isInternalTypeSpec } from "./utils.js";
7
5
  export const armResourceOperationsRule = createRule({
8
- name: "arm-resource-operations",
9
- create({ program }) {
6
+ name: "arm-resource-operation-response",
7
+ severity: "warning",
8
+ description: "[RPC 008]: PUT, GET, PATCH & LIST must return the same resource schema.",
9
+ messages: {
10
+ default: "[RPC 008]: PUT, GET, PATCH & LIST must return the same resource schema.",
11
+ },
12
+ create(context) {
10
13
  return {
11
14
  model: (model) => {
12
- if (!isInternalTypeSpec(program, model)) {
13
- const armResource = getArmResource(program, model);
15
+ if (!isInternalTypeSpec(context.program, model)) {
16
+ const armResource = getArmResource(context.program, model);
14
17
  if (armResource) {
15
- const resourceOperations = resolveResourceOperations(program, model);
18
+ const resourceOperations = resolveResourceOperations(context.program, model);
16
19
  const kinds = ["read", "createOrUpdate", "update"];
17
20
  kinds
18
21
  .map((k) => resourceOperations.lifecycle[k])
19
- .forEach((op) => op && checkArmResourceOperationReturnType(program, model, op.operation));
22
+ .forEach((op) => op && checkArmResourceOperationReturnType(context, model, op.operation));
20
23
  const lists = resourceOperations.lists;
21
24
  for (const key in lists) {
22
- checkArmResourceOperationReturnType(program, model, lists[key].operation);
25
+ checkArmResourceOperationReturnType(context, model, lists[key].operation);
23
26
  }
24
27
  }
25
28
  }
@@ -27,27 +30,27 @@ export const armResourceOperationsRule = createRule({
27
30
  };
28
31
  },
29
32
  });
30
- function checkArmResourceOperationReturnType(program, model, operation) {
31
- if (!isInternalTypeSpec(program, operation)) {
33
+ function checkArmResourceOperationReturnType(context, model, operation) {
34
+ if (!isInternalTypeSpec(context.program, operation)) {
32
35
  const returnType = operation.returnType;
33
36
  if (returnType.kind === "Model") {
34
- checkIfArmModel(program, operation, model, returnType);
37
+ checkIfArmModel(context, operation, model, returnType);
35
38
  }
36
39
  else if (returnType.kind === "Union") {
37
40
  for (const variant of returnType.variants.values()) {
38
41
  if (!isErrorType(variant.type) && variant.type.kind === "Model") {
39
- const modelCandidate = getEffectiveModelType(program, variant.type);
40
- checkIfArmModel(program, operation, model, modelCandidate);
42
+ const modelCandidate = getEffectiveModelType(context.program, variant.type);
43
+ checkIfArmModel(context, operation, model, modelCandidate);
41
44
  if (modelCandidate.templateMapper !== undefined) {
42
45
  // ArmResponse<FooResource>
43
46
  for (const arg of modelCandidate.templateMapper.args) {
44
47
  if (arg.kind === "Model") {
45
- checkIfArmModel(program, operation, model, arg);
48
+ checkIfArmModel(context, operation, model, arg);
46
49
  if (arg.templateMapper !== undefined) {
47
50
  // ArmResponse<ResourceListResult<FooResource>>
48
51
  for (const type of arg.templateMapper.args) {
49
52
  if (type.kind === "Model") {
50
- checkIfArmModel(program, operation, model, type);
53
+ checkIfArmModel(context, operation, model, type);
51
54
  }
52
55
  }
53
56
  }
@@ -59,12 +62,11 @@ function checkArmResourceOperationReturnType(program, model, operation) {
59
62
  }
60
63
  }
61
64
  }
62
- function checkIfArmModel(program, operation, model, modelCandidate) {
63
- if (getArmResource(program, modelCandidate) && modelCandidate !== model) {
64
- reportDiagnostic(program, {
65
- code: "arm-resource-operation-response",
65
+ function checkIfArmModel(context, operation, model, modelCandidate) {
66
+ if (getArmResource(context.program, modelCandidate) && modelCandidate !== model) {
67
+ context.reportDiagnostic({
66
68
  target: operation,
67
69
  });
68
70
  }
69
71
  }
70
- //# sourceMappingURL=arm-resource-operations.js.map
72
+ //# sourceMappingURL=arm-resource-operation-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arm-resource-operation-response.js","sourceRoot":"","sources":["../../../src/rules/arm-resource-operation-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,UAAU,EACV,qBAAqB,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Ae,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;yCAClD;qCACF;iCACF;6BACF;yBACF;qBACF;iBACF;aACF;SACF;KACF;AACH,CAAC;AAED,SAAS,eAAe,CACtB,OAA8C,EAC9C,SAAoB,EACpB,KAAY,EACZ,cAAqB;IAErB,IAAI,cAAc,CAAC,OAAO,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,cAAc,KAAK,KAAK,EAAE;QAC/E,OAAO,CAAC,gBAAgB,CAAC;YACvB,MAAM,EAAE,SAAS;SAClB,CAAC,CAAC;KACJ;AACH,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare const patchOperationsRule: import("@typespec/compiler").LinterRuleDefinition<"arm-resource-patch", {
2
+ readonly default: "The request body of a PATCH must be a model with a subset of resource properties";
3
+ readonly missingTags: "Resource PATCH must contain the 'tags' property.";
4
+ readonly modelSuperset: import("@typespec/compiler").CallableMessage<[string, string]>;
5
+ }>;
6
+ //# sourceMappingURL=arm-resource-patch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arm-resource-patch.d.ts","sourceRoot":"","sources":["../../../src/rules/arm-resource-patch.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,mBAAmB;;;;EAwB9B,CAAC"}
@@ -0,0 +1,108 @@
1
+ import { createRule, getEffectiveModelType, getProperty, isErrorType, paramMessage, } from "@typespec/compiler";
2
+ import { getOperationVerb, isBody, isHeader, isPathParam, isQueryParam } from "@typespec/http";
3
+ import { getArmResource } from "../resource.js";
4
+ import { getSourceModel, isInternalTypeSpec } from "./utils.js";
5
+ export const patchOperationsRule = createRule({
6
+ name: "arm-resource-patch",
7
+ severity: "warning",
8
+ description: "Validate ARM PATCH operations.",
9
+ messages: {
10
+ default: "The request body of a PATCH must be a model with a subset of resource properties",
11
+ missingTags: "Resource PATCH must contain the 'tags' property.",
12
+ modelSuperset: paramMessage `Resource PATCH models must be a subset of the resource type. The following properties: [${"name"}] do not exist in resource Model '${"resourceModel"}'.`,
13
+ },
14
+ create(context) {
15
+ return {
16
+ operation: (operation) => {
17
+ if (!isInternalTypeSpec(context.program, operation)) {
18
+ const verb = getOperationVerb(context.program, operation);
19
+ if (verb === "patch") {
20
+ const resourceType = getResourceModel(context.program, operation);
21
+ if (resourceType) {
22
+ checkPatchModel(context, operation, resourceType);
23
+ }
24
+ }
25
+ }
26
+ },
27
+ };
28
+ },
29
+ });
30
+ function checkPatchModel(context, operation, resourceType) {
31
+ const patchModel = getPatchModel(context.program, operation);
32
+ if (patchModel === undefined) {
33
+ context.reportDiagnostic({
34
+ target: operation,
35
+ });
36
+ }
37
+ else if (resourceType.properties.has("tags") &&
38
+ !patchModel.some((p) => p.name === "tags" && p.type.kind === "Model")) {
39
+ context.reportDiagnostic({
40
+ messageId: "missingTags",
41
+ target: operation,
42
+ });
43
+ }
44
+ else {
45
+ const resourceProperties = resourceType.properties.get("properties");
46
+ const badProperties = [];
47
+ for (const property of patchModel) {
48
+ const sourceModel = getSourceModel(property);
49
+ if (sourceModel === undefined || !getArmResource(context.program, sourceModel)) {
50
+ if (!getProperty(resourceType, property.name) &&
51
+ (resourceProperties === undefined ||
52
+ resourceProperties.type.kind !== "Model" ||
53
+ !getProperty(resourceProperties.type, property.name))) {
54
+ badProperties.push(property);
55
+ }
56
+ }
57
+ }
58
+ if (badProperties.length > 0)
59
+ context.reportDiagnostic({
60
+ messageId: "modelSuperset",
61
+ format: {
62
+ name: badProperties.flatMap((t) => t.name).join(", "),
63
+ resourceModel: resourceType.name,
64
+ },
65
+ target: operation,
66
+ });
67
+ }
68
+ }
69
+ function getResourceModel(program, operation) {
70
+ const returnType = operation.returnType;
71
+ if (returnType.kind === "Union") {
72
+ for (const variant of returnType.variants.values()) {
73
+ if (!isErrorType(variant.type) && variant.type.kind === "Model") {
74
+ const modelCandidate = getEffectiveModelType(program, variant.type);
75
+ if (getArmResource(program, modelCandidate)) {
76
+ return modelCandidate;
77
+ }
78
+ if (modelCandidate.templateMapper !== undefined) {
79
+ for (const arg of modelCandidate.templateMapper.args) {
80
+ if (arg.kind === "Model" && getArmResource(program, arg)) {
81
+ return arg;
82
+ }
83
+ }
84
+ }
85
+ }
86
+ }
87
+ }
88
+ return undefined;
89
+ }
90
+ function getPatchModel(program, operation) {
91
+ const bodyProperties = [];
92
+ const patchModel = getEffectiveModelType(program, operation.parameters);
93
+ for (const [_, property] of patchModel.properties) {
94
+ if (isHeader(program, property) ||
95
+ isQueryParam(program, property) ||
96
+ isPathParam(program, property))
97
+ continue;
98
+ if (isBody(program, property) && property.type.kind === "Scalar")
99
+ return undefined;
100
+ bodyProperties.push(property);
101
+ }
102
+ if (bodyProperties.length === 0)
103
+ return undefined;
104
+ if (bodyProperties.length === 1 && bodyProperties[0].type.kind === "Model")
105
+ return [...bodyProperties[0].type.properties.values()];
106
+ return bodyProperties;
107
+ }
108
+ //# sourceMappingURL=arm-resource-patch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arm-resource-patch.js","sourceRoot":"","sources":["../../../src/rules/arm-resource-patch.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,UAAU,EACV,qBAAqB,EACrB,WAAW,EACX,WAAW,EACX,YAAY,GACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE/F,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhE,MAAM,CAAC,MAAM,mBAAmB,GAAG,UAAU,CAAC;IAC5C,IAAI,EAAE,oBAAoB;IAC1B,QAAQ,EAAE,SAAS;IACnB,WAAW,EAAE,gCAAgC;IAC7C,QAAQ,EAAE;QACR,OAAO,EAAE,kFAAkF;QAC3F,WAAW,EAAE,kDAAkD;QAC/D,aAAa,EAAE,YAAY,CAAA,2FAA2F,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CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;IACzD,OAAO,cAAc,CAAC;AACxB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare const armResourcePathInvalidCharsRule: import("@typespec/compiler").LinterRuleDefinition<"arm-resource-path-segment-invalid-chars", {
2
+ readonly default: import("@typespec/compiler").CallableMessage<[string]>;
3
+ }>;
4
+ //# sourceMappingURL=arm-resource-path-invalid-chars.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arm-resource-path-invalid-chars.d.ts","sourceRoot":"","sources":["../../../src/rules/arm-resource-path-invalid-chars.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,+BAA+B;;EA6B1C,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { createRule, paramMessage } from "@typespec/compiler";
2
+ import { getSegment } from "@typespec/rest";
3
+ import { getDecoratorParam, isInternalTypeSpec, isResource, isValidKey } from "./utils.js";
4
+ export const armResourcePathInvalidCharsRule = createRule({
5
+ name: "arm-resource-path-segment-invalid-chars",
6
+ severity: "warning",
7
+ description: "Arm resource name must contain only alphanumeric characters.",
8
+ messages: {
9
+ default: paramMessage `'${"segment"}' is an invalid path segment. Segments may start with a separator must consist of alphanumeric characters or dashes, starting with a lower case letter.`,
10
+ },
11
+ create(context) {
12
+ return {
13
+ model: (model) => {
14
+ var _a, _b;
15
+ if (!isInternalTypeSpec(context.program, model) &&
16
+ isResource(model) &&
17
+ model.properties.has("name")) {
18
+ const nameProperty = model.properties.get("name");
19
+ const separator = "/";
20
+ const segment = getSegment(context.program, nameProperty);
21
+ if (segment !== undefined && !isValidPathSegment(segment, separator)) {
22
+ context.reportDiagnostic({
23
+ format: { segment: segment },
24
+ target: (_b = (_a = getDecoratorParam(nameProperty, "segment")) === null || _a === void 0 ? void 0 : _a.node) !== null && _b !== void 0 ? _b : nameProperty,
25
+ });
26
+ }
27
+ }
28
+ },
29
+ };
30
+ },
31
+ });
32
+ function isValidPathSegment(path, separator) {
33
+ if (path.startsWith(separator))
34
+ path = path.replace(separator, "");
35
+ return isValidKey(path);
36
+ }
37
+ //# sourceMappingURL=arm-resource-path-invalid-chars.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arm-resource-path-invalid-chars.js","sourceRoot":"","sources":["../../../src/rules/arm-resource-path-invalid-chars.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,UAAU,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEpF,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE3F,MAAM,CAAC,MAAM,+BAA+B,GAAG,UAAU,CAAC;IACxD,IAAI,EAAE,yCAAyC;IAC/C,QAAQ,EAAE,SAAS;IACnB,WAAW,EAAE,8DAA8D;IAC3E,QAAQ,EAAE;QACR,OAAO,EAAE,YAAY,CAAA,IAAI,SAAS,yJAAyJ;KAC5L;IACD,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,KAAK,EAAE,CAAC,KAAY,EAAE,EAAE;;gBACtB,IACE,CAAC,kBAAkB,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC;oBAC3C,UAAU,CAAC,KAAK,CAAC;oBACjB,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,EAC5B;oBACA,MAAM,YAAY,GAAkB,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAE,CAAC;oBAClE,MAAM,SAAS,GAAG,GAAG,CAAC;oBACtB,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;oBAE1D,IAAI,OAAO,KAAK,SAAS,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE;wBACpE,OAAO,CAAC,gBAAgB,CAAC;4BACvB,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE;4BAC5B,MAAM,EAAE,MAAA,MAAA,iBAAiB,CAAC,YAAY,EAAE,SAAS,CAAC,0CAAE,IAAI,mCAAI,YAAY;yBACzE,CAAC,CAAC;qBACJ;iBACF;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC;AAEH,SAAS,kBAAkB,CAAC,IAAY,EAAE,SAAiB;IACzD,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IACnE,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -1,2 +1,5 @@
1
- export declare const armResourceProvisioningStateRule: import("@typespec/lint").LintRule;
1
+ export declare const armResourceProvisioningStateRule: import("@typespec/compiler").LinterRuleDefinition<"arm-resource-provisioning-state", {
2
+ readonly default: "The RP-specific property model in the 'properties' property of this resource must contain a 'provisioningState property. The property type should be an enum, and it must specify known state values 'Succeeded', 'Failed', and 'Canceled'.";
3
+ readonly missingValues: import("@typespec/compiler").CallableMessage<[string]>;
4
+ }>;
2
5
  //# sourceMappingURL=arm-resource-provisioning-state-rule.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"arm-resource-provisioning-state-rule.d.ts","sourceRoot":"","sources":["../../../src/rules/arm-resource-provisioning-state-rule.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,gCAAgC,mCAsD3C,CAAC"}
1
+ {"version":3,"file":"arm-resource-provisioning-state-rule.d.ts","sourceRoot":"","sources":["../../../src/rules/arm-resource-provisioning-state-rule.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,gCAAgC;;;EA2D3C,CAAC"}
@@ -1,15 +1,19 @@
1
- import { getProperty } from "@typespec/compiler";
2
- import { createRule } from "@typespec/lint";
3
- import { reportDiagnostic } from "../lib.js";
1
+ import { createRule, getProperty, paramMessage } from "@typespec/compiler";
4
2
  import { getArmResource } from "../resource.js";
5
3
  import { getSourceProperty } from "./utils.js";
6
4
  export const armResourceProvisioningStateRule = createRule({
7
5
  name: "arm-resource-provisioning-state",
8
- create({ program }) {
6
+ severity: "warning",
7
+ description: "Check for properly configured provisioningState property.",
8
+ messages: {
9
+ default: "The RP-specific property model in the 'properties' property of this resource must contain a 'provisioningState property. The property type should be an enum, and it must specify known state values 'Succeeded', 'Failed', and 'Canceled'.",
10
+ missingValues: paramMessage `The "@knownValues" decorator for provisioningState, must reference an enum with 'Succeeded', 'Failed', 'Canceled' values. The enum is missing the values: [${"missingValues"}].`,
11
+ },
12
+ create(context) {
9
13
  return {
10
14
  model: (model) => {
11
15
  var _a;
12
- const resourceModel = getArmResource(program, model);
16
+ const resourceModel = getArmResource(context.program, model);
13
17
  if (resourceModel === undefined) {
14
18
  return;
15
19
  }
@@ -19,8 +23,7 @@ export const armResourceProvisioningStateRule = createRule({
19
23
  }
20
24
  let provisioning = getProperty(resourceProperties, "provisioningState");
21
25
  if (provisioning === undefined) {
22
- reportDiagnostic(program, {
23
- code: "arm-resource-provisioning-state",
26
+ context.reportDiagnostic({
24
27
  target: resourceProperties,
25
28
  });
26
29
  }
@@ -41,16 +44,15 @@ export const armResourceProvisioningStateRule = createRule({
41
44
  missing.push("Failed");
42
45
  }
43
46
  if (missing.length > 0) {
44
- reportDiagnostic(program, {
45
- code: "arm-resource-provisioning-state-values",
47
+ context.reportDiagnostic({
48
+ messageId: "missingValues",
46
49
  format: { missingValues: missing.join(", ") },
47
50
  target: enumType,
48
51
  });
49
52
  }
50
53
  break;
51
54
  default:
52
- reportDiagnostic(program, {
53
- code: "arm-resource-provisioning-state",
55
+ context.reportDiagnostic({
54
56
  target: provisioning,
55
57
  });
56
58
  }
@@ -1 +1 @@
1
- {"version":3,"file":"arm-resource-provisioning-state-rule.js","sourceRoot":"","sources":["../../../src/rules/arm-resource-provisioning-state-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,WAAW,EAAS,MAAM,oBAAoB,CAAC;AAC9D,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gCACtC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;6BAC3B;4BACD,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;gCACrC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;6BAC1B;4BACD,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;gCACnC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;6BACxB;4BACD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE;gCACtB,gBAAgB,CAAC,OAAO,EAAE;oCACxB,IAAI,EAAE,wCAAwC;oCAC9C,MAAM,EAAE,EAAE,aAAa,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;oCAC7C,MAAM,EAAE,QAAQ;iCACjB,CAAC,CAAC;6BACJ;4BACD,MAAM;wBACR;4BACE,gBAAgB,CAAC,OAAO,EAAE;gCACxB,IAAI,EAAE,iCAAiC;gCACvC,MAAM,EAAE,YAAY;6BACrB,CAAC,CAAC;qBACN;iBACF;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
1
+ {"version":3,"file":"arm-resource-provisioning-state-rule.js","sourceRoot":"","sources":["../../../src/rules/arm-resource-provisioning-state-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAExF,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,MAAM,CAAC,MAAM,gCAAgC,GAAG,UAAU,CAAC;IACzD,IAAI,EAAE,iCAAiC;IACvC,QAAQ,EAAE,SAAS;IACnB,WAAW,EAAE,2DAA2D;IACxE,QAAQ,EAAE;QACR,OAAO,EACL,8OAA8O;QAChP,aAAa,EAAE,YAAY,CAAA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,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;6BACxB;4BACD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE;gCACtB,OAAO,CAAC,gBAAgB,CAAC;oCACvB,SAAS,EAAE,eAAe;oCAC1B,MAAM,EAAE,EAAE,aAAa,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;oCAC7C,MAAM,EAAE,QAAQ;iCACjB,CAAC,CAAC;6BACJ;4BACD,MAAM;wBACR;4BACE,OAAO,CAAC,gBAAgB,CAAC;gCACvB,MAAM,EAAE,YAAY;6BACrB,CAAC,CAAC;qBACN;iBACF;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
@@ -1,5 +1,7 @@
1
1
  /**
2
2
  * verify if resource nesting beyond 3 levels
3
3
  */
4
- export declare const beyondNestingRule: import("@typespec/lint").LintRule;
4
+ export declare const beyondNestingRule: import("@typespec/compiler").LinterRuleDefinition<"beyond-nesting-levels", {
5
+ readonly default: "Tracked Resources must use 3 or fewer levels of nesting.";
6
+ }>;
5
7
  //# sourceMappingURL=beyond-nesting-levels.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"beyond-nesting-levels.d.ts","sourceRoot":"","sources":["../../../src/rules/beyond-nesting-levels.ts"],"names":[],"mappings":"AAMA;;GAEG;AAEH,eAAO,MAAM,iBAAiB,mCA2B5B,CAAC"}
1
+ {"version":3,"file":"beyond-nesting-levels.d.ts","sourceRoot":"","sources":["../../../src/rules/beyond-nesting-levels.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH,eAAO,MAAM,iBAAiB;;EA+B5B,CAAC"}
@@ -1,13 +1,17 @@
1
- import { createRule } from "@typespec/lint";
1
+ import { createRule } from "@typespec/compiler";
2
2
  import { getParentResource } from "@typespec/rest";
3
- import { reportDiagnostic } from "../lib.js";
4
3
  import { isTrackedResource } from "./utils.js";
5
4
  /**
6
5
  * verify if resource nesting beyond 3 levels
7
6
  */
8
7
  export const beyondNestingRule = createRule({
9
- name: "beyond-nesting",
10
- create({ program }) {
8
+ name: "beyond-nesting-levels",
9
+ severity: "warning",
10
+ description: "Tracked Resources must use 3 or fewer levels of nesting.",
11
+ messages: {
12
+ default: "Tracked Resources must use 3 or fewer levels of nesting.",
13
+ },
14
+ create(context) {
11
15
  return {
12
16
  model: (model) => {
13
17
  let levels = 1;
@@ -16,7 +20,7 @@ export const beyondNestingRule = createRule({
16
20
  }
17
21
  let parent = model;
18
22
  while (levels < 4) {
19
- parent = getParentResource(program, parent);
23
+ parent = getParentResource(context.program, parent);
20
24
  if (parent) {
21
25
  levels++;
22
26
  }
@@ -25,8 +29,7 @@ export const beyondNestingRule = createRule({
25
29
  }
26
30
  }
27
31
  if (levels === 4) {
28
- reportDiagnostic(program, {
29
- code: "beyond-nesting-levels",
32
+ context.reportDiagnostic({
30
33
  target: model,
31
34
  });
32
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"beyond-nesting-levels.js","sourceRoot":"","sources":["../../../src/rules/beyond-nesting-levels.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C;;GAEG;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC;IAC1C,IAAI,EAAE,gBAAgB;IACtB,MAAM,CAAC,EAAE,OAAO,EAAE;QAChB,OAAO;YACL,KAAK,EAAE,CAAC,KAAY,EAAE,EAAE;gBACtB,IAAI,MAAM,GAAG,CAAC,CAAC;gBACf,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE;oBAC7B,OAAO;iBACR;gBACD,IAAI,MAAM,GAAsB,KAAK,CAAC;gBACtC,OAAO,MAAM,GAAG,CAAC,EAAE;oBACjB,MAAM,GAAG,iBAAiB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;oBAC5C,IAAI,MAAM,EAAE;wBACV,MAAM,EAAE,CAAC;qBACV;yBAAM;wBACL,MAAM;qBACP;iBACF;gBACD,IAAI,MAAM,KAAK,CAAC,EAAE;oBAChB,gBAAgB,CAAC,OAAO,EAAE;wBACxB,IAAI,EAAE,uBAAuB;wBAC7B,MAAM,EAAE,KAAK;qBACd,CAAC,CAAC;iBACJ;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
1
+ {"version":3,"file":"beyond-nesting-levels.js","sourceRoot":"","sources":["../../../src/rules/beyond-nesting-levels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C;;GAEG;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC;IAC1C,IAAI,EAAE,uBAAuB;IAC7B,QAAQ,EAAE,SAAS;IACnB,WAAW,EAAE,0DAA0D;IACvE,QAAQ,EAAE;QACR,OAAO,EAAE,0DAA0D;KACpE;IACD,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,KAAK,EAAE,CAAC,KAAY,EAAE,EAAE;gBACtB,IAAI,MAAM,GAAG,CAAC,CAAC;gBACf,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE;oBAC7B,OAAO;iBACR;gBACD,IAAI,MAAM,GAAsB,KAAK,CAAC;gBACtC,OAAO,MAAM,GAAG,CAAC,EAAE;oBACjB,MAAM,GAAG,iBAAiB,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;oBACpD,IAAI,MAAM,EAAE;wBACV,MAAM,EAAE,CAAC;qBACV;yBAAM;wBACL,MAAM;qBACP;iBACF;gBACD,IAAI,MAAM,KAAK,CAAC,EAAE;oBAChB,OAAO,CAAC,gBAAgB,CAAC;wBACvB,MAAM,EAAE,KAAK;qBACd,CAAC,CAAC;iBACJ;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
@@ -1,2 +1,6 @@
1
- export declare const coreOperationsRule: import("@typespec/lint").LintRule;
1
+ export declare const coreOperationsRule: import("@typespec/compiler").LinterRuleDefinition<"arm-resource-operation", {
2
+ readonly default: "All Resource operations must use an api-version parameter. Please include Azure.ResourceManager.ApiVersionParameter in the operation parameter list using the spread (...ApiVersionParameter) operator, or using one of the common resource parameter models.";
3
+ readonly opOutsideInterface: "All operations must be inside an interface declaration.";
4
+ readonly opMissingDecorator: import("@typespec/compiler").CallableMessage<[string, string]>;
5
+ }>;
2
6
  //# sourceMappingURL=core-operations.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"core-operations.d.ts","sourceRoot":"","sources":["../../../src/rules/core-operations.ts"],"names":[],"mappings":"AA+BA,eAAO,MAAM,kBAAkB,mCA2E7B,CAAC"}
1
+ {"version":3,"file":"core-operations.d.ts","sourceRoot":"","sources":["../../../src/rules/core-operations.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,kBAAkB;;;;EAwD7B,CAAC"}
@@ -1,38 +1,32 @@
1
- import { getEffectiveModelType, getProperty, isErrorType, SyntaxKind, } from "@typespec/compiler";
2
- import { getOperationVerb, isBody, isHeader, isPathParam, isQueryParam, } from "@typespec/http";
3
- import { createRule } from "@typespec/lint";
4
- import { getActionDetails } from "@typespec/rest";
5
- import { reportDiagnostic } from "../lib.js";
6
- import { isArmOperationsListInterface } from "../private.decorators.js";
7
- import { getArmResource } from "../resource.js";
1
+ import { SyntaxKind, createRule, paramMessage, } from "@typespec/compiler";
2
+ import { getOperationVerb } from "@typespec/http";
8
3
  import { getNamespaceName, getSourceModel, isInternalTypeSpec, isTemplatedInterfaceOperation, } from "./utils.js";
9
4
  export const coreOperationsRule = createRule({
10
- name: "core-operations",
11
- create({ program }) {
5
+ name: "arm-resource-operation",
6
+ severity: "warning",
7
+ description: "Validate ARM Resource operations.",
8
+ messages: {
9
+ default: "All Resource operations must use an api-version parameter. Please include Azure.ResourceManager.ApiVersionParameter in the operation parameter list using the spread (...ApiVersionParameter) operator, or using one of the common resource parameter models.",
10
+ opOutsideInterface: "All operations must be inside an interface declaration.",
11
+ opMissingDecorator: paramMessage `Resource ${"verb"} operation must be decorated with ${"decorator"}.`,
12
+ },
13
+ create(context) {
12
14
  return {
13
15
  operation: (operation) => {
14
- if (!isInternalTypeSpec(program, operation)) {
15
- const actionType = getActionDetails(program, operation);
16
- const verb = getOperationVerb(program, operation);
17
- if (actionType !== undefined && verb !== "post") {
18
- reportDiagnostic(program, {
19
- code: "arm-resource-invalid-action-verb",
20
- target: operation,
21
- });
22
- }
16
+ if (!isInternalTypeSpec(context.program, operation)) {
17
+ const verb = getOperationVerb(context.program, operation);
23
18
  if (!isTemplatedInterfaceOperation(operation) &&
24
19
  (!operation.node.parent || operation.node.parent.kind !== SyntaxKind.InterfaceStatement)) {
25
- reportDiagnostic(program, {
26
- code: "arm-resource-operation-outside-interface",
20
+ context.reportDiagnostic({
21
+ messageId: "opOutsideInterface",
27
22
  target: operation,
28
23
  });
29
24
  }
30
25
  const parameters = operation.parameters;
31
26
  if (parameters === undefined ||
32
27
  parameters === null ||
33
- !hasApiParameter(program, parameters)) {
34
- reportDiagnostic(program, {
35
- code: "arm-resource-operation-missing-api-version",
28
+ !hasApiParameter(context.program, parameters)) {
29
+ context.reportDiagnostic({
36
30
  target: operation,
37
31
  });
38
32
  }
@@ -41,8 +35,8 @@ export const coreOperationsRule = createRule({
41
35
  if ((requiredDecorators === null || requiredDecorators === void 0 ? void 0 : requiredDecorators.length) > 0) {
42
36
  const decorator = operation.decorators.find((d) => requiredDecorators.indexOf(d.decorator.name) >= 0);
43
37
  if (!decorator) {
44
- reportDiagnostic(program, {
45
- code: "arm-resource-operation-missing-decorator",
38
+ context.reportDiagnostic({
39
+ messageId: "opMissingDecorator",
46
40
  target: operation,
47
41
  format: {
48
42
  verb: verb.toUpperCase(),
@@ -52,23 +46,6 @@ export const coreOperationsRule = createRule({
52
46
  }
53
47
  }
54
48
  }
55
- if (verb === "patch") {
56
- const resourceType = getResourceModel(program, operation);
57
- if (resourceType) {
58
- checkPatchModel(program, operation, resourceType);
59
- }
60
- }
61
- }
62
- },
63
- interface: (context) => {
64
- if (!isInternalTypeSpec(program, context) &&
65
- !isArmOperationsListInterface(program, context)) {
66
- if (!context.decorators.some((d) => d.decorator.name === "$armResourceOperations")) {
67
- reportDiagnostic(program, {
68
- code: "arm-resource-interface-requires-decorator",
69
- target: context,
70
- });
71
- }
72
49
  }
73
50
  },
74
51
  };
@@ -82,46 +59,6 @@ const resourceOperationDecorators = {
82
59
  post: ["$armResourceAction", "$armResourceCollectionAction"],
83
60
  head: [],
84
61
  };
85
- function checkPatchModel(program, operation, resourceType) {
86
- const patchModel = getPatchModel(program, operation);
87
- if (patchModel === undefined) {
88
- reportDiagnostic(program, {
89
- code: "arm-resource-invalid-patch-model",
90
- target: operation,
91
- });
92
- }
93
- else if (resourceType.properties.has("tags") &&
94
- !patchModel.some((p) => p.name === "tags" && p.type.kind === "Model")) {
95
- reportDiagnostic(program, {
96
- code: "arm-resource-patch-missing-tags",
97
- target: operation,
98
- });
99
- }
100
- else {
101
- const resourceProperties = resourceType.properties.get("properties");
102
- const badProperties = [];
103
- for (const property of patchModel) {
104
- const sourceModel = getSourceModel(property);
105
- if (sourceModel === undefined || !getArmResource(program, sourceModel)) {
106
- if (!getProperty(resourceType, property.name) &&
107
- (resourceProperties === undefined ||
108
- resourceProperties.type.kind !== "Model" ||
109
- !getProperty(resourceProperties.type, property.name))) {
110
- badProperties.push(property);
111
- }
112
- }
113
- }
114
- if (badProperties.length > 0)
115
- reportDiagnostic(program, {
116
- code: "arm-resource-patch-model-superset",
117
- format: {
118
- name: badProperties.flatMap((t) => t.name).join(", "),
119
- resourceModel: resourceType.name,
120
- },
121
- target: operation,
122
- });
123
- }
124
- }
125
62
  function isApiParameter(program, property) {
126
63
  if (property.type.kind !== "Scalar")
127
64
  return false;
@@ -139,43 +76,4 @@ function hasApiParameter(program, model) {
139
76
  const apiVersionParams = [...model.properties.values()].filter((i) => isApiParameter(program, i));
140
77
  return apiVersionParams !== null && apiVersionParams.length === 1;
141
78
  }
142
- function getResourceModel(program, operation) {
143
- const returnType = operation.returnType;
144
- if (returnType.kind === "Union") {
145
- for (const variant of returnType.variants.values()) {
146
- if (!isErrorType(variant.type) && variant.type.kind === "Model") {
147
- const modelCandidate = getEffectiveModelType(program, variant.type);
148
- if (getArmResource(program, modelCandidate)) {
149
- return modelCandidate;
150
- }
151
- if (modelCandidate.templateMapper !== undefined) {
152
- for (const arg of modelCandidate.templateMapper.args) {
153
- if (arg.kind === "Model" && getArmResource(program, arg)) {
154
- return arg;
155
- }
156
- }
157
- }
158
- }
159
- }
160
- }
161
- return undefined;
162
- }
163
- function getPatchModel(program, operation) {
164
- const bodyProperties = [];
165
- const patchModel = getEffectiveModelType(program, operation.parameters);
166
- for (const [_, property] of patchModel.properties) {
167
- if (isHeader(program, property) ||
168
- isQueryParam(program, property) ||
169
- isPathParam(program, property))
170
- continue;
171
- if (isBody(program, property) && property.type.kind === "Scalar")
172
- return undefined;
173
- bodyProperties.push(property);
174
- }
175
- if (bodyProperties.length === 0)
176
- return undefined;
177
- if (bodyProperties.length === 1 && bodyProperties[0].type.kind === "Model")
178
- return [...bodyProperties[0].type.properties.values()];
179
- return bodyProperties;
180
- }
181
79
  //# sourceMappingURL=core-operations.js.map