microsoft/typespec

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
3db15286f4d1436614d6c669dd0c0e949452b277

Branches

Tags

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

Clone

HTTPS

Download ZIP

packages/http/src/lib.ts

133lines · modecode

1import { createTypeSpecLibrary, paramMessage } from "@typespec/compiler";
2
3const libDefinition = {
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 "status-code-invalid": {
65 severity: "error",
66 messages: {
67 default:
68 "statusCode value must be a numeric or string literal or union of numeric or string literals",
69 value: "statusCode value must be a three digit code between 100 and 599",
70 },
71 },
72 "content-type-string": {
73 severity: "error",
74 messages: {
75 default: "contentType parameter must be a string literal or union of string literals",
76 },
77 },
78 "content-type-ignored": {
79 severity: "warning",
80 messages: {
81 default: "`Content-Type` header ignored because there is no body.",
82 },
83 },
84 "no-routes": {
85 severity: "warning",
86 messages: {
87 default:
88 "Current spec is not exposing any routes. This could be to not having the service namespace marked with @service.",
89 },
90 },
91 "invalid-type-for-auth": {
92 severity: "error",
93 messages: {
94 default: paramMessage`@useAuth ${"kind"} only accept Auth model, Tuple of auth model or union of auth model.`,
95 },
96 },
97 "shared-inconsistency": {
98 severity: "error",
99 messages: {
100 default: "All shared routes must agree on the value of the shared parameter.",
101 },
102 },
103 "write-visibility-not-supported": {
104 severity: "warning",
105 messages: {
106 default: `@visibility("write") is not supported. Use @visibility("update"), @visibility("create") or @visibility("create", "update") as appropriate.`,
107 },
108 },
109 "multipart-model": {
110 severity: "error",
111 messages: {
112 default: "Multipart request body must be a model.",
113 },
114 },
115 "header-format-required": {
116 severity: "error",
117 messages: {
118 default: `A format must be specified for @header when type is an array. e.g. @header({format: "csv"})`,
119 },
120 },
121 "query-format-required": {
122 severity: "error",
123 messages: {
124 default: `A format must be specified for @query when type is an array. e.g. @query({format: "multi"})`,
125 },
126 },
127 },
128} as const;
129
130const httpLib = createTypeSpecLibrary(libDefinition);
131const { reportDiagnostic, createDiagnostic, createStateSymbol } = httpLib;
132
133export { createDiagnostic, createStateSymbol, httpLib, reportDiagnostic };
134