microsoft/typespec

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
e26e7826068edd7ad2659a4a2ea74397dcdd1ea6

Branches

Tags

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

Clone

HTTPS

Download ZIP

packages/http/src/lib.ts

141lines · modecode

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