microsoft/typespec

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
216d28ebe4e6ae015068e1de99615f032aec7c5b

Branches

Tags

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

Clone

HTTPS

Download ZIP

packages/http/src/lib.ts

146lines · 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 "multiple-status-codes": {
66 severity: "error",
67 messages: {
68 default: "Multiple `@statusCode` decorators defined for this operation response.",
69 },
70 },
71 "status-code-invalid": {
72 severity: "error",
73 messages: {
74 default:
75 "statusCode value must be a numeric or string literal or union of numeric or string literals",
76 value: "statusCode value must be a three digit code between 100 and 599",
77 },
78 },
79 "content-type-string": {
80 severity: "error",
81 messages: {
82 default: "contentType parameter must be a string literal or union of string literals",
83 },
84 },
85 "content-type-ignored": {
86 severity: "warning",
87 messages: {
88 default: "`Content-Type` header ignored because there is no body.",
89 },
90 },
91 "no-service-found": {
92 severity: "warning",
93 messages: {
94 default: paramMessage`No namespace with '@service' was found, but Namespace '${"namespace"}' contains routes. Did you mean to annotate this with '@service'?`,
95 },
96 },
97 "invalid-type-for-auth": {
98 severity: "error",
99 messages: {
100 default: paramMessage`@useAuth ${"kind"} only accept Auth model, Tuple of auth model or union of auth model.`,
101 },
102 },
103 "shared-inconsistency": {
104 severity: "error",
105 messages: {
106 default: "All shared routes must agree on the value of the shared parameter.",
107 },
108 },
109 "write-visibility-not-supported": {
110 severity: "warning",
111 messages: {
112 default: `@visibility("write") is not supported. Use @visibility("update"), @visibility("create") or @visibility("create", "update") as appropriate.`,
113 },
114 },
115 "multipart-model": {
116 severity: "error",
117 messages: {
118 default: "Multipart request body must be a model.",
119 },
120 },
121 "header-format-required": {
122 severity: "error",
123 messages: {
124 default: `A format must be specified for @header when type is an array. e.g. @header({format: "csv"})`,
125 },
126 },
127 "query-format-required": {
128 severity: "error",
129 messages: {
130 default: `A format must be specified for @query when type is an array. e.g. @query({format: "multi"})`,
131 },
132 },
133 },
134 linter: {
135 rules: [opReferenceContainerRouteRule],
136 ruleSets: {
137 all: {
138 enable: {
139 [`@typespec/http/${opReferenceContainerRouteRule.name}`]: true,
140 },
141 },
142 },
143 },
144});
145
146export const { reportDiagnostic, createDiagnostic, createStateSymbol } = $lib;
147