@microsoft/typespec-msgraph 1.0.0-Preview.3 → 1.0.0-Preview.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.
- package/README.md +4 -0
- package/dist/src/components/common-elements.d.ts +2 -0
- package/dist/src/components/common-elements.d.ts.map +1 -1
- package/dist/src/components/common-elements.js +15 -1
- package/dist/src/components/common-elements.js.map +1 -1
- package/dist/src/components/entity-container-element.d.ts.map +1 -1
- package/dist/src/components/reference-target-element.d.ts.map +1 -1
- package/dist/src/decorators/allowed-values.d.ts.map +1 -1
- package/dist/src/decorators/allowed-values.js +20 -2
- package/dist/src/decorators/allowed-values.js.map +1 -1
- package/dist/src/decorators/graph-partial.d.ts.map +1 -1
- package/dist/src/decorators/graph-route.d.ts.map +1 -1
- package/dist/src/decorators/graph-route.js +1 -1
- package/dist/src/decorators/graph-route.js.map +1 -1
- package/dist/src/emitter.d.ts +1 -0
- package/dist/src/emitter.d.ts.map +1 -1
- package/dist/src/emitter.js +16 -8
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/entities/model.d.ts.map +1 -1
- package/dist/src/entities/model.js +7 -6
- package/dist/src/entities/model.js.map +1 -1
- package/dist/src/entities/namespace.d.ts.map +1 -1
- package/dist/src/entities/namespace.js +2 -3
- package/dist/src/entities/namespace.js.map +1 -1
- package/dist/src/entities/operation.js +2 -2
- package/dist/src/entities/operation.js.map +1 -1
- package/dist/src/entities/property.d.ts +1 -1
- package/dist/src/entities/property.d.ts.map +1 -1
- package/dist/src/entities/property.js +6 -18
- package/dist/src/entities/property.js.map +1 -1
- package/dist/src/lib.d.ts +3 -0
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +13 -7
- package/dist/src/lib.js.map +1 -1
- package/dist/src/linter.d.ts.map +1 -1
- package/dist/src/linter.js +26 -2
- package/dist/src/linter.js.map +1 -1
- package/dist/src/rules/allowed-values.d.ts +3 -0
- package/dist/src/rules/allowed-values.d.ts.map +1 -1
- package/dist/src/rules/allowed-values.js +32 -1
- package/dist/src/rules/allowed-values.js.map +1 -1
- package/dist/src/rules/collections.d.ts +4 -0
- package/dist/src/rules/collections.d.ts.map +1 -0
- package/dist/src/rules/collections.js +32 -0
- package/dist/src/rules/collections.js.map +1 -0
- package/dist/src/rules/contains.d.ts +6 -0
- package/dist/src/rules/contains.d.ts.map +1 -1
- package/dist/src/rules/contains.js +64 -4
- package/dist/src/rules/contains.js.map +1 -1
- package/dist/src/rules/entity.d.ts +3 -0
- package/dist/src/rules/entity.d.ts.map +1 -1
- package/dist/src/rules/entity.js +48 -1
- package/dist/src/rules/entity.js.map +1 -1
- package/dist/src/rules/enum.d.ts +9 -0
- package/dist/src/rules/enum.d.ts.map +1 -1
- package/dist/src/rules/enum.js +79 -3
- package/dist/src/rules/enum.js.map +1 -1
- package/dist/src/rules/index.d.ts +2 -0
- package/dist/src/rules/index.d.ts.map +1 -1
- package/dist/src/rules/index.js +2 -0
- package/dist/src/rules/index.js.map +1 -1
- package/dist/src/rules/limited-charset.d.ts.map +1 -1
- package/dist/src/rules/model.d.ts +3 -0
- package/dist/src/rules/model.d.ts.map +1 -1
- package/dist/src/rules/model.js +62 -20
- package/dist/src/rules/model.js.map +1 -1
- package/dist/src/rules/namespace.js +1 -1
- package/dist/src/rules/namespace.js.map +1 -1
- package/dist/src/rules/properties.d.ts +10 -0
- package/dist/src/rules/properties.d.ts.map +1 -0
- package/dist/src/rules/properties.js +118 -0
- package/dist/src/rules/properties.js.map +1 -0
- package/dist/src/supressions/csdl-suppression-rules.d.ts +8 -0
- package/dist/src/supressions/csdl-suppression-rules.d.ts.map +1 -0
- package/dist/src/supressions/csdl-suppression-rules.js +28 -0
- package/dist/src/supressions/csdl-suppression-rules.js.map +1 -0
- package/dist/src/supressions/path-util.d.ts +17 -0
- package/dist/src/supressions/path-util.d.ts.map +1 -0
- package/dist/src/supressions/path-util.js +65 -0
- package/dist/src/supressions/path-util.js.map +1 -0
- package/dist/src/supressions/suppression-collector.d.ts +10 -0
- package/dist/src/supressions/suppression-collector.d.ts.map +1 -0
- package/dist/src/supressions/suppression-collector.js +158 -0
- package/dist/src/supressions/suppression-collector.js.map +1 -0
- package/dist/src/utils.d.ts +8 -2
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +61 -4
- package/dist/src/utils.js.map +1 -1
- package/lib/schema-Prod-v1.0.tsp +312 -0
- package/package.json +23 -18
|
@@ -1,20 +1,8 @@
|
|
|
1
|
-
import { getPropertyTypeName } from "../utils.js";
|
|
2
|
-
export function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
let defaultValueValue = undefined;
|
|
7
|
-
switch (property.default.kind) {
|
|
8
|
-
case "String":
|
|
9
|
-
case "Boolean":
|
|
10
|
-
case "Number":
|
|
11
|
-
defaultValueValue = property.default.value;
|
|
12
|
-
break;
|
|
13
|
-
case "EnumMember":
|
|
14
|
-
defaultValueValue = property.defaultValue.value.name;
|
|
15
|
-
break;
|
|
16
|
-
default:
|
|
17
|
-
return undefined;
|
|
1
|
+
import { getPropertyTypeName, getDefaultPropertyValue } from "../utils.js";
|
|
2
|
+
export function getDefaultPropertyRecord(program, property) {
|
|
3
|
+
let defaultValue = getDefaultPropertyValue(property);
|
|
4
|
+
if (defaultValue === undefined) {
|
|
5
|
+
return defaultValue;
|
|
18
6
|
}
|
|
19
7
|
const propType = getPropertyTypeName(program, property.type);
|
|
20
8
|
let defaultValueKey = "String";
|
|
@@ -59,6 +47,6 @@ export function getDefaultPropertyValue(program, property) {
|
|
|
59
47
|
}
|
|
60
48
|
return undefined;
|
|
61
49
|
}
|
|
62
|
-
return { [defaultValueKey]:
|
|
50
|
+
return { [defaultValueKey]: defaultValue };
|
|
63
51
|
}
|
|
64
52
|
//# sourceMappingURL=property.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"property.js","sourceRoot":"","sources":["../../../src/entities/property.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mB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C,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;gBAClC,eAAe,GAAG,QAAQ,CAAC;gBAC3B,MAAM;YACR,CAAC;YACD,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,OAAO,EAAE,CAAC,eAAe,CAAC,EAAE,YAAY,EAAE,CAAC;AAC7C,CAAC"}
|
package/dist/src/lib.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const namespace = "MsGraph";
|
|
2
2
|
export interface MsGraphEmitterOptions {
|
|
3
3
|
filename?: string;
|
|
4
|
+
baseDir?: string;
|
|
4
5
|
}
|
|
5
6
|
export declare const $flags: import("@typespec/compiler").PackageFlags;
|
|
6
7
|
export declare const reportDiagnostic: <C extends "decorator-missing-dependencies" | "element-missing-dependencies" | "decorator-invalid-use" | "model-invalid-use" | "singleton-invalid-name" | "extends-invalid-use" | "type-invalid-use" | "container-invalid-use", M extends keyof {
|
|
@@ -98,6 +99,7 @@ export declare const reportDiagnostic: <C extends "decorator-missing-dependencie
|
|
|
98
99
|
readonly interfaceWithPartialBindingType: import("@typespec/compiler").CallableMessage<["interface", "type"]>;
|
|
99
100
|
readonly propertyTypeCannotBeStringLiteral: import("@typespec/compiler").CallableMessage<["property", "type"]>;
|
|
100
101
|
readonly sharedEntityCannotCreateSingletonOrEntitySet: import("@typespec/compiler").CallableMessage<["type"]>;
|
|
102
|
+
readonly collectionShouldNotBeEnum: import("@typespec/compiler").CallableMessage<["member", "enum"]>;
|
|
101
103
|
};
|
|
102
104
|
"container-invalid-use": {
|
|
103
105
|
readonly default: "@container can only be used once in a compilation unit.";
|
|
@@ -197,6 +199,7 @@ export declare const reportDiagnostic: <C extends "decorator-missing-dependencie
|
|
|
197
199
|
readonly interfaceWithPartialBindingType: import("@typespec/compiler").CallableMessage<["interface", "type"]>;
|
|
198
200
|
readonly propertyTypeCannotBeStringLiteral: import("@typespec/compiler").CallableMessage<["property", "type"]>;
|
|
199
201
|
readonly sharedEntityCannotCreateSingletonOrEntitySet: import("@typespec/compiler").CallableMessage<["type"]>;
|
|
202
|
+
readonly collectionShouldNotBeEnum: import("@typespec/compiler").CallableMessage<["member", "enum"]>;
|
|
200
203
|
};
|
|
201
204
|
"container-invalid-use": {
|
|
202
205
|
readonly default: "@container can only be used once in a compilation unit.";
|
package/dist/src/lib.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,SAAS,YAAY,CAAC;AAEnC,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAsBD,eAAO,MAAM,MAAM,2CAEjB,CAAC;AAEH,eAAO,MAAQ,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiIpB,CAAC"}
|
package/dist/src/lib.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createTypeSpecLibrary, definePackageFlags, paramMessage } from "@typespec/compiler";
|
|
1
|
+
import { createTypeSpecLibrary, definePackageFlags, paramMessage, } from "@typespec/compiler";
|
|
2
2
|
export const namespace = "MsGraph";
|
|
3
3
|
const EmitterOptionsSchema = {
|
|
4
4
|
type: "object",
|
|
@@ -7,7 +7,12 @@ const EmitterOptionsSchema = {
|
|
|
7
7
|
filename: {
|
|
8
8
|
type: "string",
|
|
9
9
|
nullable: true,
|
|
10
|
-
description: "The name of the generated CSDL file. If not specified, it defaults to `workload.csdl`."
|
|
10
|
+
description: "The name of the generated CSDL file. If not specified, it defaults to `workload.csdl`.",
|
|
11
|
+
},
|
|
12
|
+
baseDir: {
|
|
13
|
+
type: "string",
|
|
14
|
+
nullable: true,
|
|
15
|
+
description: "Absolute path of base directory (or repo directory) for relative paths in suppression output. If not specified, uses the project root directory (where the command is ran).",
|
|
11
16
|
},
|
|
12
17
|
},
|
|
13
18
|
required: [],
|
|
@@ -107,7 +112,7 @@ export const { reportDiagnostic } = createTypeSpecLibrary({
|
|
|
107
112
|
severity: "error",
|
|
108
113
|
messages: {
|
|
109
114
|
default: paramMessage `Model '${"model"}' should be an operationParameter, entity or complex type.`,
|
|
110
|
-
}
|
|
115
|
+
},
|
|
111
116
|
},
|
|
112
117
|
"singleton-invalid-name": {
|
|
113
118
|
severity: "error",
|
|
@@ -119,7 +124,7 @@ export const { reportDiagnostic } = createTypeSpecLibrary({
|
|
|
119
124
|
severity: "error",
|
|
120
125
|
messages: {
|
|
121
126
|
default: paramMessage `A ${"type"} model can only extend a ${"type"} baseModel`,
|
|
122
|
-
namespaces:
|
|
127
|
+
namespaces: "A model can only extend other models in a different logical namespace. Use @graphPartial instead.",
|
|
123
128
|
},
|
|
124
129
|
},
|
|
125
130
|
"type-invalid-use": {
|
|
@@ -132,14 +137,15 @@ export const { reportDiagnostic } = createTypeSpecLibrary({
|
|
|
132
137
|
interfaceWithPartialBindingType: paramMessage `The interface "${"interface"}" targets a partial or non-owned type "${"type"}" and as such cannot declare operations.`,
|
|
133
138
|
propertyTypeCannotBeStringLiteral: paramMessage `The type for "${"property"}" cannot be a ${"type"} literal.`,
|
|
134
139
|
sharedEntityCannotCreateSingletonOrEntitySet: paramMessage `The shared entity "${"type"}" cannot be the type of a routed interface that creates a Singleton or an EntitySet`,
|
|
135
|
-
|
|
140
|
+
collectionShouldNotBeEnum: paramMessage `Collection property "${"member"}" uses enum "${"enum"}". Consider using @graphFlags to mark the enum as flags instead of using a collection. For information, refer to the [API guidelines](https://github.com/microsoft/api-guidelines/blob/vNext/graph/patterns/enums.md#flag-enums-or-collection-of-enums).`,
|
|
141
|
+
},
|
|
136
142
|
},
|
|
137
143
|
"container-invalid-use": {
|
|
138
144
|
severity: "error",
|
|
139
145
|
messages: {
|
|
140
146
|
default: "@container can only be used once in a compilation unit.",
|
|
141
|
-
}
|
|
142
|
-
}
|
|
147
|
+
},
|
|
148
|
+
},
|
|
143
149
|
},
|
|
144
150
|
emitter: { options: EmitterOptionsSchema },
|
|
145
151
|
});
|
package/dist/src/lib.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,GACb,MAAM,oBAAoB,CAAC;AAE5B,MAAM,CAAC,MAAM,SAAS,GAAG,SAAS,CAAC;AAOnC,MAAM,oBAAoB,GAA0C;IAClE,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,KAAK;IAC3B,UAAU,EAAE;QACV,QAAQ,EAAE;YACR,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,WAAW,EACT,wFAAwF;SAC3F;QACD,OAAO,EAAE;YACP,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,WAAW,EACT,6KAA6K;SAChL;KACF;IACD,QAAQ,EAAE,EAAE;CACb,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG,kBAAkB,CAAC;IACvC,uBAAuB,EAAE,KAAK;CAC/B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,EAAE,gBAAgB,EAAE,GAAG,qBAAqB,CAAC;IACxD,IAAI,EAAE,6BAA6B;IACnC,WAAW,EAAE;QACX,gCAAgC,EAAE;YAChC,QA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yBAAyB,EAAE,YAAY,CAAA,wBAAwB,QAAQ,gBAAgB,MAAM,0PAA0P;aACxV;SACF;QACD,uBAAuB,EAAE;YACvB,QAAQ,EAAE,OAAO;YACjB,QAAQ,EAAE;gBACR,OAAO,EAAE,yDAAyD;aACnE;SACF;KACF;IACD,OAAO,EAAE,EAAE,OAAO,EAAE,oBAA6D,EAAE;CAC3E,CAAC,CAAC"}
|
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":"AAyBA,eAAO,MAAM,OAAO,+CAqDlB,CAAC"}
|
package/dist/src/linter.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { defineLinter } from "@typespec/compiler";
|
|
2
|
-
import { useEvolvableEnumRule, mediaTypeValuesShouldBeMinimallyFormattedForMIMETypes, interfaceNavigationSourceShouldHaveMediaIf$ValueIsSpecified, getPutPostAndPatchOperationsShouldHaveSelectDecorator, useRecordTypeInsteadOfDictionary, dictionaryTypeIsMostlyUsedWithRecordType, containedNavigationPropertyTypeShouldNotBeExternallyReferenced, entityAndComplexPropertyNameShouldNotBeName, validateCoreElementsHaveDocString, operationParametersShouldHaveRequiredBeforeOptional } from "./rules/index.js";
|
|
2
|
+
import { useEvolvableEnumRule, collectionPropertyShouldNotBeNullable, collectionShouldNotBeEnum, mediaTypeValuesShouldBeMinimallyFormattedForMIMETypes, interfaceNavigationSourceShouldHaveMediaIf$ValueIsSpecified, getPutPostAndPatchOperationsShouldHaveSelectDecorator, useRecordTypeInsteadOfDictionary, dictionaryTypeIsMostlyUsedWithRecordType, containedNavigationPropertyTypeShouldNotBeExternallyReferenced, entityAndComplexPropertyNameShouldNotBeName, validateCoreElementsHaveDocString, operationParametersShouldHaveRequiredBeforeOptional, containedEntityShouldNotHaveEntitySet, referenceIdPropertyShouldBeNavigationProperty, useProperDefaultRecord, shouldNotUseUnnecessaryInheritance, nullableBooleanShouldBeEnum, nullableEnumsShouldAddAdditionalMember, allowedValuesCsdlCompatibility, useCreatedInPropertyNames, useModifiedInPropertyNames } from "./rules/index.js";
|
|
3
3
|
export const $linter = defineLinter({
|
|
4
4
|
rules: [
|
|
5
5
|
useEvolvableEnumRule,
|
|
6
|
+
collectionPropertyShouldNotBeNullable,
|
|
7
|
+
collectionShouldNotBeEnum,
|
|
6
8
|
mediaTypeValuesShouldBeMinimallyFormattedForMIMETypes,
|
|
7
9
|
interfaceNavigationSourceShouldHaveMediaIf$ValueIsSpecified,
|
|
8
10
|
getPutPostAndPatchOperationsShouldHaveSelectDecorator,
|
|
@@ -11,12 +13,33 @@ export const $linter = defineLinter({
|
|
|
11
13
|
containedNavigationPropertyTypeShouldNotBeExternallyReferenced,
|
|
12
14
|
entityAndComplexPropertyNameShouldNotBeName,
|
|
13
15
|
validateCoreElementsHaveDocString,
|
|
14
|
-
operationParametersShouldHaveRequiredBeforeOptional
|
|
16
|
+
operationParametersShouldHaveRequiredBeforeOptional,
|
|
17
|
+
containedEntityShouldNotHaveEntitySet,
|
|
18
|
+
referenceIdPropertyShouldBeNavigationProperty,
|
|
19
|
+
useProperDefaultRecord,
|
|
20
|
+
shouldNotUseUnnecessaryInheritance,
|
|
21
|
+
nullableBooleanShouldBeEnum,
|
|
22
|
+
nullableEnumsShouldAddAdditionalMember,
|
|
23
|
+
allowedValuesCsdlCompatibility,
|
|
24
|
+
useCreatedInPropertyNames,
|
|
25
|
+
useModifiedInPropertyNames
|
|
15
26
|
],
|
|
16
27
|
ruleSets: {
|
|
17
28
|
recommended: {
|
|
18
29
|
enable: {
|
|
30
|
+
// onboarding csdl linter rules */
|
|
19
31
|
[`@microsoft/typespec-msgraph/${useEvolvableEnumRule.name}`]: true,
|
|
32
|
+
[`@microsoft/typespec-msgraph/${collectionPropertyShouldNotBeNullable.name}`]: true,
|
|
33
|
+
[`@microsoft/typespec-msgraph/${collectionShouldNotBeEnum.name}`]: true,
|
|
34
|
+
[`@microsoft/typespec-msgraph/${nullableBooleanShouldBeEnum.name}`]: true,
|
|
35
|
+
[`@microsoft/typespec-msgraph/${nullableEnumsShouldAddAdditionalMember.name}`]: true,
|
|
36
|
+
[`@microsoft/typespec-msgraph/${containedEntityShouldNotHaveEntitySet.name}`]: true,
|
|
37
|
+
[`@microsoft/typespec-msgraph/${shouldNotUseUnnecessaryInheritance.name}`]: true,
|
|
38
|
+
[`@microsoft/typespec-msgraph/${referenceIdPropertyShouldBeNavigationProperty.name}`]: true,
|
|
39
|
+
[`@microsoft/typespec-msgraph/${useCreatedInPropertyNames.name}`]: true,
|
|
40
|
+
[`@microsoft/typespec-msgraph/${useModifiedInPropertyNames.name}`]: true,
|
|
41
|
+
[`@microsoft/typespec-msgraph/${useProperDefaultRecord.name}`]: true,
|
|
42
|
+
// library recommended rules
|
|
20
43
|
[`@microsoft/typespec-msgraph/${mediaTypeValuesShouldBeMinimallyFormattedForMIMETypes.name}`]: true,
|
|
21
44
|
[`@microsoft/typespec-msgraph/${interfaceNavigationSourceShouldHaveMediaIf$ValueIsSpecified.name}`]: true,
|
|
22
45
|
[`@microsoft/typespec-msgraph/${getPutPostAndPatchOperationsShouldHaveSelectDecorator.name}`]: true,
|
|
@@ -26,6 +49,7 @@ export const $linter = defineLinter({
|
|
|
26
49
|
[`@microsoft/typespec-msgraph/${entityAndComplexPropertyNameShouldNotBeName.name}`]: true,
|
|
27
50
|
[`@microsoft/typespec-msgraph/${validateCoreElementsHaveDocString.name}`]: true,
|
|
28
51
|
[`@microsoft/typespec-msgraph/${operationParametersShouldHaveRequiredBeforeOptional.name}`]: true,
|
|
52
|
+
[`@microsoft/typespec-msgraph/${allowedValuesCsdlCompatibility.name}`]: true,
|
|
29
53
|
}
|
|
30
54
|
}
|
|
31
55
|
}
|
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,EACL,oBAAoB,EACpB,qDAAqD,EACrD,2DAA2D,EAC3D,qDAAqD,EACrD,gCAAgC,EAChC,wCAAwC,EACxC,8DAA8D,EAC9D,2CAA2C,EAC3C,iCAAiC,EACjC,mDAAmD,
|
|
1
|
+
{"version":3,"file":"linter.js","sourceRoot":"","sources":["../../src/linter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EACL,oBAAoB,EACpB,qCAAqC,EACrC,yBAAyB,EACzB,qDAAqD,EACrD,2DAA2D,EAC3D,qDAAqD,EACrD,gCAAgC,EAChC,wCAAwC,EACxC,8DAA8D,EAC9D,2CAA2C,EAC3C,iCAAiC,EACjC,mDAAmD,EACnD,qCAAqC,EACrC,6CAA6C,EAC7C,sBAAsB,EACtB,kCAAkC,EAClC,2BAA2B,EAC3B,sCAAsC,EACtC,8BAA8B,EAC9B,yBAAyB,EACzB,0BAA0B,EAC3B,MAAM,kBAAkB,CAAC;AAE1B,MAAM,CAAC,MAAM,OAAO,GAAG,YAAY,CAAC;IAClC,KAAK,EAAE;QACL,oBAAoB;QACpB,qCAAqC;QACrC,yBAAyB;QACzB,qDAAqD;QACrD,2DAA2D;QAC3D,qDAAqD;QACrD,gCAAgC;QAChC,wCAAwC;QACxC,8DAA8D;QAC9D,2CAA2C;QAC3C,iCAAiC;QACjC,mDAAmD;QACnD,qCAAqC;QACrC,6CAA6C;QAC7C,sBAAsB;QACtB,kCAAkC;QAClC,2BAA2B;QAC3B,sCAAsC;QACtC,8BAA8B;QAC9B,yBAAyB;QACzB,0BAA0B;KAC3B;IACD,QAAQ,EAAE;QACR,WAAW,EAAE;YACX,MAAM,EAAE;gBACN,kCAAkC;gBAClC,CAAC,+BAA+B,oBA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E,CAAC,EAAE,IAAI;gBAC/E,CAAC,+BAA+B,mDAAmD,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI;gBACjG,CAAC,+BAA+B,8BAA8B,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI;aAC7E;SACF;KACF;CACF,CAAC,CAAC"}
|
|
@@ -4,4 +4,7 @@ import { Program } from "@typespec/compiler";
|
|
|
4
4
|
* @allowedValues cannot have empty values
|
|
5
5
|
*/
|
|
6
6
|
export declare function validateAllowedValuesCannotBeEmpty(program: Program): void;
|
|
7
|
+
export declare const allowedValuesCsdlCompatibility: import("@typespec/compiler").LinterRuleDefinition<"allowed-values-csdl-compatibility", {
|
|
8
|
+
readonly default: "MsGraph generation only supports string and numeric values for annotations. Other types may not render correctly.";
|
|
9
|
+
}>;
|
|
7
10
|
//# sourceMappingURL=allowed-values.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"allowed-values.d.ts","sourceRoot":"","sources":["../../../src/rules/allowed-values.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"allowed-values.d.ts","sourceRoot":"","sources":["../../../src/rules/allowed-values.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,OAAO,EAGR,MAAM,oBAAoB,CAAC;AAK5B;;;GAGG;AACH,wBAAgB,kCAAkC,CAAC,OAAO,EAAE,OAAO,QAmDlE;AAED,eAAO,MAAM,8BAA8B;;EAiCzC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { navigateTypesInNamespace } from "@typespec/compiler";
|
|
1
|
+
import { createRule, navigateTypesInNamespace, } from "@typespec/compiler";
|
|
2
2
|
import { GetDeclaredNamespaces } from "../entities/namespace.js";
|
|
3
3
|
import { getAllowedValues, hasAllowedValues, isAllowedValuesArgumentsEmpty, isAllowedValuesPrimitive } from "../index.js";
|
|
4
4
|
import { reportDiagnostic } from "../lib.js";
|
|
@@ -56,4 +56,35 @@ export function validateAllowedValuesCannotBeEmpty(program) {
|
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
+
export const allowedValuesCsdlCompatibility = createRule({
|
|
60
|
+
name: "allowed-values-csdl-compatibility",
|
|
61
|
+
severity: "warning",
|
|
62
|
+
description: "Warns when @allowedValues contains non-string/numeric values that may not render correctly in CSDL",
|
|
63
|
+
messages: {
|
|
64
|
+
default: "MsGraph generation only supports string and numeric values for annotations. Other types may not render correctly.",
|
|
65
|
+
},
|
|
66
|
+
create(context) {
|
|
67
|
+
return {
|
|
68
|
+
modelProperty(property) {
|
|
69
|
+
if (!hasAllowedValues(context.program, property)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const allowedValues = getAllowedValues(context.program, property);
|
|
73
|
+
if (!(allowedValues === null || allowedValues === void 0 ? void 0 : allowedValues.values) || allowedValues.values.length === 0) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
// Check if any values are not strings or numbers
|
|
77
|
+
const hasNonCsdlCompatibleValues = allowedValues.values.some(value => {
|
|
78
|
+
const valueType = typeof value;
|
|
79
|
+
return valueType !== 'string' && valueType !== 'number' && valueType !== 'bigint';
|
|
80
|
+
});
|
|
81
|
+
if (hasNonCsdlCompatibleValues) {
|
|
82
|
+
context.reportDiagnostic({
|
|
83
|
+
target: property,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
});
|
|
59
90
|
//# sourceMappingURL=allowed-values.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"allowed-values.js","sourceRoot":"","sources":["../../../src/rules/allowed-values.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"allowed-values.js","sourceRoot":"","sources":["../../../src/rules/allowed-values.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EACV,wBAAwB,GACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,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,OAAO,KAAK,CAAC;oBAC/B,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,QAAQ,CAAC;gBACpF,CAAC,CAAC,CAAC;gBAEH,IAAI,0BAA0B,EAAE,CAAC;oBAC/B,OAAO,CAAC,gBAAgB,CAAC;wBACvB,MAAM,EAAE,QAAQ;qBACjB,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const collectionPropertyShouldNotBeNullable: import("@typespec/compiler").LinterRuleDefinition<"collection-property-should-not-be-nullable", {
|
|
2
|
+
readonly default: import("@typespec/compiler").CallableMessage<["property"]>;
|
|
3
|
+
}>;
|
|
4
|
+
//# sourceMappingURL=collections.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../../../src/rules/collections.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qCAAqC;;EA8BhD,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createRule, paramMessage } from "@typespec/compiler";
|
|
2
|
+
import { isTypeCollection, isTypeNullable } from "../utils.js";
|
|
3
|
+
export const collectionPropertyShouldNotBeNullable = createRule({
|
|
4
|
+
name: "collection-property-should-not-be-nullable",
|
|
5
|
+
severity: "warning",
|
|
6
|
+
description: "Collection-valued properties cannot be nullable.",
|
|
7
|
+
messages: {
|
|
8
|
+
default: paramMessage `Collection property '${"property"}' cannot be nullable. Collections on Graph may not contain null values.`,
|
|
9
|
+
},
|
|
10
|
+
create(context) {
|
|
11
|
+
return {
|
|
12
|
+
modelProperty(property) {
|
|
13
|
+
// Check if this is a collection type
|
|
14
|
+
if (!isTypeCollection(context.program, property.type)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
// Check if the collection is nullable
|
|
18
|
+
if (!isTypeNullable(context.program, property.type)) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
context.reportDiagnostic({
|
|
22
|
+
target: property,
|
|
23
|
+
messageId: "default",
|
|
24
|
+
format: {
|
|
25
|
+
property: property.name,
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=collections.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections.js","sourceRoot":"","sources":["../../../src/rules/collections.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE/D,MAAM,CAAC,MAAM,qCAAqC,GAAG,UAAU,CAAC;IAC9D,IAAI,EAAE,4CAA4C;IAClD,QAAQ,EAAE,SAAS;IACnB,WAAW,EAAE,kDAAkD;IAC/D,QAAQ,EAAE;QACR,OAAO,EAAE,YAAY,CAAA,wBAAwB,UAAU,yEAAyE;KACjI;IACD,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,aAAa,CAAC,QAAQ;gBACpB,qCAAqC;gBACrC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;oBACtD,OAAO;gBACT,CAAC;gBAED,sCAAsC;gBACtC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;oBACpD,OAAO;gBACT,CAAC;gBAED,OAAO,CAAC,gBAAgB,CAAC;oBACvB,MAAM,EAAE,QAAQ;oBAChB,SAAS,EAAE,SAAS;oBACpB,MAAM,EAAE;wBACN,QAAQ,EAAE,QAAQ,CAAC,IAAI;qBACxB;iBACF,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -3,4 +3,10 @@ import { Program } from "@typespec/compiler";
|
|
|
3
3
|
* @contains applies to a navigation property.
|
|
4
4
|
*/
|
|
5
5
|
export declare function validateContainsOnlyAppliesToNavigationProperty(program: Program): void;
|
|
6
|
+
/**
|
|
7
|
+
* Validates that entities used with @contains decorator should not also be used as independent EntitySets.
|
|
8
|
+
*/
|
|
9
|
+
export declare const containedEntityShouldNotHaveEntitySet: import("@typespec/compiler").LinterRuleDefinition<"contained-entity-should-not-have-entity-set", {
|
|
10
|
+
readonly default: import("@typespec/compiler").CallableMessage<["entityName"]>;
|
|
11
|
+
}>;
|
|
6
12
|
//# sourceMappingURL=contains.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contains.d.ts","sourceRoot":"","sources":["../../../src/rules/contains.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"contains.d.ts","sourceRoot":"","sources":["../../../src/rules/contains.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,OAAO,EAKR,MAAM,oBAAoB,CAAC;AAW5B;;GAEG;AACH,wBAAgB,+CAA+C,CAAC,OAAO,EAAE,OAAO,QAwB/E;AAED;;GAEG;AACH,eAAO,MAAM,qCAAqC;;EAuEhD,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { navigateTypesInNamespace } from "@typespec/compiler";
|
|
2
|
-
import { isContains } from "../index.js";
|
|
1
|
+
import { createRule, navigateTypesInNamespace, paramMessage, } from "@typespec/compiler";
|
|
2
|
+
import { getGraphRoutePaths, hasGraphRoute, isContains } from "../index.js";
|
|
3
3
|
import { reportDiagnostic } from "../lib.js";
|
|
4
|
-
import { isNavigationProperty } from "../utils.js";
|
|
4
|
+
import { getInterfaceNavigationSourceType, isNavigationProperty, removeRoutePathParams, } from "../utils.js";
|
|
5
5
|
import { GetDeclaredNamespaces } from "../entities/namespace.js";
|
|
6
6
|
/**
|
|
7
7
|
* @contains applies to a navigation property.
|
|
@@ -29,5 +29,65 @@ export function validateContainsOnlyAppliesToNavigationProperty(program) {
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Validates that entities used with @contains decorator should not also be used as independent EntitySets.
|
|
34
|
+
*/
|
|
35
|
+
export const containedEntityShouldNotHaveEntitySet = createRule({
|
|
36
|
+
name: "contained-entity-should-not-have-entity-set",
|
|
37
|
+
severity: "warning",
|
|
38
|
+
description: "Entities used with @contains should not also be used as independent EntitySets or Singletons",
|
|
39
|
+
messages: {
|
|
40
|
+
default: paramMessage `The entity "${"entityName"}" is used with @contains decorator and should not also be used as an independent EntitySet or Singleton.`,
|
|
41
|
+
},
|
|
42
|
+
create(context) {
|
|
43
|
+
const containedEntityTypes = new Set();
|
|
44
|
+
return {
|
|
45
|
+
modelProperty: (property) => {
|
|
46
|
+
// Collect entities used with @contains
|
|
47
|
+
if (!isContains(context.program, property) ||
|
|
48
|
+
!isNavigationProperty(context.program, property)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
// Get the entity type from the property
|
|
52
|
+
let entityType = property.type;
|
|
53
|
+
// Handle array types (e.g., OrderItem[])
|
|
54
|
+
if (entityType.kind === "Model" && entityType.name === "Array" && entityType.indexer) {
|
|
55
|
+
entityType = entityType.indexer.value;
|
|
56
|
+
}
|
|
57
|
+
if (entityType.kind === "Model") {
|
|
58
|
+
containedEntityTypes.add(entityType);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
interface: ($interface) => {
|
|
62
|
+
// Check for EntitySet/Singleton conflicts with collected @contains entities
|
|
63
|
+
if (!hasGraphRoute(context.program, $interface)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
// Check if this is a top-level navigation source (direct child of EntityContainer)
|
|
67
|
+
const graphRoutes = getGraphRoutePaths(context.program, $interface);
|
|
68
|
+
if (!graphRoutes || graphRoutes.length === 0) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const hasTopLevelRoute = graphRoutes.some((route) => removeRoutePathParams(route).split("/").length === 1);
|
|
72
|
+
if (!hasTopLevelRoute) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
// Get the entity type this interface operates on
|
|
76
|
+
const entityType = getInterfaceNavigationSourceType(context.program, $interface);
|
|
77
|
+
if (!entityType || entityType.kind !== "Model") {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
// Check if this entity type is also used with @contains
|
|
81
|
+
if (containedEntityTypes.has(entityType)) {
|
|
82
|
+
context.reportDiagnostic({
|
|
83
|
+
target: $interface,
|
|
84
|
+
format: {
|
|
85
|
+
entityName: entityType.name,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
});
|
|
33
93
|
//# sourceMappingURL=contains.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contains.js","sourceRoot":"","sources":["../../../src/rules/contains.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"contains.js","sourceRoot":"","sources":["../../../src/rules/contains.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,UAAU,EACV,wBAAwB,EACxB,YAAY,GACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EACL,gCAAgC,EAChC,oBAAoB,EAEpB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE;;GAEG;AACH,MAAM,UAAU,+CAA+C,CAAC,OAAgB;IAC9E,KAAK,MAAM,SAAS,IAAI,qBAAqB,CAAC,OAAO,CAAC,EAAE,CAAC;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AC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -7,4 +7,7 @@ export declare function validateEntityAndComplexAreMutuallyExclusive(program: Pr
|
|
|
7
7
|
export declare const entityAndComplexPropertyNameShouldNotBeName: import("@typespec/compiler").LinterRuleDefinition<"entity-complex-property-names-should-not-be-name", {
|
|
8
8
|
readonly default: import("@typespec/compiler").CallableMessage<[]>;
|
|
9
9
|
}>;
|
|
10
|
+
export declare const referenceIdPropertyShouldBeNavigationProperty: import("@typespec/compiler").LinterRuleDefinition<"reference-id-property-should-be-navigation-property", {
|
|
11
|
+
readonly default: import("@typespec/compiler").CallableMessage<["property", "entityType", "navigationPropertyName"]>;
|
|
12
|
+
}>;
|
|
10
13
|
//# sourceMappingURL=entity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../../src/rules/entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EACsH,MAAM,oBAAoB,CAAC;AAMjK,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,QAsDzD;AAED,wBAAgB,mDAAmD,CAAC,OAAO,EAAE,OAAO,QA2CnF;AAGD,wBAAgB,8CAA8C,CAAC,OAAO,EAAE,OAAO,QA2B9E;AAED,wBAAgB,4DAA4D,CAAE,OAAO,EAAE,OAAO,QA0B7F;AAED,wBAAgB,4CAA4C,CAAC,OAAO,EAAE,OAAO,QAmB5E;AAED,eAAO,MAAM,2CAA2C;;EA2BtD,CAAA"}
|
|
1
|
+
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../../src/rules/entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EACsH,MAAM,oBAAoB,CAAC;AAMjK,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,QAsDzD;AAED,wBAAgB,mDAAmD,CAAC,OAAO,EAAE,OAAO,QA2CnF;AAGD,wBAAgB,8CAA8C,CAAC,OAAO,EAAE,OAAO,QA2B9E;AAED,wBAAgB,4DAA4D,CAAE,OAAO,EAAE,OAAO,QA0B7F;AAED,wBAAgB,4CAA4C,CAAC,OAAO,EAAE,OAAO,QAmB5E;AAED,eAAO,MAAM,2CAA2C;;EA2BtD,CAAA;AAEF,eAAO,MAAM,6CAA6C;;EA6CxD,CAAC"}
|
package/dist/src/rules/entity.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isKey, navigateTypesInNamespace, walkPropertiesInherited, isArrayModelType, createRule, paramMessage } from "@typespec/compiler";
|
|
2
|
-
import { isComplex, isDirectEntity, isOwnerless, isSharedEntity, isPartial, isEntity } from "../index.js";
|
|
2
|
+
import { isComplex, isDirectEntity, isOwnerless, isSharedEntity, isPartial, isEntity, getEntity } from "../index.js";
|
|
3
3
|
import { reportDiagnostic } from "../lib.js";
|
|
4
4
|
import { isTypeNullable, isExcludedLibraryType, isSameNamespace, extractTypesFromUnion, getInterfaceNavigationSourceType, isNavigationProperty, isTypeDefinedInExternalLibrary, isTypeDefinedInLocalProject, isParentSharedEntity } from "../utils.js";
|
|
5
5
|
import { GetDeclaredNamespaces } from "../entities/namespace.js";
|
|
@@ -193,6 +193,53 @@ export const entityAndComplexPropertyNameShouldNotBeName = createRule({
|
|
|
193
193
|
};
|
|
194
194
|
},
|
|
195
195
|
});
|
|
196
|
+
export const referenceIdPropertyShouldBeNavigationProperty = createRule({
|
|
197
|
+
name: "reference-id-property-should-be-navigation-property",
|
|
198
|
+
severity: "warning",
|
|
199
|
+
description: "Properties ending with 'Id' that reference existing entity types should use navigation properties instead",
|
|
200
|
+
messages: {
|
|
201
|
+
default: paramMessage `Property '${"property"}' appears to reference entity type '${"entityType"}'. Consider using a navigation property named '${"navigationPropertyName"}' with @references decorator instead of an ID property.`,
|
|
202
|
+
},
|
|
203
|
+
create(context) {
|
|
204
|
+
return {
|
|
205
|
+
modelProperty: (property) => {
|
|
206
|
+
if (!property.model || !isEntity(context.program, property.model)) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
// Check if property name ends with "Id" and extract prefix
|
|
210
|
+
const prefix = trySplitAtSuffix(property.name, "Id");
|
|
211
|
+
if (!prefix) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (property.type.kind !== "Scalar") {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const potentialEntityType = getEntity(context.program, prefix);
|
|
218
|
+
if (!potentialEntityType) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
const existingNavProperty = property.model.properties.get(prefix);
|
|
222
|
+
if (existingNavProperty && isNavigationProperty(context.program, existingNavProperty)) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
context.reportDiagnostic({
|
|
226
|
+
target: property,
|
|
227
|
+
format: {
|
|
228
|
+
property: property.name,
|
|
229
|
+
entityType: potentialEntityType.name,
|
|
230
|
+
navigationPropertyName: prefix,
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
function trySplitAtSuffix(value, suffix) {
|
|
238
|
+
if (value.length <= suffix.length || !value.toLowerCase().endsWith(suffix.toLowerCase())) {
|
|
239
|
+
return undefined;
|
|
240
|
+
}
|
|
241
|
+
return value.slice(0, -suffix.length);
|
|
242
|
+
}
|
|
196
243
|
function isPropertyParentModelAndPropertyTypeEntity(program, property) {
|
|
197
244
|
const propertyType = getPropertyType(program, property);
|
|
198
245
|
return !isTypeDefinedInExternalLibrary(program, property) &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../../src/rules/entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,EAAE,wBAAwB,EAC9C,uBAAuB,EAAiE,gBAAgB,EAAE,UAAU,EAAE,YAAY,EAAC,MAAM,oBAAoB,CAAC;AACjK,OAAO,EAAE,SAAS,EAAE,cAAc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compiler").LinterRu
|
|
|
3
3
|
readonly default: import("@typespec/compiler").CallableMessage<["enum"]>;
|
|
4
4
|
}>;
|
|
5
5
|
export declare function validateEnumMemberUnknownFutureValueShouldNotHaveDocString(program: Program): void;
|
|
6
|
+
export declare const collectionShouldNotBeEnum: import("@typespec/compiler").LinterRuleDefinition<"collection-should-not-be-enum", {
|
|
7
|
+
readonly default: import("@typespec/compiler").CallableMessage<["member", "enum"]>;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const nullableBooleanShouldBeEnum: import("@typespec/compiler").LinterRuleDefinition<"nullable-boolean-should-be-enum", {
|
|
10
|
+
readonly default: import("@typespec/compiler").CallableMessage<["property"]>;
|
|
11
|
+
}>;
|
|
12
|
+
export declare const nullableEnumsShouldAddAdditionalMember: import("@typespec/compiler").LinterRuleDefinition<"nullable-enum-should-add-additional-member", {
|
|
13
|
+
readonly default: import("@typespec/compiler").CallableMessage<["property"]>;
|
|
14
|
+
}>;
|
|
6
15
|
//# sourceMappingURL=enum.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../../src/rules/enum.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../../src/rules/enum.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,OAAO,EAMR,MAAM,oBAAoB,CAAC;AAW5B,eAAO,MAAM,oBAAoB;;EA2B/B,CAAC;AAEH,wBAAgB,0DAA0D,CAAC,OAAO,EAAE,OAAO,QAwB1F;AAED,eAAO,MAAM,yBAAyB;;EA+BpC,CAAC;AAEH,eAAO,MAAM,2BAA2B;;EA6BtC,CAAC;AAEH,eAAO,MAAM,sCAAsC;;EA6BjD,CAAC"}
|