-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathaz-arm.js
4176 lines (4088 loc) · 171 KB
/
az-arm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { oas2, oas3 } from '@stoplight/spectral-formats';
import { pattern, falsy, truthy } from '@stoplight/spectral-functions';
import _, { isEmpty, isNull } from 'lodash';
import { createRulesetFunction } from '@stoplight/spectral-core';
import 'jsonpath-plus';
import 'url';
const avoidAnonymousSchema = (schema, _opts, paths) => {
if (schema === null || schema["x-ms-client-name"] !== undefined) {
return [];
}
const path = paths.path || [];
const properties = schema.properties;
if ((properties === undefined || Object.keys(properties).length === 0) &&
schema.additionalProperties === undefined &&
schema.allOf === undefined) {
return [];
}
return [
{
message: 'Inline/anonymous models must not be used, instead define a schema with a model name in the "definitions" section and refer to it. This allows operations to share the models.',
path,
},
];
};
const avoidMsdnReferences = (swaggerObj, _opts, paths) => {
if (swaggerObj === null) {
return [];
}
if (typeof swaggerObj === "string" && !swaggerObj.includes("https://msdn.microsoft.com"))
return [];
if (typeof swaggerObj === "object") {
const docUrl = swaggerObj.url;
if (docUrl === undefined || !docUrl.startsWith("https://msdn.microsoft.com"))
return [];
}
const path = paths.path || [];
return [{
message: 'For better generated code quality, remove all references to "msdn.microsoft.com".',
path,
}];
};
const defaultInEnum = (swaggerObj, _opts, paths) => {
const defaultValue = swaggerObj.default;
const enumValue = swaggerObj.enum;
if (swaggerObj === null ||
typeof swaggerObj !== "object" ||
!defaultValue === null ||
defaultValue === undefined ||
enumValue === null ||
enumValue === undefined) {
return [];
}
if (!Array.isArray(enumValue)) {
return [];
}
const path = paths.path || [];
if (enumValue && !enumValue.includes(defaultValue)) {
return [
{
message: "Default value should appear in the enum constraint for a schema.",
path,
},
];
}
return [];
};
const deleteInOperationName = (operationId, _opts, ctx) => {
if (operationId === "" || typeof operationId !== "string") {
return [];
}
if (!operationId.includes("_")) {
return [];
}
const path = ctx.path || [];
const errors = [];
if (!operationId.match(/^(\w+)_(Delete)/) && !operationId.match(/^(Delete)/)) {
errors.push({
message: `'DELETE' operation '${operationId}' should use method name 'Delete'. Note: If you have already shipped an SDK on top of this spec, fixing this warning may introduce a breaking change.`,
path: [...path],
});
}
return errors;
};
const descriptiveDescriptionRequired = (swaggerObj, _opts, paths) => {
if (swaggerObj === null || typeof swaggerObj !== "string") {
return [];
}
if (swaggerObj.trim().length != 0) {
return [];
}
const path = paths.path || [];
return [{
message: 'The value provided for description is not descriptive enough. Accurate and descriptive description is essential for maintaining reference documentation.',
path,
}];
};
const enumInsteadOfBoolean = (swaggerObj, _opts, paths) => {
if (swaggerObj === null) {
return [];
}
const path = paths.path || [];
return [{
message: 'Booleans properties are not descriptive in all cases and can make them to use, evaluate whether is makes sense to keep the property as boolean or turn it into an enum.',
path,
}];
};
const longRunningOperationsOptionsValidator = (postOp, _opts, ctx) => {
var _a, _b, _c;
if (postOp === null || typeof postOp !== "object") {
return [];
}
const path = ctx.path || [];
if (!postOp["x-ms-long-running-operation"]) {
return [];
}
const errors = [];
const responses = postOp === null || postOp === void 0 ? void 0 : postOp.responses;
let schemaAvailable = false;
for (const responseCode in responses) {
if (responseCode[0] === "2" && ((_a = responses[responseCode]) === null || _a === void 0 ? void 0 : _a.schema) !== undefined) {
schemaAvailable = true;
break;
}
}
if (schemaAvailable &&
((_b = postOp === null || postOp === void 0 ? void 0 : postOp["x-ms-long-running-operation-options"]) === null || _b === void 0 ? void 0 : _b["final-state-via"]) !== "location" &&
((_c = postOp === null || postOp === void 0 ? void 0 : postOp["x-ms-long-running-operation-options"]) === null || _c === void 0 ? void 0 : _c["final-state-via"]) !== "azure-async-operation") {
errors.push({
message: `A LRO Post operation with return schema must have "x-ms-long-running-operation-options" extension enabled.`,
path: [...path.slice(0, -1)],
});
}
return errors;
};
const mutabilityWithReadOnly = (prop, _opts, ctx) => {
if (prop === null || typeof prop !== "object") {
return [];
}
if (prop.readOnly === undefined ||
prop["x-ms-mutability"] === undefined ||
prop["x-ms-mutability"].length === 0) {
return [];
}
const path = ctx.path || [];
const errors = [];
let hasErrors = false;
let invalidValues = "";
if (prop.readOnly === true) {
if (prop["x-ms-mutability"].length !== 1 || prop["x-ms-mutability"][0] !== "read") {
hasErrors = true;
invalidValues = prop["x-ms-mutability"].join(", ");
}
}
else {
if (prop["x-ms-mutability"].length === 1 && prop["x-ms-mutability"][0] === "read") {
hasErrors = true;
invalidValues = "read";
}
}
if (hasErrors) {
errors.push({
message: `When property is modeled as "readOnly": true then x-ms-mutability extension can only have "read" value. When property is modeled as "readOnly": false then applying x-ms-mutability extension with only "read" value is not allowed. Extension contains invalid values: '${invalidValues}'.`,
path: [...path],
});
}
return errors;
};
const LATEST_VERSION_BY_COMMON_TYPES_FILENAME = new Map([
["types.json", "v5"],
["managedidentity.json", "v5"],
["privatelinks.json", "v5"],
["customermanagedkeys.json", "v5"],
["managedidentitywithdelegation.json", "v5"],
["networksecurityperimeter.json", "v5"],
["mobo.json", "v5"],
]);
function isLatestCommonTypesVersionForFile(version, fileName) {
return LATEST_VERSION_BY_COMMON_TYPES_FILENAME.get(fileName) === version.toLowerCase();
}
const ExtensionResourceFullyQualifiedPathReg = new RegExp(".+/providers/.+/providers/.+$", "gi");
const ExtensionResourceReg = new RegExp("^((/{\\w+})|({\\w+}))/providers/.+$", "gi");
function isPathOfExtensionResource(path) {
return !!path.match(ExtensionResourceFullyQualifiedPathReg) || !!path.match(ExtensionResourceReg);
}
function getProperties(schema) {
if (!schema) {
return {};
}
let properties = {};
if (schema.allOf && Array.isArray(schema.allOf)) {
schema.allOf.forEach((base) => {
properties = { ...getProperties(base), ...properties };
});
}
if (schema.properties) {
properties = { ...properties, ...schema.properties };
}
return properties;
}
function getAllPropertiesIncludingDeeplyNestedProperties(schema, properties) {
if (!schema) {
return {};
}
if (schema.allOf && Array.isArray(schema.allOf)) {
schema.allOf.forEach((base) => {
getAllPropertiesIncludingDeeplyNestedProperties(base, properties);
});
}
if (schema.properties) {
const props = schema.properties;
Object.entries(props).forEach(([key, value]) => {
if (!value.properties) {
properties.push(Object.fromEntries([[key, value]]));
}
else {
getAllPropertiesIncludingDeeplyNestedProperties(props[key], properties);
}
});
}
return properties;
}
function getProperty(schema, propName) {
if (!schema) {
return {};
}
if (schema.allOf && Array.isArray(schema.allOf)) {
for (const base of schema.allOf) {
const result = getProperty(base, propName);
if (result) {
return result;
}
}
}
if (schema.properties) {
if (propName in schema.properties) {
return schema.properties[propName];
}
}
return undefined;
}
function findBodyParam(params) {
const isBody = (elem) => elem.in === "body";
if (params && Array.isArray(params)) {
return params.filter(isBody).shift();
}
return undefined;
}
function getRequiredProperties(schema) {
if (!schema) {
return [];
}
let requires = [];
if (schema.allOf && Array.isArray(schema.allOf)) {
schema.allOf.forEach((base) => {
requires = [...getRequiredProperties(base), ...requires];
});
}
if (schema.required) {
requires = [...schema.required, requires];
}
return requires;
}
function jsonPath(paths, root) {
let result = undefined;
paths.some((p) => {
if (typeof root !== "object" && root !== null) {
result = undefined;
return true;
}
root = root[p];
result = root;
return false;
});
return result;
}
function diffSchema(a, b) {
const notMatchedProperties = [];
function diffSchemaInternal(a, b, paths) {
if (!(a || b)) {
return;
}
if (a && b) {
const propsA = getProperties(a);
const propsB = getProperties(b);
Object.keys(propsA).forEach((p) => {
if (propsB[p]) {
diffSchemaInternal(propsA[p], propsB[p], [...paths, p]);
}
else {
notMatchedProperties.push([...paths, p].join("."));
}
});
}
}
diffSchemaInternal(a, b, []);
return notMatchedProperties;
}
function getGetOperationSchema(paths, ctx) {
var _a, _b, _c;
const getOperationPath = [...paths, "get"];
const getOperation = jsonPath(getOperationPath, (_a = ctx === null || ctx === void 0 ? void 0 : ctx.documentInventory) === null || _a === void 0 ? void 0 : _a.resolved);
if (!getOperation) {
return undefined;
}
return ((_b = getOperation === null || getOperation === void 0 ? void 0 : getOperation.responses["200"]) === null || _b === void 0 ? void 0 : _b.schema) || ((_c = getOperation === null || getOperation === void 0 ? void 0 : getOperation.responses["201"]) === null || _c === void 0 ? void 0 : _c.schema);
}
function isPageableOperation(operation) {
return !!(operation === null || operation === void 0 ? void 0 : operation["x-ms-pageable"]);
}
function getReturnedType(operation) {
var _a;
const succeededCodes = ["200", "201", "202"];
for (const code of succeededCodes) {
const response = operation.responses[code];
if (response) {
return (_a = response === null || response === void 0 ? void 0 : response.schema) === null || _a === void 0 ? void 0 : _a.$ref;
}
}
}
function getReturnedSchema(operation) {
const succeededCodes = ["200", "201"];
for (const code of succeededCodes) {
const response = operation.responses[code];
if (response === null || response === void 0 ? void 0 : response.schema) {
return response === null || response === void 0 ? void 0 : response.schema;
}
}
}
function isXmsResource(schema) {
if (!schema) {
return false;
}
if (schema["x-ms-azure-resource"]) {
return true;
}
if (schema.allOf && Array.isArray(schema.allOf)) {
for (const base of schema.allOf) {
if (isXmsResource(base)) {
return true;
}
}
}
return false;
}
function isSchemaEqual(a, b) {
if (a && b) {
const propsA = Object.getOwnPropertyNames(a);
const propsB = Object.getOwnPropertyNames(b);
if (propsA.length === propsB.length) {
if (propsA.length === 0) {
return true;
}
for (let i = 0; i < propsA.length; i++) {
const propsAName = propsA[i];
const [propA, propB] = [a[propsAName], b[propsAName]];
if (typeof propA === "object") {
if (!isSchemaEqual(propA, propB)) {
return false;
}
else if (i === propsA.length - 1) {
return true;
}
}
else if (propA !== propB) {
return false;
}
else if (propA === propB && i === propsA.length - 1) {
return true;
}
}
}
}
return false;
}
const providerAndNamespace = "/providers/[^/]+";
const resourceTypeAndResourceName = "(?:/\\w+/default|/\\w+/{[^/]+})";
const queryParam = "(?:\\?\\w+)";
const resourcePathRegEx = new RegExp(`${providerAndNamespace}${resourceTypeAndResourceName}+${queryParam}?$`, "gi");
function getResourcesPathHierarchyBasedOnResourceType(path) {
const index = path.lastIndexOf("/providers/");
if (index === -1) {
return [];
}
const lastProvider = path.substr(index);
const result = [];
const matches = lastProvider.match(resourcePathRegEx);
if (matches && matches.length) {
const match = matches[0];
const resourcePathSegments = match.split("/").slice(3);
for (const resourcePathSegment of resourcePathSegments) {
if (resourcePathSegment.startsWith("{") || resourcePathSegment === "default") {
continue;
}
result.push(resourcePathSegment);
}
}
return result;
}
function deepFindObjectKeyPath(object, keyName, path = []) {
if (!_.isObject(object)) {
return [];
}
if (_.has(object, keyName)) {
return _.concat(path, keyName);
}
for (const [key, value] of Object.entries(object)) {
const result = deepFindObjectKeyPath(value, keyName, _.concat(path, key));
if (result) {
return result;
}
}
return [];
}
const nextLinkPropertyMustExist = (opt, _opts, ctx) => {
var _a, _b, _c;
if (opt === null || typeof opt !== "object") {
return [];
}
if (opt["x-ms-pageable"] === undefined) {
return [];
}
const path = ctx.path || [];
const errors = [];
const nextLinkName = ((_a = opt["x-ms-pageable"]) === null || _a === void 0 ? void 0 : _a.nextLinkName) || null;
const responseSchemaProperties = getProperties((_c = (_b = opt === null || opt === void 0 ? void 0 : opt.responses) === null || _b === void 0 ? void 0 : _b["200"]) === null || _c === void 0 ? void 0 : _c.schema);
if (nextLinkName !== null && nextLinkName !== "") {
if (Object.keys(responseSchemaProperties).length === 0 ||
!Object.keys(responseSchemaProperties).includes(nextLinkName)) {
errors.push({
message: `The property '${nextLinkName}' specified by nextLinkName does not exist in the 200 response schema. Please, specify the name of the property that provides the nextLink. If the model does not have the nextLink property then specify null.`,
path: [...path],
});
}
}
return errors;
};
const xmsClientName = (opt, _opts, ctx) => {
if (opt === null || typeof opt !== "object") {
return [];
}
if (opt["x-ms-client-name"] === undefined) {
return [];
}
const path = ctx.path || [];
const errors = [];
if (path.includes("parameters")) {
if (opt["x-ms-client-name"] === opt.name) {
errors.push({
message: `Value of 'x-ms-client-name' cannot be the same as '${opt.name}' Property/Model.`,
path: [...path],
});
}
}
else {
if (opt["x-ms-client-name"] === path.slice(-1)[0]) {
errors.push({
message: `Value of 'x-ms-client-name' cannot be the same as '${path.slice(-1)[0]}' Property/Model.`,
path: [...path],
});
}
}
return errors;
};
const xmsPathsMustOverloadPaths = (xmsPaths, _opts, ctx) => {
var _a;
if (xmsPaths === null || typeof xmsPaths !== "object") {
return [];
}
const path = ctx.path || [];
const errors = [];
const swagger = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.documentInventory) === null || _a === void 0 ? void 0 : _a.resolved;
for (const xmsPath in xmsPaths) {
const pathName = xmsPath.split("?")[0];
if (!Object.keys(swagger.paths).includes(pathName)) {
errors.push({
message: `Paths in x-ms-paths must overload a normal path in the paths section, i.e. a path in the x-ms-paths must either be same as a path in the paths section or a path in the paths sections followed by additional parameters.`,
path: [...path, xmsPath],
});
}
}
return errors;
};
const getInOperationName = (operationId, _opts, ctx) => {
if (operationId === "" || typeof operationId !== "string") {
return [];
}
const path = ctx.path || [];
const errors = [];
if (!operationId.match(/^(\w+)_(Get|List)/) && !operationId.match(/^(Get|List)/)) {
errors.push({
message: `'GET' operation '${operationId}' should use method name 'Get' or Method name start with 'List'. Note: If you have already shipped an SDK on top of this spec, fixing this warning may introduce a breaking change.`,
path: [...path],
});
}
return errors;
};
const listInOperationName = (swaggerObj, _opts, paths) => {
if (swaggerObj === null && typeof swaggerObj !== "object") {
return [];
}
const listRegex = /^((\w+_List\w*)|List)$/;
const path = paths.path;
if (swaggerObj["x-ms-pageable"] !== undefined) {
if (!listRegex.test(swaggerObj.operationId)) {
return [
{
message: "Since operation '${swaggerObj.operationId}' response has model definition 'x-ms-pageable', it should be of the form \\\"*_list*\\\". Note: If you have already shipped an SDK on top of this spec, fixing this warning may introduce a breaking change.",
path: [...path, path[path.length - 1], "operationId"],
},
];
}
else {
return [];
}
}
if (swaggerObj.responses === undefined)
return [];
const responseList = swaggerObj.responses;
let gotArray = false;
Object.values(responseList).some((response) => {
var _a, _b;
if (response.schema) {
if (((_b = (_a = response.schema.properties) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.type) === "array" && Object.keys(response.schema.properties).length <= 2) {
if (!listRegex.test(swaggerObj["operationId"])) {
gotArray = true;
return true;
}
}
}
return false;
});
if (gotArray)
return [
{
message: "Since operation `${swaggerObj.operationId}` response has model definition 'array', it should be of the form \"_\\_list_\".",
path: [...path, path[path.length - 1], "operationId"],
},
];
return [];
};
const lroStatusCodesReturnTypeSchema = (putOp, _opts, ctx) => {
if (putOp === null || typeof putOp !== "object") {
return [];
}
const path = ctx.path || [];
if (!putOp["x-ms-long-running-operation"]) {
return [];
}
const errors = [];
const operationId = putOp["operationId"] || "";
const responseCodes = ["200", "201"];
for (const responseCode of responseCodes) {
if ((putOp === null || putOp === void 0 ? void 0 : putOp.responses) && (putOp === null || putOp === void 0 ? void 0 : putOp.responses[responseCode])) {
if (!(putOp === null || putOp === void 0 ? void 0 : putOp.responses[responseCode].schema) ||
Object.keys(putOp === null || putOp === void 0 ? void 0 : putOp.responses[responseCode].schema).length === 0) {
errors.push({
message: `200/201 Responses of long running operations must have a schema definition for return type. OperationId: '${operationId}', Response code: '${responseCode}'`,
path: [...path, "responses", `${responseCode}`],
});
}
}
}
return errors;
};
const namePropertyDefinitionInParameter = (parameters, _opts, ctx) => {
if (parameters === null || typeof parameters !== "object") {
return [];
}
const path = ctx.path || [];
const errors = [];
const propsParameters = Object.getOwnPropertyNames(parameters);
if (propsParameters.length === 0) {
return [];
}
for (const propsParameter of propsParameters) {
if (propsParameter === "length") {
continue;
}
const parameter = parameters[propsParameter];
if (!parameter.name || parameter.name === "") {
errors.push({
message: `Parameter Must have the "name" property defined with non-empty string as its value`,
path: [...path],
});
}
}
return errors;
};
const operationIdSingleUnderscore = (operationId, _opts, ctx) => {
if (operationId === "" || typeof operationId !== "string") {
return [];
}
if (!operationId.includes("_")) {
return [];
}
const path = ctx.path || [];
const errors = [];
if (operationId.match(/_/g).length > 1) {
errors.push({
message: `Only 1 underscore is permitted in the operation id, following Noun_Verb conventions`,
path: [...path],
});
}
return errors;
};
const operationIdNounConflictingModelNames = (operationId, _opts, ctx) => {
var _a;
if (operationId === "" || typeof operationId !== "string") {
return [];
}
if (!operationId.includes("_")) {
return [];
}
const path = ctx.path || [];
const errors = [];
const nounPartOfOperationId = operationId.split("_")[0];
const swagger = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.documentInventory) === null || _a === void 0 ? void 0 : _a.resolved;
const definitionsList = swagger.definitions ? Object.keys(swagger.definitions) : [];
if (definitionsList.includes(nounPartOfOperationId)) {
errors.push({
message: `OperationId has a noun that conflicts with one of the model names in definitions section. The model name will be disambiguated to '${nounPartOfOperationId}Model'. Consider using the plural form of '${nounPartOfOperationId}' to avoid this. Note: If you have already shipped an SDK on top of this spec, fixing this warning may introduce a breaking change.`,
path: [...path],
});
}
return errors;
};
const operationIdNounVerb = (operationId, _opts, ctx) => {
if (operationId === "" || typeof operationId !== "string") {
return [];
}
if (!operationId.includes("_")) {
return [];
}
const path = ctx.path || [];
const errors = [];
const nounPartOfOperationId = operationId.split("_")[0];
const nounSearchPattern = nounPartOfOperationId.slice(-1) === "s"
? `${nounPartOfOperationId}?`
: `${nounPartOfOperationId}`;
const verbPartOfOperationId = operationId.split("_")[1];
if (verbPartOfOperationId.match(nounSearchPattern)) {
errors.push({
message: `Per the Noun_Verb convention for Operation Ids, the noun '${nounPartOfOperationId}' should not appear after the underscore. Note: If you have already shipped an SDK on top of this spec, fixing this warning may introduce a breaking change.`,
path: [...path],
});
}
return errors;
};
function paramLocation(paramSchema, options, { path }) {
if (paramSchema === null || typeof paramSchema !== "object") {
return [];
}
const errors = [];
if (!paramSchema["x-ms-parameter-location"]) {
errors.push({
message: ``,
path,
});
}
return errors;
}
const patchInOperationName = (operationId, _opts, ctx) => {
if (operationId === "" || typeof operationId !== "string") {
return [];
}
if (!operationId.includes("_")) {
return [];
}
const path = ctx.path || [];
const errors = [];
if (!operationId.match(/^(\w+)_(Update)/) && !operationId.match(/^(Update)/)) {
errors.push({
message: `'PATCH' operation '${operationId}' should use method name 'Update'. Note: If you have already shipped an SDK on top of this spec, fixing this warning may introduce a breaking change.`,
path: [...path],
});
}
return errors;
};
const putInOperationName = (operationId, _opts, ctx) => {
if (operationId === "" || typeof operationId !== "string") {
return [];
}
if (!operationId.includes("_")) {
return [];
}
const path = ctx.path || [];
const errors = [];
if (!operationId.match(/^(\w+)_(Create)/) && !operationId.match(/^(Create)/)) {
errors.push({
message: `'PUT' operation '${operationId}' should use method name 'Create'. Note: If you have already shipped an SDK on top of this spec, fixing this warning may introduce a breaking change.`,
path: [...path],
});
}
return errors;
};
function checkSchemaFormat(schema, options, { path }) {
if (schema === null || typeof schema !== "object") {
return [];
}
const errors = [];
const schemaFormats = [
"int32",
"int64",
"float",
"double",
"unixtime",
"byte",
"binary",
"date",
"date-time",
"password",
"char",
"time",
"date-time-rfc1123",
"date-time-rfc7231",
"duration",
"uuid",
"base64url",
"url",
"odata-query",
"certificate",
"uri",
"uri-reference",
"uri-template",
"email",
"hostname",
"ipv4",
"ipv6",
"regex",
"json-pointer",
"relative-json-pointer",
"arm-id",
];
if ((schema.type === "boolean" || schema.type === "integer" || schema.type === "number" || schema.type === "string") && schema.format) {
if (!schemaFormats.includes(schema.format)) {
errors.push({
message: `${schema.format}`,
path: [...path, "format"],
});
}
}
return errors;
}
function checkSummaryAndDescription(op, options, ctx) {
const errors = [];
const path = ctx.path;
if (op.summary && op.description && op.summary.trim() === op.description.trim()) {
errors.push({
message: ``,
path,
});
}
return errors;
}
const xmsClientNameParameter = (swaggerObj, _opts, paths) => {
if (swaggerObj === null) {
return [];
}
if (swaggerObj.name !== swaggerObj['x-ms-client-name'])
return [];
const path = paths.path || [];
path.push('x-ms-client-name');
return [
{
message: `Value of 'x-ms-client-name' cannot be the same as ${swaggerObj.name} Property/Model.`,
path: path
},
];
};
const xmsClientNameProperty = (swaggerObj, _opts, paths) => {
if (swaggerObj === null || typeof swaggerObj !== "string") {
return [];
}
const path = paths.path || [];
if (!path || path.length <= 2)
return [];
const name = path[path.length - 2];
if (swaggerObj !== name)
return [];
return [
{
message: `Value of 'x-ms-client-name' cannot be the same as ${name} Property/Model.`,
path: path
},
];
};
const xmsExamplesRequired = (swaggerObj, _opts, paths) => {
if (swaggerObj === null || typeof swaggerObj !== "object") {
return [];
}
if (swaggerObj["x-ms-examples"] !== undefined && Object.keys(swaggerObj["x-ms-examples"].length > 0))
return [];
const path = paths.path || [];
return [
{
message: `Please provide x-ms-examples describing minimum/maximum property set for response/request payloads for operations.`,
path: path,
},
];
};
const ruleset$1 = {
extends: [],
rules: {
docLinkLocale: {
description: "This rule is to ensure the documentation link in the description does not contains any locale.",
message: "The documentation link in the description contains locale info, please change it to the link without locale.",
severity: "error",
resolved: false,
formats: [oas2],
given: ["$..[?(@property === 'description')]^"],
then: {
function: pattern,
functionOptions: {
match: "https://docs.microsoft.com/\\w+\\-\\w+/azure/.*",
},
},
},
OperationSummaryOrDescription: {
description: "Operation should have a summary or description.",
message: "Operation should have a summary or description.",
severity: "warn",
disableForTypeSpecDataPlane: true,
disableForTypeSpecDataPlaneReason: "Covered by TSP's '@azure-tools/typespec-azure-core/documentation-required' rule.",
given: [
"$.paths[*][?( @property === 'get' && [email protected] && [email protected] )]",
"$.paths[*][?( @property === 'put' && [email protected] && [email protected] )]",
"$.paths[*][?( @property === 'post' && [email protected] && [email protected] )]",
"$.paths[*][?( @property === 'patch' && [email protected] && [email protected] )]",
"$.paths[*][?( @property === 'delete' && [email protected] && [email protected] )]",
"$.paths[*][?( @property === 'options' && [email protected] && [email protected] )]",
"$.paths[*][?( @property === 'head' && [email protected] && [email protected] )]",
"$.paths[*][?( @property === 'trace' && [email protected] && [email protected] )]",
],
then: {
function: falsy,
},
},
SchemaDescriptionOrTitle: {
description: "All schemas should have a description or title.",
message: "Schema should have a description or title.",
severity: "warn",
disableForTypeSpecDataPlane: true,
disableForTypeSpecDataPlaneReason: "Covered by TSP's '@azure-tools/typespec-azure-core/documentation-required' rule.",
formats: [oas2, oas3],
given: ["$.definitions[?([email protected] && [email protected])]", "$.components.schemas[?([email protected] && [email protected])]"],
then: {
function: falsy,
},
},
ParameterDescription: {
description: "All parameters should have a description.",
message: "Parameter should have a description.",
severity: "warn",
disableForTypeSpecDataPlane: true,
disableForTypeSpecDataPlaneReason: "Covered by TSP's '@azure-tools/typespec-azure-core/documentation-required' rule.",
given: ["$.paths[*].parameters.*", "$.paths.*[get,put,post,patch,delete,options,head].parameters.*"],
then: {
field: "description",
function: truthy,
},
},
InvalidVerbUsed: {
description: `Each operation definition must have a HTTP verb and it must be DELETE/GET/PUT/PATCH/HEAD/OPTIONS/POST/TRACE.`,
message: "Permissible values for HTTP Verb are DELETE, GET, PUT, PATCH, HEAD, OPTIONS, POST, TRACE.",
severity: "error",
resolved: false,
given: "$[paths,'x-ms-paths'].*[?([email protected](/^(DELETE|GET|PUT|PATCH|HEAD|OPTIONS|POST|TRACE|PARAMETERS)$/i))]",
then: {
function: falsy,
},
},
LroExtension: {
description: "Operations with a 202 response must specify `x-ms-long-running-operation: true`. GET operation is excluded from the validation as GET will have 202 only if it is a polling action & hence x-ms-long-running-operation wouldn't be defined",
message: "Operations with a 202 response must specify `x-ms-long-running-operation: true`. GET operation is excluded from the validation as GET will have 202 only if it is a polling action & hence x-ms-long-running-operation wouldn't be defined",
severity: "error",
formats: [oas2],
given: "$.paths[*][put,patch,post,delete].responses[?(@property == '202')]^^",
then: {
field: "x-ms-long-running-operation",
function: truthy,
},
},
LroStatusCodesReturnTypeSchema: {
description: "The '200'/'201' responses of the long running operation must have a schema definition.",
message: "{{error}}",
severity: "error",
resolved: true,
formats: [oas2],
given: ["$[paths,'x-ms-paths'].*[put][?(@property === 'x-ms-long-running-operation' && @ === true)]^"],
then: {
function: lroStatusCodesReturnTypeSchema,
},
},
NamePropertyDefinitionInParameter: {
description: "A parameter must have a `name` property for the SDK to be properly generated.",
message: "{{error}}",
severity: "error",
resolved: true,
formats: [oas2],
given: ["$.parameters", "$.paths.*.parameters", "$.paths.*.*.parameters"],
then: {
function: namePropertyDefinitionInParameter,
},
},
OperationIdNounConflictingModelNames: {
description: "The first part of an operation Id separated by an underscore i.e., `Noun` in a `Noun_Verb` should not conflict with names of the models defined in the definitions section. If this happens, AutoRest appends `Model` to the name of the model to resolve the conflict (`NounModel` in given example) with the name of the client itself (which will be named as `Noun` in given example). This can result in an inconsistent user experience.",
message: "{{error}}",
severity: "warn",
resolved: true,
formats: [oas2],
given: ["$[paths,'x-ms-paths'].*.*[?(@property === 'operationId')]"],
then: {
function: operationIdNounConflictingModelNames,
},
},
OperationIdNounVerb: {
description: "OperationId should be of the form `Noun_Verb`.",
message: "{{error}}",
severity: "error",
resolved: true,
formats: [oas2],
given: ["$[paths,'x-ms-paths'].*.*[?(@property === 'operationId')]"],
then: {
function: operationIdNounVerb,
},
},
OperationIdSingleUnderscore: {
description: "An operationId can have exactly one underscore, not adhering to it can cause errors in code generation.",
message: "{{error}}",
severity: "error",
resolved: true,
formats: [oas2],
given: ["$[paths,'x-ms-paths'].*.*[?(@property === 'operationId')]"],
then: {
function: operationIdSingleUnderscore,
},
},
GetInOperationName: {
description: "Verifies whether value for `operationId` is named as per ARM guidelines.",
message: "{{error}}",
severity: "warn",
resolved: true,
formats: [oas2],
given: ["$[paths,'x-ms-paths'].*[get][?(@property === 'operationId')]"],
then: {
function: getInOperationName,
},
},
PutInOperationName: {
description: "Verifies whether value for `operationId` is named as per ARM guidelines.",
message: "{{error}}",
severity: "warn",
resolved: true,
formats: [oas2],
given: ["$[paths,'x-ms-paths'].*[put][?(@property === 'operationId')]"],
then: {
function: putInOperationName,
},
},
PatchInOperationName: {
description: "Verifies whether value for `operationId` is named as per ARM guidelines.",
message: "{{error}}",
severity: "warn",
resolved: true,
formats: [oas2],
given: ["$[paths,'x-ms-paths'].*[patch][?(@property === 'operationId')]"],
then: {
function: patchInOperationName,
},
},
DeleteInOperationName: {
description: "Verifies whether value for `operationId` is named as per ARM guidelines.",