forked from microsoft/typespec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp.tsp
106 lines (98 loc) · 2.71 KB
/
http.tsp
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
import "../dist/src/index.js";
import "./http-decorators.tsp";
import "./auth.tsp";
namespace TypeSpec.Http;
using Private;
/**
* Describes an HTTP response.
*
* @template Status The status code of the response.
*/
@doc("")
model Response<Status> {
@doc("The status code.")
@statusCode
statusCode: Status;
}
/**
* Defines a model with a single property of the given type, marked with `@body`.
*
* This can be useful in situations where you cannot use a bare type as the body
* and it is awkward to add a property.
*
* @template Type The type of the model's `body` property.
*/
@doc("")
model Body<Type> {
@body
@doc("The body type of the operation request or response.")
body: Type;
}
/**
* The Location header contains the URL where the status of the long running operation can be checked.
*/
model LocationHeader {
@doc("The Location header contains the URL where the status of the long running operation can be checked.")
@header
location: string;
}
// Don't put @doc on these, change `getStatusCodeDescription` implementation
// to update the default descriptions for these status codes. This ensures
// that we get consistent emit between different ways to spell the same
// responses in TypeSpec.
/**
* The request has succeeded.
*/
model OkResponse is Response<200>;
/**
* The request has succeeded and a new resource has been created as a result.
*/
model CreatedResponse is Response<201>;
/**
* The request has been accepted for processing, but processing has not yet completed.
*/
model AcceptedResponse is Response<202>;
/**
* There is no content to send for this request, but the headers may be useful.
*/
model NoContentResponse is Response<204>;
/**
* The URL of the requested resource has been changed permanently. The new URL is given in the response.
*/
model MovedResponse is Response<301> {
...LocationHeader;
}
/**
* The client has made a conditional request and the resource has not been modified.
*/
model NotModifiedResponse is Response<304>;
/**
* The server could not understand the request due to invalid syntax.
*/
model BadRequestResponse is Response<400>;
/**
* Access is unauthorized.
*/
model UnauthorizedResponse is Response<401>;
/**
* Access is forbidden.
*/
model ForbiddenResponse is Response<403>;
/**
* The server cannot find the requested resource.
*/
model NotFoundResponse is Response<404>;
/**
* The request conflicts with the current state of the server.
*/
model ConflictResponse is Response<409>;
/**
* Produces a new model with the same properties as T, but with `@query`,
* `@header`, `@body`, and `@path` decorators removed from all properties.
*
* @template Data The model to spread as the plain data.
*/
@plainData
model PlainData<Data> {
...Data;
}