@azure-tools/typespec-azure-core 0.63.0-dev.3 → 0.63.0-dev.5
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.
- package/README.md +2 -0
- package/dist/src/linter.d.ts.map +1 -1
- package/dist/src/linter.js +4 -0
- package/dist/src/linter.js.map +1 -1
- package/dist/src/rules/no-case-mismatch.d.ts +4 -0
- package/dist/src/rules/no-case-mismatch.d.ts.map +1 -0
- package/dist/src/rules/no-case-mismatch.js +49 -0
- package/dist/src/rules/no-case-mismatch.js.map +1 -0
- package/dist/src/rules/no-unnamed-union.d.ts +4 -0
- package/dist/src/rules/no-unnamed-union.d.ts.map +1 -0
- package/dist/src/rules/no-unnamed-union.js +56 -0
- package/dist/src/rules/no-unnamed-union.js.map +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -37,6 +37,7 @@ Available ruleSets:
|
|
|
37
37
|
| `@azure-tools/typespec-azure-core/composition-over-inheritance` | Check that if a model is used in an operation and has derived models that it has a discriminator or recommend to use composition via spread or `is`. |
|
|
38
38
|
| `@azure-tools/typespec-azure-core/known-encoding` | Check for supported encodings. |
|
|
39
39
|
| `@azure-tools/typespec-azure-core/long-running-polling-operation-required` | Long-running operations should have a linked polling operation. |
|
|
40
|
+
| [`@azure-tools/typespec-azure-core/no-case-mismatch`](https://azure.github.io/typespec-azure/docs/libraries/azure-core/rules/no-case-mismatch) | Validate that no two types have the same name with different casing. |
|
|
40
41
|
| [`@azure-tools/typespec-azure-core/no-closed-literal-union`](https://azure.github.io/typespec-azure/docs/libraries/azure-core/rules/no-closed-literal-union) | Unions of literals should include the base scalar type to mark them as open enum. |
|
|
41
42
|
| [`@azure-tools/typespec-azure-core/no-enum`](https://azure.github.io/typespec-azure/docs/libraries/azure-core/rules/no-enum) | Azure services should not use enums. |
|
|
42
43
|
| `@azure-tools/typespec-azure-core/no-error-status-codes` | Recommend using the error response defined by Azure REST API guidelines. |
|
|
@@ -48,6 +49,7 @@ Available ruleSets:
|
|
|
48
49
|
| `@azure-tools/typespec-azure-core/no-response-body` | Ensure that the body is set correctly for the response type. |
|
|
49
50
|
| `@azure-tools/typespec-azure-core/no-rpc-path-params` | Operations defined using RpcOperation should not have path parameters. |
|
|
50
51
|
| `@azure-tools/typespec-azure-core/no-openapi` | Azure specs should not be using decorators from @typespec/openapi or @azure-tools/typespec-autorest |
|
|
52
|
+
| [`@azure-tools/typespec-azure-core/no-unnamed-union`](https://azure.github.io/typespec-azure/docs/libraries/azure-core/rules/no-unnamed-union) | Azure services should not define a union expression but create a declaration. |
|
|
51
53
|
| [`@azure-tools/typespec-azure-core/no-header-explode`](https://azure.github.io/typespec-azure/docs/libraries/azure-core/rules/no-header-explode) | It is recommended to serialize header parameter without explode: true |
|
|
52
54
|
| [`@azure-tools/typespec-azure-core/no-format`](https://azure.github.io/typespec-azure/docs/libraries/azure-core/rules/prevent-format) | Azure services should not use the `@format` decorator. |
|
|
53
55
|
| `@azure-tools/typespec-azure-core/no-multiple-discriminator` | Classes should have at most one discriminator. |
|
package/dist/src/linter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linter.d.ts","sourceRoot":"","sources":["../../src/linter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"linter.d.ts","sourceRoot":"","sources":["../../src/linter.ts"],"names":[],"mappings":"AAqFA,eAAO,MAAM,OAAO,+CASlB,CAAC"}
|
package/dist/src/linter.js
CHANGED
|
@@ -7,6 +7,7 @@ import { compositionOverInheritanceRule } from "./rules/composition-over-inherit
|
|
|
7
7
|
import { friendlyNameRule } from "./rules/friendly-name.js";
|
|
8
8
|
import { knownEncodingRule } from "./rules/known-encoding.js";
|
|
9
9
|
import { longRunningOperationsRequirePollingOperation } from "./rules/lro-polling-operation.js";
|
|
10
|
+
import { noCaseMismatchRule } from "./rules/no-case-mismatch.js";
|
|
10
11
|
import { noClosedLiteralUnionRule } from "./rules/no-closed-literal-union.js";
|
|
11
12
|
import { noEnumRule } from "./rules/no-enum.js";
|
|
12
13
|
import { noErrorStatusCodesRule } from "./rules/no-error-status-codes.js";
|
|
@@ -23,6 +24,7 @@ import { noQueryExplodeRule } from "./rules/no-query-explode.js";
|
|
|
23
24
|
import { noResponseBodyRule } from "./rules/no-response-body.js";
|
|
24
25
|
import { noRpcPathParamsRule } from "./rules/no-rpc-path-params.js";
|
|
25
26
|
import { noStringDiscriminatorRule } from "./rules/no-string-discriminator.js";
|
|
27
|
+
import { noUnnamedUnionRule } from "./rules/no-unnamed-union.js";
|
|
26
28
|
import { nonBreakingVersioningRule } from "./rules/non-breaking-versioning.js";
|
|
27
29
|
import { apiVersionRule } from "./rules/operation-missing-api-version.js";
|
|
28
30
|
import { preventFormatRule } from "./rules/prevent-format.js";
|
|
@@ -46,6 +48,7 @@ const rules = [
|
|
|
46
48
|
compositionOverInheritanceRule,
|
|
47
49
|
knownEncodingRule,
|
|
48
50
|
longRunningOperationsRequirePollingOperation,
|
|
51
|
+
noCaseMismatchRule,
|
|
49
52
|
noClosedLiteralUnionRule,
|
|
50
53
|
noEnumRule,
|
|
51
54
|
noErrorStatusCodesRule,
|
|
@@ -57,6 +60,7 @@ const rules = [
|
|
|
57
60
|
noResponseBodyRule,
|
|
58
61
|
noRpcPathParamsRule,
|
|
59
62
|
noOpenAPIRule,
|
|
63
|
+
noUnnamedUnionRule,
|
|
60
64
|
noHeaderExplodeRule,
|
|
61
65
|
preventFormatRule,
|
|
62
66
|
noMultipleDiscriminatorRule,
|
package/dist/src/linter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linter.js","sourceRoot":"","sources":["../../src/linter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,E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AAG;IACZ,cAAc;IACd,gBAAgB;IAChB,aAAa;IACb,QAAQ;IACR,UAAU;IACV,8BAA8B;IAC9B,iBAAiB;IACjB,4CAA4C;IAC5C,kBAAkB;IAClB,wBAAwB;IACxB,UAAU;IACV,sBAAsB;IACtB,2BAA2B;IAC3B,yBAAyB;IACzB,oBAAoB;IACpB,cAAc;IACd,oBAAoB;IACpB,kBAAkB;IAClB,mBAAmB;IACnB,aAAa;IACb,kBAAkB;IAClB,mBAAmB;IACnB,iBAAiB;IACjB,2BAA2B;IAC3B,4BAA4B;IAC5B,kBAAkB;IAClB,iBAAiB;IACjB,oBAAoB;IACpB,oBAAoB;IACpB,iCAAiC;IACjC,2BAA2B;IAC3B,4BAA4B;IAC5B,gBAAgB;IAChB,qBAAqB;IACrB,yBAAyB;IACzB,oBAAoB;IACpB,gBAAgB;IAChB,cAAc;IACd,aAAa;IACb,kBAAkB;CACnB,CAAC;AAEF,MAAM,CAAC,MAAM,OAAO,GAAG,YAAY,CAAC;IAClC,KAAK;IACL,QAAQ,EAAE;QACR,sBAAsB,EAAE;YACtB,MAAM,EAAE;gBACN,CAAC,oCAAoC,yBAAyB,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI;aAC7E;SACF;KACF;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-case-mismatch.d.ts","sourceRoot":"","sources":["../../../src/rules/no-case-mismatch.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,kBAAkB;;EA8C7B,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createRule, isTemplateInstance, paramMessage, } from "@typespec/compiler";
|
|
2
|
+
import { DuplicateTracker } from "@typespec/compiler/utils";
|
|
3
|
+
export const noCaseMismatchRule = createRule({
|
|
4
|
+
name: "no-case-mismatch",
|
|
5
|
+
description: "Validate that no two types have the same name with different casing.",
|
|
6
|
+
severity: "warning",
|
|
7
|
+
url: "https://azure.github.io/typespec-azure/docs/libraries/azure-core/rules/no-case-mismatch",
|
|
8
|
+
messages: {
|
|
9
|
+
default: paramMessage `Type '${"typeName"}' has a name that differs only by casing from another type: ${"otherNames"}`,
|
|
10
|
+
},
|
|
11
|
+
create(context) {
|
|
12
|
+
const duplicateTrackers = new Map();
|
|
13
|
+
const track = (type) => {
|
|
14
|
+
if (!(type.namespace && type.name) || isTemplateInstance(type)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
let tracker = duplicateTrackers.get(type.namespace);
|
|
18
|
+
if (tracker === undefined) {
|
|
19
|
+
tracker = new DuplicateTracker();
|
|
20
|
+
duplicateTrackers.set(type.namespace, tracker);
|
|
21
|
+
}
|
|
22
|
+
tracker.track(type.name.toLowerCase(), type);
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
model: (en) => track(en),
|
|
26
|
+
union: (en) => track(en),
|
|
27
|
+
enum: (en) => track(en),
|
|
28
|
+
exit: () => {
|
|
29
|
+
for (const [_, tracker] of duplicateTrackers) {
|
|
30
|
+
for (const [_k, duplicates] of tracker.entries()) {
|
|
31
|
+
for (const duplicate of duplicates) {
|
|
32
|
+
context.reportDiagnostic({
|
|
33
|
+
format: {
|
|
34
|
+
typeName: duplicate.name,
|
|
35
|
+
otherNames: duplicates
|
|
36
|
+
.map((d) => d.name)
|
|
37
|
+
.filter((name) => name !== duplicate.name)
|
|
38
|
+
.join(", "),
|
|
39
|
+
},
|
|
40
|
+
target: duplicate,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=no-case-mismatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-case-mismatch.js","sourceRoot":"","sources":["../../../src/rules/no-case-mismatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,UAAU,EACV,kBAAkB,EAClB,YAAY,GACb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,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,iBAAiB,EAAE,CAAC;oBAC7C,KAAK,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;wBACjD,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;4BACnC,OAAO,CAAC,gBAAgB,CAAC;gCACvB,MAAM,EAAE;oCACN,QAAQ,EAAE,SAAS,CAAC,IAAK;oCACzB,UAAU,EAAE,UAAU;yCACnB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;yCAClB,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,CAAC;yCACzC,IAAI,CAAC,IAAI,CAAC;iCACd;gCACD,MAAM,EAAE,SAAS;6BAClB,CAAC,CAAC;wBACL,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-unnamed-union.d.ts","sourceRoot":"","sources":["../../../src/rules/no-unnamed-union.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,kBAAkB;;EAmD7B,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { createRule, paramMessage } from "@typespec/compiler";
|
|
2
|
+
import { $ } from "@typespec/compiler/typekit";
|
|
3
|
+
import { getHeaderFieldName, isHeader, isStatusCode } from "@typespec/http";
|
|
4
|
+
export const noUnnamedUnionRule = createRule({
|
|
5
|
+
name: "no-unnamed-union",
|
|
6
|
+
description: "Azure services should not define a union expression but create a declaration.",
|
|
7
|
+
severity: "warning",
|
|
8
|
+
url: "https://azure.github.io/typespec-azure/docs/libraries/azure-core/rules/no-unnamed-union",
|
|
9
|
+
messages: {
|
|
10
|
+
default: paramMessage `Union expression should be defined as a named union declaration.`,
|
|
11
|
+
},
|
|
12
|
+
create(context) {
|
|
13
|
+
const program = context.program;
|
|
14
|
+
const excludedUnions = new Set();
|
|
15
|
+
const invalidUnions = new Set();
|
|
16
|
+
return {
|
|
17
|
+
modelProperty: (prop) => {
|
|
18
|
+
const type = prop.type;
|
|
19
|
+
if (type.kind !== "Union" || type.name) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (isStatusCode(program, prop) ||
|
|
23
|
+
(isHeader(program, prop) &&
|
|
24
|
+
getHeaderFieldName(program, prop).toLowerCase() === "content-type")) {
|
|
25
|
+
excludedUnions.add(type);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
operation: (operation) => {
|
|
29
|
+
if (operation.returnType.kind === "Union") {
|
|
30
|
+
excludedUnions.add(operation.returnType);
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
union: (union) => {
|
|
34
|
+
if (union.kind === "Union" && !union.name && !isOnlyNullableUnion(program, union)) {
|
|
35
|
+
invalidUnions.add(union);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
exit: () => {
|
|
39
|
+
for (const union of invalidUnions) {
|
|
40
|
+
if (!excludedUnions.has(union)) {
|
|
41
|
+
context.reportDiagnostic({
|
|
42
|
+
format: { enumName: union.name },
|
|
43
|
+
target: union,
|
|
44
|
+
codefixes: [],
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
/** Check if the union is only there to make the type nullable */
|
|
53
|
+
function isOnlyNullableUnion(program, union) {
|
|
54
|
+
return ([...union.variants.values()].filter((v) => v.type !== $(program).intrinsic.null).length === 1);
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=no-unnamed-union.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-unnamed-union.js","sourceRoot":"","sources":["../../../src/rules/no-unnamed-union.ts"],"names":[],"mappings":"AAAA,OAA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C;YACH,CAAC;YACD,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;gBACf,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC;oBAClF,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBAC3B,CAAC;YACH,CAAC;YACD,IAAI,EAAE,GAAG,EAAE;gBACT,KAAK,MAAM,KAAK,IAAI,aAAa,EAAE,CAAC;oBAClC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;wBAC/B,OAAO,CAAC,gBAAgB,CAAC;4BACvB,MAAM,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,IAAI,EAAE;4BAChC,MAAM,EAAE,KAAK;4BACb,SAAS,EAAE,EAAE;yBACd,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC;AAEH,iEAAiE;AACjE,SAAS,mBAAmB,CAAC,OAAgB,EAAE,KAAY;IACzD,OAAO,CACL,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAC9F,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure-tools/typespec-azure-core",
|
|
3
|
-
"version": "0.63.0-dev.
|
|
3
|
+
"version": "0.63.0-dev.5",
|
|
4
4
|
"author": "Microsoft Corporation",
|
|
5
5
|
"description": "TypeSpec Azure Core library",
|
|
6
6
|
"homepage": "https://azure.github.io/typespec-azure",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"dependencies": {},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"clean": "rimraf ./dist ./temp",
|
|
73
|
-
"build": "
|
|
73
|
+
"build": "pnpm run gen-extern-signature && tsc -p . && pnpm run lint-typespec-library",
|
|
74
74
|
"watch": "tsc -p . --watch",
|
|
75
75
|
"gen-extern-signature": "tspd --enable-experimental gen-extern-signature .",
|
|
76
76
|
"lint-typespec-library": "tsp compile . --warn-as-error --import @typespec/library-linter --no-emit",
|