microsoft/typespec

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
4199f83575db84feb69e28f57d78c400aec1eab4

Branches

Tags

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

Clone

HTTPS

Download ZIP

packages/http/lib/http.tsp

106lines · modecode

1import "../dist/src/index.js";
2import "./http-decorators.tsp";
3import "./auth.tsp";
4
5namespace TypeSpec.Http;
6
7using Private;
8
9/**
10 * Describes an HTTP response.
11 *
12 * @template Status The status code of the response.
13 */
14@doc("")
15model Response<Status> {
16 @doc("The status code.")
17 @statusCode
18 statusCode: Status;
19}
20
21/**
22 * Defines a model with a single property of the given type, marked with `@body`.
23 *
24 * This can be useful in situations where you cannot use a bare type as the body
25 * and it is awkward to add a property.
26 *
27 * @template Type The type of the model's `body` property.
28 */
29@doc("")
30model Body<Type> {
31 @body
32 @doc("The body type of the operation request or response.")
33 body: Type;
34}
35
36/**
37 * The Location header contains the URL where the status of the long running operation can be checked.
38 */
39model LocationHeader {
40 @doc("The Location header contains the URL where the status of the long running operation can be checked.")
41 @header
42 location: string;
43}
44
45// Don't put @doc on these, change `getStatusCodeDescription` implementation
46// to update the default descriptions for these status codes. This ensures
47// that we get consistent emit between different ways to spell the same
48// responses in TypeSpec.
49
50/**
51 * The request has succeeded.
52 */
53model OkResponse is Response<200>;
54/**
55 * The request has succeeded and a new resource has been created as a result.
56 */
57model CreatedResponse is Response<201>;
58/**
59 * The request has been accepted for processing, but processing has not yet completed.
60 */
61model AcceptedResponse is Response<202>;
62/**
63 * There is no content to send for this request, but the headers may be useful.
64 */
65model NoContentResponse is Response<204>;
66/**
67 * The URL of the requested resource has been changed permanently. The new URL is given in the response.
68 */
69model MovedResponse is Response<301> {
70 ...LocationHeader;
71}
72/**
73 * The client has made a conditional request and the resource has not been modified.
74 */
75model NotModifiedResponse is Response<304>;
76/**
77 * The server could not understand the request due to invalid syntax.
78 */
79model BadRequestResponse is Response<400>;
80/**
81 * Access is unauthorized.
82 */
83model UnauthorizedResponse is Response<401>;
84/**
85 * Access is forbidden.
86 */
87model ForbiddenResponse is Response<403>;
88/**
89 * The server cannot find the requested resource.
90 */
91model NotFoundResponse is Response<404>;
92/**
93 * The request conflicts with the current state of the server.
94 */
95model ConflictResponse is Response<409>;
96
97/**
98 * Produces a new model with the same properties as T, but with `@query`,
99 * `@header`, `@body`, and `@path` decorators removed from all properties.
100 *
101 * @template Data The model to spread as the plain data.
102 */
103@plainData
104model PlainData<Data> {
105 ...Data;
106}
107