forked from microsoft/typespec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.ts
163 lines (160 loc) · 5.57 KB
/
lib.ts
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
import { createTypeSpecLibrary, paramMessage } from "@typespec/compiler";
export const $lib = createTypeSpecLibrary({
name: "@typespec/http",
diagnostics: {
"http-verb-duplicate": {
severity: "error",
messages: {
default: paramMessage`HTTP verb already applied to ${"entityName"}`,
},
},
"http-verb-wrong-type": {
severity: "error",
messages: {
default: paramMessage`Cannot use @${"verb"} on a ${"entityKind"}`,
},
},
"missing-path-param": {
severity: "error",
messages: {
default: paramMessage`Route reference parameter '${"param"}' but wasn't found in operation parameters`,
},
},
"optional-path-param": {
severity: "error",
messages: {
default: paramMessage`Path parameter '${"paramName"}' cannot be optional.`,
},
},
"missing-server-param": {
severity: "error",
messages: {
default: paramMessage`Server url contains parameter '${"param"}' but wasn't found in given parameters`,
},
},
"duplicate-body": {
severity: "error",
messages: {
default: "Operation has multiple @body parameters declared",
duplicateUnannotated:
"Operation has multiple unannotated parameters. There can only be one representing the body",
bodyAndUnannotated:
"Operation has a @body and an unannotated parameter. There can only be one representing the body",
},
},
"duplicate-route-decorator": {
severity: "error",
messages: {
namespace: "@route was defined twice on this namespace and has different values.",
},
},
"operation-param-duplicate-type": {
severity: "error",
messages: {
default: paramMessage`Param ${"paramName"} has multiple types: [${"types"}]`,
},
},
"duplicate-operation": {
severity: "error",
messages: {
default: paramMessage`Duplicate operation "${"operationName"}" routed at "${"verb"} ${"path"}".`,
},
},
"multiple-status-codes": {
severity: "error",
messages: {
default: "Multiple `@statusCode` decorators defined for this operation response.",
},
},
"status-code-invalid": {
severity: "error",
messages: {
default:
"statusCode value must be a numeric or string literal or union of numeric or string literals",
value: "statusCode value must be a three digit code between 100 and 599",
},
},
"content-type-string": {
severity: "error",
messages: {
default: "contentType parameter must be a string literal or union of string literals",
},
},
"content-type-ignored": {
severity: "warning",
messages: {
default: "`Content-Type` header ignored because there is no body.",
},
},
"metadata-ignored": {
severity: "warning",
messages: {
default: paramMessage`${"kind"} property will be ignored as it is inside of a @body property. Use @bodyRoot instead if wanting to mix.`,
},
},
"no-service-found": {
severity: "warning",
messages: {
default: paramMessage`No namespace with '@service' was found, but Namespace '${"namespace"}' contains routes. Did you mean to annotate this with '@service'?`,
},
},
"invalid-type-for-auth": {
severity: "error",
messages: {
default: paramMessage`@useAuth ${"kind"} only accept Auth model, Tuple of auth model or union of auth model.`,
},
},
"shared-inconsistency": {
severity: "error",
messages: {
default: paramMessage`Each operation routed at "${"verb"} ${"path"}" needs to have the @sharedRoute decorator.`,
},
},
"write-visibility-not-supported": {
severity: "warning",
messages: {
default: `@visibility("write") is not supported. Use @visibility("update"), @visibility("create") or @visibility("create", "update") as appropriate.`,
},
},
"multipart-model": {
severity: "error",
messages: {
default: "Multipart request body must be a model.",
},
},
"header-format-required": {
severity: "error",
messages: {
default: `A format must be specified for @header when type is an array. e.g. @header({format: "csv"})`,
},
},
"query-format-required": {
severity: "error",
messages: {
default: `A format must be specified for @query when type is an array. e.g. @query({format: "multi"})`,
},
},
},
state: {
authentication: { description: "State for the @auth decorator" },
header: { description: "State for the @header decorator" },
query: { description: "State for the @query decorator" },
path: { description: "State for the @path decorator" },
body: { description: "State for the @body decorator" },
bodyRoot: { description: "State for the @bodyRoot decorator" },
bodyIgnore: { description: "State for the @bodyIgnore decorator" },
statusCode: { description: "State for the @statusCode decorator" },
verbs: { description: "State for the verb decorators (@get, @post, @put, etc.)" },
servers: { description: "State for the @server decorator" },
includeInapplicableMetadataInPayload: {
description: "State for the @includeInapplicableMetadataInPayload decorator",
},
// route.ts
externalInterfaces: {},
routeProducer: {},
routes: {},
sharedRoutes: { description: "State for the @sharedRoute decorator" },
routeOptions: {},
},
} as const);
export const { reportDiagnostic, createDiagnostic, stateKeys: HttpStateKeys } = $lib;