@typespec/http-specs 0.38.0-dev.3 → 0.38.0-dev.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/specs/encode/duration/mockapi.js +6 -0
- package/dist/specs/encode/duration/mockapi.js.map +1 -1
- package/dist/specs/payload/content-negotiation/mockapi.d.ts +3 -0
- package/dist/specs/payload/content-negotiation/mockapi.d.ts.map +1 -0
- package/dist/specs/payload/content-negotiation/mockapi.js +169 -0
- package/dist/specs/payload/content-negotiation/mockapi.js.map +1 -0
- package/dist/specs/special-words/mockapi.js +1 -1
- package/dist/specs/special-words/mockapi.js.map +1 -1
- package/package.json +8 -7
- package/specs/authentication/api-key/main.tsp +2 -1
- package/specs/authentication/http/custom/main.tsp +1 -0
- package/specs/authentication/oauth2/main.tsp +2 -1
- package/specs/authentication/union/main.tsp +2 -1
- package/specs/encode/bytes/main.tsp +2 -8
- package/specs/encode/datetime/main.tsp +2 -7
- package/specs/encode/duration/main.tsp +2 -6
- package/specs/encode/duration/mockapi.ts +14 -0
- package/specs/encode/numeric/main.tsp +2 -4
- package/specs/parameters/basic/main.tsp +2 -5
- package/specs/parameters/body-optionality/main.tsp +2 -4
- package/specs/parameters/collection-format/main.tsp +2 -5
- package/specs/parameters/spread/main.tsp +2 -5
- package/specs/payload/content-negotiation/main.tsp +61 -0
- package/specs/payload/content-negotiation/mockapi.ts +188 -0
- package/specs/payload/json-merge-patch/main.tsp +2 -1
- package/specs/payload/media-type/main.tsp +2 -4
- package/specs/payload/multipart/main.tsp +2 -1
- package/specs/payload/xml/main.tsp +15 -25
- package/specs/routes/main.tsp +2 -1
- package/specs/serialization/encoded-name/json/main.tsp +2 -2
- package/specs/server/endpoint/not-defined/main.tsp +2 -1
- package/specs/server/path/multiple/main.tsp +2 -1
- package/specs/server/path/single/main.tsp +2 -1
- package/specs/server/versions/not-versioned/main.tsp +2 -1
- package/specs/server/versions/versioned/main.tsp +2 -3
- package/specs/special-headers/conditional-request/main.tsp +2 -2
- package/specs/special-headers/repeatability/main.tsp +2 -2
- package/specs/special-words/main.tsp +2 -6
- package/specs/special-words/mockapi.ts +1 -1
- package/specs/type/array/main.tsp +15 -39
- package/specs/type/dictionary/main.tsp +15 -36
- package/specs/type/enum/extensible/main.tsp +2 -1
- package/specs/type/enum/fixed/main.tsp +2 -2
- package/specs/type/model/empty/main.tsp +2 -1
- package/specs/type/model/inheritance/enum-discriminator/main.tsp +2 -2
- package/specs/type/model/inheritance/nested-discriminator/main.tsp +2 -1
- package/specs/type/model/inheritance/not-discriminated/main.tsp +2 -1
- package/specs/type/model/inheritance/recursive/main.tsp +2 -1
- package/specs/type/model/inheritance/single-discriminator/main.tsp +2 -1
- package/specs/type/model/templated/main.tsp +2 -2
- package/specs/type/model/usage/main.tsp +2 -1
- package/specs/type/model/visibility/main.tsp +2 -1
- package/specs/type/property/additional-properties/main.tsp +15 -57
- package/specs/type/property/nullable/main.tsp +31 -54
- package/specs/type/property/optionality/main.tsp +31 -63
- package/specs/type/property/value-types/main.tsp +15 -56
- package/specs/type/scalar/main.tsp +34 -62
- package/specs/type/union/main.tsp +5 -18
- package/specs/versioning/added/main.tsp +2 -1
- package/specs/versioning/madeOptional/main.tsp +2 -1
- package/specs/versioning/removed/main.tsp +2 -1
- package/specs/versioning/renamedFrom/main.tsp +2 -1
- package/specs/versioning/returnTypeChangedFrom/main.tsp +2 -1
- package/specs/versioning/typeChangedFrom/main.tsp +2 -1
- package/temp/.tsbuildinfo +1 -1
- package/specs/type/property/nullable/client.tsp +0 -21
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import "@typespec/http";
|
|
2
|
+
import "@typespec/spec-lib";
|
|
3
|
+
|
|
4
|
+
using Http;
|
|
5
|
+
using SpecLib;
|
|
6
|
+
|
|
7
|
+
@doc("Test describing optionality of the request body.")
|
|
8
|
+
@scenarioService("/content-negotiation")
|
|
9
|
+
namespace Payload.ContentNegotiation;
|
|
10
|
+
|
|
11
|
+
@scenario
|
|
12
|
+
@scenarioDoc("""
|
|
13
|
+
Scenario that returns a different file encoding depending on the accept header.
|
|
14
|
+
|
|
15
|
+
- image/png return a png image
|
|
16
|
+
- image/jpeg return a jpeg image
|
|
17
|
+
""")
|
|
18
|
+
@route("same-body")
|
|
19
|
+
namespace SameBody {
|
|
20
|
+
model PngImage {
|
|
21
|
+
@header contentType: "image/png";
|
|
22
|
+
@body image: bytes;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
model JpegImage {
|
|
26
|
+
@header contentType: "image/jpeg";
|
|
27
|
+
@body image: bytes;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@sharedRoute
|
|
31
|
+
op getAvatarAsPng(@header accept: "image/png"): PngImage;
|
|
32
|
+
|
|
33
|
+
@sharedRoute
|
|
34
|
+
op getAvatarAsJpeg(@header accept: "image/jpeg"): JpegImage;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@scenario
|
|
38
|
+
@scenarioDoc("""
|
|
39
|
+
Scenario that a different payload depending on the accept header.
|
|
40
|
+
|
|
41
|
+
- application/json return a png image in a Json object
|
|
42
|
+
- image/png return the png image
|
|
43
|
+
""")
|
|
44
|
+
@route("different-body")
|
|
45
|
+
namespace DifferentBody {
|
|
46
|
+
model PngImage {
|
|
47
|
+
@header contentType: "image/png";
|
|
48
|
+
@body image: bytes;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
model PngImageAsJson {
|
|
52
|
+
@header contentType: "application/json";
|
|
53
|
+
content: bytes;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@sharedRoute
|
|
57
|
+
op getAvatarAsPng(@header accept: "image/png"): PngImage;
|
|
58
|
+
|
|
59
|
+
@sharedRoute
|
|
60
|
+
op getAvatarAsJson(@header accept: "application/json"): PngImageAsJson;
|
|
61
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import {
|
|
2
|
+
json,
|
|
3
|
+
MockRequest,
|
|
4
|
+
ScenarioMockApi,
|
|
5
|
+
ValidationError,
|
|
6
|
+
withServiceKeys,
|
|
7
|
+
} from "@typespec/spec-api";
|
|
8
|
+
import { jpgFile, pngFile } from "../../helper.js";
|
|
9
|
+
|
|
10
|
+
export const Scenarios: Record<string, ScenarioMockApi> = {};
|
|
11
|
+
|
|
12
|
+
function sameBodyHandler(req: MockRequest) {
|
|
13
|
+
switch (req.headers["accept"]) {
|
|
14
|
+
case "image/png":
|
|
15
|
+
return {
|
|
16
|
+
pass: "image/png",
|
|
17
|
+
status: 200,
|
|
18
|
+
body: {
|
|
19
|
+
contentType: "image/png",
|
|
20
|
+
rawContent: pngFile,
|
|
21
|
+
},
|
|
22
|
+
} as const;
|
|
23
|
+
case "image/jpeg":
|
|
24
|
+
return {
|
|
25
|
+
pass: "image/jpeg",
|
|
26
|
+
|
|
27
|
+
status: 200,
|
|
28
|
+
body: {
|
|
29
|
+
contentType: "image/jpeg",
|
|
30
|
+
rawContent: jpgFile,
|
|
31
|
+
},
|
|
32
|
+
} as const;
|
|
33
|
+
default:
|
|
34
|
+
throw new ValidationError(
|
|
35
|
+
"Unsupported Accept header",
|
|
36
|
+
`"image/png" | "image/jpeg"`,
|
|
37
|
+
req.headers["accept"],
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function differentBodyHandler(req: MockRequest) {
|
|
43
|
+
switch (req.headers["accept"]) {
|
|
44
|
+
case "image/png":
|
|
45
|
+
return {
|
|
46
|
+
pass: "image/png",
|
|
47
|
+
status: 200,
|
|
48
|
+
body: {
|
|
49
|
+
contentType: "image/png",
|
|
50
|
+
rawContent: pngFile,
|
|
51
|
+
},
|
|
52
|
+
} as const;
|
|
53
|
+
case "application/json":
|
|
54
|
+
return {
|
|
55
|
+
pass: "application/json",
|
|
56
|
+
status: 200,
|
|
57
|
+
body: json({
|
|
58
|
+
content: pngFile.toString("base64"),
|
|
59
|
+
}),
|
|
60
|
+
} as const;
|
|
61
|
+
default:
|
|
62
|
+
throw new ValidationError(
|
|
63
|
+
"Unsupported Accept header",
|
|
64
|
+
`"image/png" | "application/json"`,
|
|
65
|
+
req.headers["accept"],
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
Scenarios.Payload_ContentNegotiation_SameBody = withServiceKeys(["image/png", "image/jpeg"]).pass([
|
|
71
|
+
{
|
|
72
|
+
uri: "/content-negotiation/same-body",
|
|
73
|
+
method: "get",
|
|
74
|
+
request: {
|
|
75
|
+
headers: {
|
|
76
|
+
accept: "image/png",
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
response: {
|
|
80
|
+
body: {
|
|
81
|
+
contentType: "image/png",
|
|
82
|
+
rawContent: pngFile,
|
|
83
|
+
},
|
|
84
|
+
status: 200,
|
|
85
|
+
},
|
|
86
|
+
handler: (req) => sameBodyHandler(req),
|
|
87
|
+
kind: "MockApiDefinition",
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
uri: "/content-negotiation/same-body",
|
|
91
|
+
method: "get",
|
|
92
|
+
request: {
|
|
93
|
+
headers: {
|
|
94
|
+
accept: "image/jpeg",
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
response: {
|
|
98
|
+
body: {
|
|
99
|
+
contentType: "image/jpeg",
|
|
100
|
+
rawContent: jpgFile,
|
|
101
|
+
},
|
|
102
|
+
status: 200,
|
|
103
|
+
},
|
|
104
|
+
handler: (req) => sameBodyHandler(req),
|
|
105
|
+
kind: "MockApiDefinition",
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
uri: "/content-negotiation/same-body",
|
|
109
|
+
method: "get",
|
|
110
|
+
request: {
|
|
111
|
+
status: 400,
|
|
112
|
+
headers: {
|
|
113
|
+
accept: "wrongAccept",
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
response: {
|
|
117
|
+
status: 400,
|
|
118
|
+
body: json({
|
|
119
|
+
message: "Unsupported Accept header",
|
|
120
|
+
expected: `"image/png" | "image/jpeg"`,
|
|
121
|
+
actual: "wrongAccept",
|
|
122
|
+
}),
|
|
123
|
+
},
|
|
124
|
+
handler: sameBodyHandler,
|
|
125
|
+
kind: "MockApiDefinition",
|
|
126
|
+
},
|
|
127
|
+
]);
|
|
128
|
+
|
|
129
|
+
Scenarios.Payload_ContentNegotiation_DifferentBody = withServiceKeys([
|
|
130
|
+
"image/png",
|
|
131
|
+
"application/json",
|
|
132
|
+
]).pass([
|
|
133
|
+
{
|
|
134
|
+
uri: "/content-negotiation/different-body",
|
|
135
|
+
method: "get",
|
|
136
|
+
request: {
|
|
137
|
+
headers: {
|
|
138
|
+
accept: "image/png",
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
response: {
|
|
142
|
+
status: 200,
|
|
143
|
+
body: {
|
|
144
|
+
contentType: "image/png",
|
|
145
|
+
rawContent: pngFile,
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
handler: differentBodyHandler,
|
|
149
|
+
kind: "MockApiDefinition",
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
uri: "/content-negotiation/different-body",
|
|
153
|
+
method: "get",
|
|
154
|
+
request: {
|
|
155
|
+
headers: {
|
|
156
|
+
accept: "application/json",
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
response: {
|
|
160
|
+
status: 200,
|
|
161
|
+
body: json({
|
|
162
|
+
content: pngFile.toString("base64"),
|
|
163
|
+
}),
|
|
164
|
+
},
|
|
165
|
+
handler: differentBodyHandler,
|
|
166
|
+
kind: "MockApiDefinition",
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
uri: "/content-negotiation/different-body",
|
|
170
|
+
method: "get",
|
|
171
|
+
request: {
|
|
172
|
+
status: 400,
|
|
173
|
+
headers: {
|
|
174
|
+
accept: "wrongAccept",
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
response: {
|
|
178
|
+
status: 400,
|
|
179
|
+
body: json({
|
|
180
|
+
message: "Unsupported Accept header",
|
|
181
|
+
expected: `"image/png" | "application/json"`,
|
|
182
|
+
actual: "wrongAccept",
|
|
183
|
+
}),
|
|
184
|
+
},
|
|
185
|
+
handler: differentBodyHandler,
|
|
186
|
+
kind: "MockApiDefinition",
|
|
187
|
+
},
|
|
188
|
+
]);
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import "@typespec/http";
|
|
2
2
|
import "@typespec/spec-lib";
|
|
3
3
|
|
|
4
|
-
using
|
|
5
|
-
using
|
|
4
|
+
using Http;
|
|
5
|
+
using SpecLib;
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Test the payload with different media types and different types of the payload itself.
|
|
9
9
|
*/
|
|
10
|
-
@supportedBy("dpg")
|
|
11
10
|
@scenarioService("/payload/media-type")
|
|
12
11
|
namespace Payload.MediaType;
|
|
13
12
|
|
|
14
|
-
@operationGroup
|
|
15
13
|
@route("/string-body")
|
|
16
14
|
namespace StringBody {
|
|
17
15
|
@scenario
|
|
@@ -2,9 +2,9 @@ import "@typespec/http";
|
|
|
2
2
|
import "@typespec/xml";
|
|
3
3
|
import "@typespec/spec-lib";
|
|
4
4
|
|
|
5
|
-
using
|
|
5
|
+
using Http;
|
|
6
|
+
using SpecLib;
|
|
6
7
|
using TypeSpec.Xml;
|
|
7
|
-
using Azure.ClientGenerator.Core;
|
|
8
8
|
|
|
9
9
|
@doc("Sends and receives bodies in XML format.")
|
|
10
10
|
@scenarioService("/payload/xml")
|
|
@@ -83,19 +83,14 @@ model ModelWithEncodedNames {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
@doc("Template for XML operations")
|
|
86
|
-
interface XmlOperations<TModel, TDoc extends string> {
|
|
86
|
+
interface XmlOperations<TModel, TDoc extends valueof string> {
|
|
87
87
|
@scenario
|
|
88
|
-
@scenarioDoc(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
""",
|
|
95
|
-
{
|
|
96
|
-
doc: TDoc,
|
|
97
|
-
}
|
|
98
|
-
)
|
|
88
|
+
@scenarioDoc("""
|
|
89
|
+
Expected response body:
|
|
90
|
+
```xml
|
|
91
|
+
${TDoc}
|
|
92
|
+
```
|
|
93
|
+
""")
|
|
99
94
|
@get
|
|
100
95
|
get(): {
|
|
101
96
|
@header("content-type") contentType: "application/xml";
|
|
@@ -103,17 +98,12 @@ interface XmlOperations<TModel, TDoc extends string> {
|
|
|
103
98
|
};
|
|
104
99
|
|
|
105
100
|
@scenario
|
|
106
|
-
@scenarioDoc(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
""",
|
|
113
|
-
{
|
|
114
|
-
doc: TDoc,
|
|
115
|
-
}
|
|
116
|
-
)
|
|
101
|
+
@scenarioDoc("""
|
|
102
|
+
Expected request body:
|
|
103
|
+
```xml
|
|
104
|
+
${TDoc}
|
|
105
|
+
```
|
|
106
|
+
""")
|
|
117
107
|
@put
|
|
118
108
|
put(@header("content-type") contentType: "application/xml", @body input: TModel): void;
|
|
119
109
|
}
|
package/specs/routes/main.tsp
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "@typespec/http";
|
|
2
2
|
import "@typespec/spec-lib";
|
|
3
3
|
|
|
4
|
-
using
|
|
4
|
+
using Http;
|
|
5
|
+
using SpecLib;
|
|
5
6
|
|
|
6
7
|
@doc("Projection")
|
|
7
|
-
@supportedBy("dpg")
|
|
8
8
|
@scenarioService("/serialization/encoded-name/json")
|
|
9
9
|
namespace Serialization.EncodedName.Json;
|
|
10
10
|
|
|
@@ -2,7 +2,8 @@ import "@typespec/http";
|
|
|
2
2
|
import "@typespec/spec-lib";
|
|
3
3
|
import "@typespec/versioning";
|
|
4
4
|
|
|
5
|
-
using
|
|
5
|
+
using Http;
|
|
6
|
+
using SpecLib;
|
|
6
7
|
using TypeSpec.Versioning;
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -30,13 +31,11 @@ enum Versions {
|
|
|
30
31
|
/**
|
|
31
32
|
* The version 2022-12-01-preview.
|
|
32
33
|
*/
|
|
33
|
-
@useDependency(global.Azure.Core.Versions.v1_0_Preview_2)
|
|
34
34
|
v2021_01_01_preview: "2021-01-01-preview",
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* The version 2022-12-01-preview.
|
|
38
38
|
*/
|
|
39
|
-
@useDependency(global.Azure.Core.Versions.v1_0_Preview_2)
|
|
40
39
|
v2022_12_01_preview: "2022-12-01-preview",
|
|
41
40
|
}
|
|
42
41
|
|
|
@@ -2,11 +2,11 @@ import "@typespec/http";
|
|
|
2
2
|
import "@typespec/versioning";
|
|
3
3
|
import "@typespec/spec-lib";
|
|
4
4
|
|
|
5
|
-
using
|
|
5
|
+
using Http;
|
|
6
|
+
using SpecLib;
|
|
6
7
|
using TypeSpec.Versioning;
|
|
7
8
|
|
|
8
9
|
@doc("Illustrates conditional request headers")
|
|
9
|
-
@supportedBy("dpg")
|
|
10
10
|
@scenarioService("/special-headers/conditional-request")
|
|
11
11
|
namespace SpecialHeaders.ConditionalRequest;
|
|
12
12
|
|
|
@@ -2,11 +2,11 @@ import "@typespec/http";
|
|
|
2
2
|
import "@typespec/versioning";
|
|
3
3
|
import "@typespec/spec-lib";
|
|
4
4
|
|
|
5
|
-
using
|
|
5
|
+
using Http;
|
|
6
|
+
using SpecLib;
|
|
6
7
|
using TypeSpec.Versioning;
|
|
7
8
|
|
|
8
9
|
@doc("Illustrates OASIS repeatability headers")
|
|
9
|
-
@supportedBy("dpg")
|
|
10
10
|
@scenarioService("/special-headers/repeatability")
|
|
11
11
|
namespace SpecialHeaders.Repeatability;
|
|
12
12
|
|
|
@@ -2,8 +2,8 @@ import "@typespec/http";
|
|
|
2
2
|
import "@typespec/spec-lib";
|
|
3
3
|
import "./dec.js";
|
|
4
4
|
|
|
5
|
-
using
|
|
6
|
-
using
|
|
5
|
+
using Http;
|
|
6
|
+
using SpecLib;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Scenarios to verify that reserved words can be used in service and generators will handle it appropriately.
|
|
@@ -52,7 +52,6 @@ namespace SpecialWords;
|
|
|
52
52
|
* Test reserved words as operation name.
|
|
53
53
|
*/
|
|
54
54
|
@route("/operations")
|
|
55
|
-
@operationGroup
|
|
56
55
|
interface Operations {
|
|
57
56
|
@opNameScenario("and") and(): void;
|
|
58
57
|
@opNameScenario("as") as(): void;
|
|
@@ -93,7 +92,6 @@ interface Operations {
|
|
|
93
92
|
* Verify reserved words as parameter name.
|
|
94
93
|
*/
|
|
95
94
|
@route("/parameters")
|
|
96
|
-
@operationGroup
|
|
97
95
|
interface Parameters {
|
|
98
96
|
@paramNameScenario("and") withAnd(@query and: string): void;
|
|
99
97
|
@paramNameScenario("as") withAs(@query as: string): void;
|
|
@@ -139,7 +137,6 @@ interface Parameters {
|
|
|
139
137
|
* Verify model names
|
|
140
138
|
*/
|
|
141
139
|
@route("/models")
|
|
142
|
-
@operationGroup
|
|
143
140
|
namespace Models {
|
|
144
141
|
model Base {
|
|
145
142
|
name: string;
|
|
@@ -217,7 +214,6 @@ namespace Models {
|
|
|
217
214
|
* Verify model names
|
|
218
215
|
*/
|
|
219
216
|
@route("/model-properties")
|
|
220
|
-
@operationGroup
|
|
221
217
|
namespace ModelProperties {
|
|
222
218
|
model SameAsModel {
|
|
223
219
|
SameAsModel: string;
|
|
@@ -2,7 +2,7 @@ import { MockRequest, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api"
|
|
|
2
2
|
|
|
3
3
|
export const Scenarios: Record<string, ScenarioMockApi> = {};
|
|
4
4
|
|
|
5
|
-
Scenarios.
|
|
5
|
+
Scenarios.SpecialWords_ModelProperties_sameAsModel = passOnSuccess({
|
|
6
6
|
uri: "/special-words/model-properties/same-as-model",
|
|
7
7
|
method: "post",
|
|
8
8
|
request: {
|
|
@@ -1,85 +1,67 @@
|
|
|
1
1
|
import "@typespec/http";
|
|
2
2
|
import "@typespec/spec-lib";
|
|
3
3
|
|
|
4
|
-
using
|
|
5
|
-
using
|
|
4
|
+
using Http;
|
|
5
|
+
using SpecLib;
|
|
6
6
|
|
|
7
7
|
@doc("Illustrates various types of arrays.")
|
|
8
8
|
@scenarioService("/type/array")
|
|
9
9
|
namespace Type.Array;
|
|
10
10
|
|
|
11
11
|
@doc("Template to have Array operations")
|
|
12
|
-
interface ArrayOperations<TArr, TDoc extends string> {
|
|
12
|
+
interface ArrayOperations<TArr, TDoc extends valueof string> {
|
|
13
13
|
@scenario
|
|
14
|
-
@scenarioDoc(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
""",
|
|
21
|
-
{
|
|
22
|
-
doc: TDoc,
|
|
23
|
-
}
|
|
24
|
-
)
|
|
14
|
+
@scenarioDoc("""
|
|
15
|
+
Expected Array response body:
|
|
16
|
+
```json
|
|
17
|
+
${TDoc}
|
|
18
|
+
```
|
|
19
|
+
""")
|
|
25
20
|
@get
|
|
26
21
|
get(): TArr;
|
|
27
22
|
|
|
28
23
|
@scenario
|
|
29
|
-
@scenarioDoc(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
""",
|
|
36
|
-
{
|
|
37
|
-
doc: TDoc,
|
|
38
|
-
}
|
|
39
|
-
)
|
|
24
|
+
@scenarioDoc("""
|
|
25
|
+
Expected Array input body:
|
|
26
|
+
```json
|
|
27
|
+
${TDoc}
|
|
28
|
+
```
|
|
29
|
+
""")
|
|
40
30
|
@put
|
|
41
31
|
put(@body body: TArr): void;
|
|
42
32
|
}
|
|
43
33
|
|
|
44
34
|
@doc("Array of int32 values")
|
|
45
35
|
@route("/int32")
|
|
46
|
-
@operationGroup
|
|
47
36
|
interface Int32Value extends ArrayOperations<int32[], "[1, 2]"> {}
|
|
48
37
|
|
|
49
38
|
@doc("Array of int64 values")
|
|
50
39
|
@route("/int64")
|
|
51
|
-
@operationGroup
|
|
52
40
|
interface Int64Value
|
|
53
41
|
extends ArrayOperations<int64[], "[0x7FFFFFFFFFFFFFFF, -0x7FFFFFFFFFFFFFFF]"> {}
|
|
54
42
|
|
|
55
43
|
@doc("Array of boolean values")
|
|
56
44
|
@route("/boolean")
|
|
57
|
-
@operationGroup
|
|
58
45
|
interface BooleanValue extends ArrayOperations<boolean[], "[true, false]"> {}
|
|
59
46
|
|
|
60
47
|
@doc("Array of string values")
|
|
61
48
|
@route("/string")
|
|
62
|
-
@operationGroup
|
|
63
49
|
interface StringValue extends ArrayOperations<string[], "['hello', '']"> {}
|
|
64
50
|
|
|
65
51
|
@doc("Array of float values")
|
|
66
52
|
@route("/float32")
|
|
67
|
-
@operationGroup
|
|
68
53
|
interface Float32Value extends ArrayOperations<float32[], "[43.125]"> {}
|
|
69
54
|
|
|
70
55
|
@doc("Array of datetime values")
|
|
71
56
|
@route("/datetime")
|
|
72
|
-
@operationGroup
|
|
73
57
|
interface DatetimeValue extends ArrayOperations<utcDateTime[], "['2022-08-26T18:38:00Z']"> {}
|
|
74
58
|
|
|
75
59
|
@doc("Array of duration values")
|
|
76
60
|
@route("/duration")
|
|
77
|
-
@operationGroup
|
|
78
61
|
interface DurationValue extends ArrayOperations<duration[], "['P123DT22H14M12.011S']"> {}
|
|
79
62
|
|
|
80
63
|
@doc("Array of unknown values")
|
|
81
64
|
@route("/unknown")
|
|
82
|
-
@operationGroup
|
|
83
65
|
interface UnknownValue extends ArrayOperations<unknown[], "[1, 'hello', 'k3': null]"> {}
|
|
84
66
|
|
|
85
67
|
@doc("Array inner model")
|
|
@@ -92,39 +74,33 @@ model InnerModel {
|
|
|
92
74
|
|
|
93
75
|
@doc("Array of model values")
|
|
94
76
|
@route("/model")
|
|
95
|
-
@operationGroup
|
|
96
77
|
interface ModelValue
|
|
97
78
|
extends ArrayOperations<InnerModel[], "[{'property': 'hello'}, {'property': 'world'}]"> {}
|
|
98
79
|
|
|
99
80
|
alias NullableFloat = float32 | null;
|
|
100
81
|
@doc("Array of nullable float values")
|
|
101
82
|
@route("/nullable-float")
|
|
102
|
-
@operationGroup
|
|
103
83
|
interface NullableFloatValue extends ArrayOperations<NullableFloat[], "[1.25, null, 3.0]"> {}
|
|
104
84
|
|
|
105
85
|
alias NullableInt32 = int32 | null;
|
|
106
86
|
@doc("Array of nullable int32 values")
|
|
107
87
|
@route("/nullable-int32")
|
|
108
|
-
@operationGroup
|
|
109
88
|
interface NullableInt32Value extends ArrayOperations<NullableInt32[], "[1, null, 3]"> {}
|
|
110
89
|
|
|
111
90
|
alias NullableBoolean = boolean | null;
|
|
112
91
|
@doc("Array of nullable boolean values")
|
|
113
92
|
@route("/nullable-boolean")
|
|
114
|
-
@operationGroup
|
|
115
93
|
interface NullableBooleanValue extends ArrayOperations<NullableBoolean[], "[true, null, false]"> {}
|
|
116
94
|
|
|
117
95
|
alias NullableString = string | null;
|
|
118
96
|
@doc("Array of nullable string values")
|
|
119
97
|
@route("/nullable-string")
|
|
120
|
-
@operationGroup
|
|
121
98
|
interface NullableStringValue
|
|
122
99
|
extends ArrayOperations<NullableString[], "['hello', null, 'world']"> {}
|
|
123
100
|
|
|
124
101
|
alias NullableModel = InnerModel | null;
|
|
125
102
|
@doc("Array of nullable model values")
|
|
126
103
|
@route("/nullable-model")
|
|
127
|
-
@operationGroup
|
|
128
104
|
interface NullableModelValue
|
|
129
105
|
extends ArrayOperations<
|
|
130
106
|
NullableModel[],
|