microsoft/typespec

Public

mirrored from https://github.com/microsoft/typespecAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
e0dfe6f5d00641b1423eccb3a6162a03393d65a7

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

packages/http/src/lib.ts

155lines · modecode

1import { createTypeSpecLibrary, paramMessage } from "@typespec/compiler";
2
3export const $lib = createTypeSpecLibrary({
4 name: "@typespec/http",
5 diagnostics: {
6 "http-verb-duplicate": {
7 severity: "error",
8 messages: {
9 default: paramMessage`HTTP verb already applied to ${"entityName"}`,
10 },
11 },
12 "http-verb-wrong-type": {
13 severity: "error",
14 messages: {
15 default: paramMessage`Cannot use @${"verb"} on a ${"entityKind"}`,
16 },
17 },
18 "missing-path-param": {
19 severity: "error",
20 messages: {
21 default: paramMessage`Path contains parameter ${"param"} but wasn't found in given parameters`,
22 },
23 },
24 "optional-path-param": {
25 severity: "error",
26 messages: {
27 default: paramMessage`Path parameter '${"paramName"}' cannot be optional.`,
28 },
29 },
30 "missing-server-param": {
31 severity: "error",
32 messages: {
33 default: paramMessage`Server url contains parameter '${"param"}' but wasn't found in given parameters`,
34 },
35 },
36 "duplicate-body": {
37 severity: "error",
38 messages: {
39 default: "Operation has multiple @body parameters declared",
40 duplicateUnannotated:
41 "Operation has multiple unannotated parameters. There can only be one representing the body",
42 bodyAndUnannotated:
43 "Operation has a @body and an unannotated parameter. There can only be one representing the body",
44 },
45 },
46 "duplicate-route-decorator": {
47 severity: "error",
48 messages: {
49 namespace: "@route was defined twice on this namespace and has different values.",
50 },
51 },
52 "operation-param-duplicate-type": {
53 severity: "error",
54 messages: {
55 default: paramMessage`Param ${"paramName"} has multiple types: [${"types"}]`,
56 },
57 },
58 "duplicate-operation": {
59 severity: "error",
60 messages: {
61 default: paramMessage`Duplicate operation "${"operationName"}" routed at "${"verb"} ${"path"}".`,
62 },
63 },
64 "multiple-status-codes": {
65 severity: "error",
66 messages: {
67 default: "Multiple `@statusCode` decorators defined for this operation response.",
68 },
69 },
70 "status-code-invalid": {
71 severity: "error",
72 messages: {
73 default:
74 "statusCode value must be a numeric or string literal or union of numeric or string literals",
75 value: "statusCode value must be a three digit code between 100 and 599",
76 },
77 },
78 "content-type-string": {
79 severity: "error",
80 messages: {
81 default: "contentType parameter must be a string literal or union of string literals",
82 },
83 },
84 "content-type-ignored": {
85 severity: "warning",
86 messages: {
87 default: "`Content-Type` header ignored because there is no body.",
88 },
89 },
90 "no-service-found": {
91 severity: "warning",
92 messages: {
93 default: paramMessage`No namespace with '@service' was found, but Namespace '${"namespace"}' contains routes. Did you mean to annotate this with '@service'?`,
94 },
95 },
96 "invalid-type-for-auth": {
97 severity: "error",
98 messages: {
99 default: paramMessage`@useAuth ${"kind"} only accept Auth model, Tuple of auth model or union of auth model.`,
100 },
101 },
102 "shared-inconsistency": {
103 severity: "error",
104 messages: {
105 default: paramMessage`Each operation routed at "${"verb"} ${"path"}" needs to have the @sharedRoute decorator.`,
106 },
107 },
108 "write-visibility-not-supported": {
109 severity: "warning",
110 messages: {
111 default: `@visibility("write") is not supported. Use @visibility("update"), @visibility("create") or @visibility("create", "update") as appropriate.`,
112 },
113 },
114 "multipart-model": {
115 severity: "error",
116 messages: {
117 default: "Multipart request body must be a model.",
118 },
119 },
120 "header-format-required": {
121 severity: "error",
122 messages: {
123 default: `A format must be specified for @header when type is an array. e.g. @header({format: "csv"})`,
124 },
125 },
126 "query-format-required": {
127 severity: "error",
128 messages: {
129 default: `A format must be specified for @query when type is an array. e.g. @query({format: "multi"})`,
130 },
131 },
132 },
133 state: {
134 authentication: { description: "State for the @auth decorator" },
135 header: { description: "State for the @header decorator" },
136 query: { description: "State for the @query decorator" },
137 path: { description: "State for the @path decorator" },
138 body: { description: "State for the @body decorator" },
139 statusCode: { description: "State for the @statusCode decorator" },
140 verbs: { description: "State for the verb decorators (@get, @post, @put, etc.)" },
141 servers: { description: "State for the @server decorator" },
142 includeInapplicableMetadataInPayload: {
143 description: "State for the @includeInapplicableMetadataInPayload decorator",
144 },
145
146 // route.ts
147 externalInterfaces: {},
148 routeProducer: {},
149 routes: {},
150 sharedRoutes: { description: "State for the @sharedRoute decorator" },
151 routeOptions: {},
152 },
153} as const);
154
155export const { reportDiagnostic, createDiagnostic, stateKeys: HttpStateKeys } = $lib;
156