@typespec/http-specs 0.1.0-alpha.24-dev.0 → 0.1.0-alpha.24-dev.2

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.
@@ -1,3 +1,3 @@
1
- export declare const pngFile: Buffer<ArrayBufferLike>;
2
- export declare const jpgFile: Buffer<ArrayBufferLike>;
1
+ export declare const pngFile: NonSharedBuffer;
2
+ export declare const jpgFile: NonSharedBuffer;
3
3
  //# sourceMappingURL=helper.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../specs/helper.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,OAAO,yBAAsD,CAAC;AAC3E,eAAO,MAAM,OAAO,yBAAsD,CAAC"}
1
+ {"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../specs/helper.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,OAAO,iBAAsD,CAAC;AAC3E,eAAO,MAAM,OAAO,iBAAsD,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { ScenarioMockApi } from "@typespec/spec-api";
2
+ export declare const Scenarios: Record<string, ScenarioMockApi>;
3
+ //# sourceMappingURL=mockapi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mockapi.d.ts","sourceRoot":"","sources":["../../../../../specs/type/union/discriminated/mockapi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEvF,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAM,CAAC"}
@@ -0,0 +1,212 @@
1
+ import { json, passOnSuccess } from "@typespec/spec-api";
2
+ export const Scenarios = {};
3
+ // Test data for discriminated union scenarios
4
+ const catData = {
5
+ name: "Whiskers",
6
+ meow: true,
7
+ };
8
+ const dogData = {
9
+ name: "Rex",
10
+ bark: false,
11
+ };
12
+ // Envelope discriminated union (default serialization)
13
+ const envelopeCatBody = {
14
+ kind: "cat",
15
+ value: catData,
16
+ };
17
+ const envelopeDogBody = {
18
+ kind: "dog",
19
+ value: dogData,
20
+ };
21
+ Scenarios.Type_Union_Discriminated_Envelope_Object_Default_get = passOnSuccess({
22
+ uri: "/type/union/discriminated/envelope/object/default",
23
+ method: "get",
24
+ request: {},
25
+ response: {
26
+ status: 200,
27
+ body: json(envelopeCatBody),
28
+ },
29
+ handler: (req) => {
30
+ const kind = req.query.kind;
31
+ // When kind is null or "cat", return response for "cat"
32
+ // When kind is "dog", return response for "dog"
33
+ if (kind === "dog") {
34
+ return {
35
+ status: 200,
36
+ body: json(envelopeDogBody),
37
+ };
38
+ }
39
+ else {
40
+ // Default case: when kind is null, undefined, or "cat"
41
+ return {
42
+ status: 200,
43
+ body: json(envelopeCatBody),
44
+ };
45
+ }
46
+ },
47
+ kind: "MockApiDefinition",
48
+ });
49
+ Scenarios.Type_Union_Discriminated_Envelope_Object_Default_put = passOnSuccess({
50
+ uri: "/type/union/discriminated/envelope/object/default",
51
+ method: "put",
52
+ request: {
53
+ body: json(envelopeCatBody),
54
+ },
55
+ response: {
56
+ status: 200,
57
+ body: json(envelopeCatBody),
58
+ },
59
+ kind: "MockApiDefinition",
60
+ });
61
+ // Custom names discriminated union
62
+ const customNamesCatBody = {
63
+ petType: "cat",
64
+ petData: catData,
65
+ };
66
+ const customNamesDogBody = {
67
+ petType: "dog",
68
+ petData: dogData,
69
+ };
70
+ Scenarios.Type_Union_Discriminated_Envelope_Object_CustomProperties_get = passOnSuccess({
71
+ uri: "/type/union/discriminated/envelope/object/custom-properties",
72
+ method: "get",
73
+ request: {},
74
+ response: {
75
+ status: 200,
76
+ body: json(customNamesCatBody),
77
+ },
78
+ handler: (req) => {
79
+ const petType = req.query.petType;
80
+ // When petType is null or "cat", return response for "cat"
81
+ // When petType is "dog", return response for "dog"
82
+ if (petType === "dog") {
83
+ return {
84
+ status: 200,
85
+ body: json(customNamesDogBody),
86
+ };
87
+ }
88
+ else {
89
+ // Default case: when petType is null, undefined, or "cat"
90
+ return {
91
+ status: 200,
92
+ body: json(customNamesCatBody),
93
+ };
94
+ }
95
+ },
96
+ kind: "MockApiDefinition",
97
+ });
98
+ Scenarios.Type_Union_Discriminated_Envelope_Object_CustomProperties_put = passOnSuccess({
99
+ uri: "/type/union/discriminated/envelope/object/custom-properties",
100
+ method: "put",
101
+ request: {
102
+ body: json(customNamesCatBody),
103
+ },
104
+ response: {
105
+ status: 200,
106
+ body: json(customNamesCatBody),
107
+ },
108
+ kind: "MockApiDefinition",
109
+ });
110
+ // Inline discriminated union (no envelope)
111
+ const inlineCatBody = {
112
+ kind: "cat",
113
+ name: "Whiskers",
114
+ meow: true,
115
+ };
116
+ const inlineDogBody = {
117
+ kind: "dog",
118
+ name: "Rex",
119
+ bark: false,
120
+ };
121
+ Scenarios.Type_Union_Discriminated_NoEnvelope_Default_get = passOnSuccess({
122
+ uri: "/type/union/discriminated/no-envelope/default",
123
+ method: "get",
124
+ request: {},
125
+ response: {
126
+ status: 200,
127
+ body: json(inlineCatBody),
128
+ },
129
+ handler: (req) => {
130
+ const kind = req.query.kind;
131
+ // When kind is null or "cat", return response for "cat"
132
+ // When kind is "dog", return response for "dog"
133
+ if (kind === "dog") {
134
+ return {
135
+ status: 200,
136
+ body: json(inlineDogBody),
137
+ };
138
+ }
139
+ else {
140
+ // Default case: when kind is null, undefined, or "cat"
141
+ return {
142
+ status: 200,
143
+ body: json(inlineCatBody),
144
+ };
145
+ }
146
+ },
147
+ kind: "MockApiDefinition",
148
+ });
149
+ Scenarios.Type_Union_Discriminated_NoEnvelope_Default_put = passOnSuccess({
150
+ uri: "/type/union/discriminated/no-envelope/default",
151
+ method: "put",
152
+ request: {
153
+ body: json(inlineCatBody),
154
+ },
155
+ response: {
156
+ status: 200,
157
+ body: json(inlineCatBody),
158
+ },
159
+ kind: "MockApiDefinition",
160
+ });
161
+ // Inline discriminated union with custom discriminator property name
162
+ const inlineCustomCatBody = {
163
+ type: "cat",
164
+ name: "Whiskers",
165
+ meow: true,
166
+ };
167
+ const inlineCustomDogBody = {
168
+ type: "dog",
169
+ name: "Rex",
170
+ bark: false,
171
+ };
172
+ Scenarios.Type_Union_Discriminated_NoEnvelope_CustomDiscriminator_get = passOnSuccess({
173
+ uri: "/type/union/discriminated/no-envelope/custom-discriminator",
174
+ method: "get",
175
+ request: {},
176
+ response: {
177
+ status: 200,
178
+ body: json(inlineCustomCatBody),
179
+ },
180
+ handler: (req) => {
181
+ const type = req.query.type;
182
+ // When type is null or "cat", return response for "cat"
183
+ // When type is "dog", return response for "dog"
184
+ if (type === "dog") {
185
+ return {
186
+ status: 200,
187
+ body: json(inlineCustomDogBody),
188
+ };
189
+ }
190
+ else {
191
+ // Default case: when type is null, undefined, or "cat"
192
+ return {
193
+ status: 200,
194
+ body: json(inlineCustomCatBody),
195
+ };
196
+ }
197
+ },
198
+ kind: "MockApiDefinition",
199
+ });
200
+ Scenarios.Type_Union_Discriminated_NoEnvelope_CustomDiscriminator_put = passOnSuccess({
201
+ uri: "/type/union/discriminated/no-envelope/custom-discriminator",
202
+ method: "put",
203
+ request: {
204
+ body: json(inlineCustomCatBody),
205
+ },
206
+ response: {
207
+ status: 200,
208
+ body: json(inlineCustomCatBody),
209
+ },
210
+ kind: "MockApiDefinition",
211
+ });
212
+ //# sourceMappingURL=mockapi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mockapi.js","sourceRoot":"","sources":["../../../../../specs/type/union/discriminated/mockapi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAe,aAAa,EAAmB,MAAM,oBAAoB,CAAC;AAEvF,MAAM,CAAC,MAAM,SAAS,GAAoC,EAAE,CAAC;AAE7D,8CAA8C;AAC9C,MAAM,OAAO,GAAG;IACd,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,IAAI;CACX,CAAC;AAEF,MAAM,OAAO,GAAG;IACd,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,KAAK;CACZ,CAAC;AAEF,uDAAuD;A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E,KAAK;CACZ,CAAC;AAEF,SAAS,CAAC,2DAA2D,GAAG,aAAa,CAAC;IACpF,GAAG,EAAE,4DAA4D;IACjE,MAAM,EAAE,KAAK;IACb,OAAO,EAAE,EAAE;IACX,QAAQ,EAAE;QACR,MAAM,EAAE,GAAG;QACX,IAAI,EAAE,IAAI,CAAC,mBAAmB,CAAC;KAChC;IACD,OAAO,EAAE,CAAC,GAAgB,EAAE,EAAE;QAC5B,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,IAA0B,CAAC;QAElD,wDAAwD;QACxD,gDAAgD;QAChD,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;YACnB,OAAO;gBACL,MAAM,EAAE,GAAG;gBACX,IAAI,EAAE,IAAI,CAAC,mBAAmB,CAAC;aAChC,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,uDAAuD;YACvD,OAAO;gBACL,MAAM,EAAE,GAAG;gBACX,IAAI,EAAE,IAAI,CAAC,mBAAmB,CAAC;aAChC,CAAC;QACJ,CAAC;IACH,CAAC;IACD,IAAI,EAAE,mBAAmB;CAC1B,CAAC,CAAC;AAEH,SAAS,CAAC,2DAA2D,GAAG,aAAa,CAAC;IACpF,GAAG,EAAE,4DAA4D;IACjE,MAAM,EAAE,KAAK;IACb,OAAO,EAAE;QACP,IAAI,EAAE,IAAI,CAAC,mBAAmB,CAAC;KAChC;IACD,QAAQ,EAAE;QACR,MAAM,EAAE,GAAG;QACX,IAAI,EAAE,IAAI,CAAC,mBAAmB,CAAC;KAChC;IACD,IAAI,EAAE,mBAAmB;CAC1B,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/http-specs",
3
- "version": "0.1.0-alpha.24-dev.0",
3
+ "version": "0.1.0-alpha.24-dev.2",
4
4
  "description": "Spec scenarios and mock apis",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -25,10 +25,10 @@
25
25
  "devDependencies": {
26
26
  "@types/deep-equal": "^1.0.1",
27
27
  "@types/multer": "^1.4.10",
28
- "@types/node": "~22.13.11",
28
+ "@types/node": "~24.0.3",
29
+ "@typespec/json-schema": "^1.1.0",
29
30
  "@typespec/openapi": "^1.1.0",
30
31
  "@typespec/openapi3": "^1.1.0",
31
- "@typespec/json-schema": "^1.1.0",
32
32
  "concurrently": "^9.1.2",
33
33
  "rimraf": "~6.0.1",
34
34
  "typescript": "~5.8.2"
package/spec-summary.md CHANGED
@@ -7127,6 +7127,178 @@ Expect to handle a unknown type value. Mock api will return 'test'
7127
7127
 
7128
7128
  Expect to send a string value. Mock api expect to receive 'test'
7129
7129
 
7130
+ ### Type_Union_Discriminated_Envelope_Object_CustomProperties_get
7131
+
7132
+ - Endpoint: `get /type/union/discriminated/envelope/object/custom-properties`
7133
+
7134
+ Test discriminated union with custom property names.
7135
+ When value of query parameter "petType" is "cat" or no query parameter input, the expected response is:
7136
+
7137
+ ```json
7138
+ {
7139
+ "petType": "cat",
7140
+ "petData": {
7141
+ "name": "Whiskers",
7142
+ "meow": true
7143
+ }
7144
+ }
7145
+ ```
7146
+
7147
+ When it is "dog", expected response is:
7148
+
7149
+ ```json
7150
+ {
7151
+ "petType": "dog",
7152
+ "petData": {
7153
+ "name": "Rex",
7154
+ "bark": false
7155
+ }
7156
+ }
7157
+ ```
7158
+
7159
+ ### Type_Union_Discriminated_Envelope_Object_CustomProperties_put
7160
+
7161
+ - Endpoint: `put /type/union/discriminated/envelope/object/custom-properties`
7162
+
7163
+ Test discriminated union with custom property names.
7164
+ Send the union as:
7165
+
7166
+ ```json
7167
+ {
7168
+ "petType": "cat",
7169
+ "petData": {
7170
+ "name": "Whiskers",
7171
+ "meow": true
7172
+ }
7173
+ }
7174
+ ```
7175
+
7176
+ ### Type_Union_Discriminated_Envelope_Object_Default_get
7177
+
7178
+ - Endpoint: `get /type/union/discriminated/envelope/object/default`
7179
+
7180
+ Test discriminated union with envelope serialization.
7181
+ When value of query parameter "kind" is "cat" or no query parameter input, the expected response is:
7182
+
7183
+ ```json
7184
+ {
7185
+ "kind": "cat",
7186
+ "value": {
7187
+ "name": "Whiskers",
7188
+ "meow": true
7189
+ }
7190
+ }
7191
+ ```
7192
+
7193
+ When it is "dog", expected response is:
7194
+
7195
+ ```json
7196
+ {
7197
+ "kind": "dog",
7198
+ "value": {
7199
+ "name": "Rex",
7200
+ "bark": false
7201
+ }
7202
+ }
7203
+ ```
7204
+
7205
+ ### Type_Union_Discriminated_Envelope_Object_Default_put
7206
+
7207
+ - Endpoint: `put /type/union/discriminated/envelope/object/default`
7208
+
7209
+ Test discriminated union with envelope serialization.
7210
+ Send the union as:
7211
+
7212
+ ```json
7213
+ {
7214
+ "kind": "cat",
7215
+ "value": {
7216
+ "name": "Whiskers",
7217
+ "meow": true
7218
+ }
7219
+ }
7220
+ ```
7221
+
7222
+ ### Type_Union_Discriminated_NoEnvelope_CustomDiscriminator_get
7223
+
7224
+ - Endpoint: `get /type/union/discriminated/no-envelope/custom-discriminator`
7225
+
7226
+ Test discriminated union with inline discriminator and custom discriminator property name.
7227
+ When value of query parameter "type" is "cat" or no query parameter input, the expected response is:
7228
+
7229
+ ```json
7230
+ {
7231
+ "type": "cat",
7232
+ "name": "Whiskers",
7233
+ "meow": true
7234
+ }
7235
+ ```
7236
+
7237
+ When it is "dog", expected response is:
7238
+
7239
+ ```json
7240
+ {
7241
+ "type": "dog",
7242
+ "name": "Rex",
7243
+ "bark": false
7244
+ }
7245
+ ```
7246
+
7247
+ ### Type_Union_Discriminated_NoEnvelope_CustomDiscriminator_put
7248
+
7249
+ - Endpoint: `put /type/union/discriminated/no-envelope/custom-discriminator`
7250
+
7251
+ Test discriminated union with inline discriminator and custom discriminator property name.
7252
+ Send the union as:
7253
+
7254
+ ```json
7255
+ {
7256
+ "type": "cat",
7257
+ "name": "Whiskers",
7258
+ "meow": true
7259
+ }
7260
+ ```
7261
+
7262
+ ### Type_Union_Discriminated_NoEnvelope_Default_get
7263
+
7264
+ - Endpoint: `get /type/union/discriminated/no-envelope/default`
7265
+
7266
+ Test discriminated union with inline discriminator.
7267
+ When value of query parameter "kind" is "cat" or no query parameter input, the expected response is:
7268
+
7269
+ ```json
7270
+ {
7271
+ "kind": "cat",
7272
+ "name": "Whiskers",
7273
+ "meow": true
7274
+ }
7275
+ ```
7276
+
7277
+ When it is "dog", expected response is:
7278
+
7279
+ ```json
7280
+ {
7281
+ "kind": "dog",
7282
+ "name": "Rex",
7283
+ "bark": false
7284
+ }
7285
+ ```
7286
+
7287
+ ### Type_Union_Discriminated_NoEnvelope_Default_put
7288
+
7289
+ - Endpoint: `put /type/union/discriminated/no-envelope/default`
7290
+
7291
+ Test discriminated union with inline discriminator.
7292
+ Send the union as:
7293
+
7294
+ ```json
7295
+ {
7296
+ "kind": "cat",
7297
+ "name": "Whiskers",
7298
+ "meow": true
7299
+ }
7300
+ ```
7301
+
7130
7302
  ### Type_Union_EnumsOnly_get
7131
7303
 
7132
7304
  - Endpoint: `get /type/union/enums-only`
@@ -0,0 +1,251 @@
1
+ import "@typespec/http";
2
+ import "@typespec/spector";
3
+
4
+ using Http;
5
+ using Spector;
6
+
7
+ /**
8
+ * Describe scenarios for discriminated unions.
9
+ */
10
+ @scenarioService("/type/union/discriminated")
11
+ namespace Type.Union.Discriminated;
12
+
13
+ // Models for discriminated unions
14
+ model Cat {
15
+ name: string;
16
+ meow: boolean;
17
+ }
18
+
19
+ model Dog {
20
+ name: string;
21
+ bark: boolean;
22
+ }
23
+
24
+ /**
25
+ * Test discriminated union with default envelope serialization.
26
+ * The discriminated union should serialize with "kind" as discriminator
27
+ * and "value" as envelope property.
28
+ */
29
+ @discriminated
30
+ union PetWithEnvelope {
31
+ cat: Cat,
32
+ dog: Dog,
33
+ }
34
+
35
+ @route("/envelope")
36
+ namespace Envelope {
37
+ @route("/object")
38
+ namespace Object {
39
+ @route("/default")
40
+ interface Default {
41
+ @scenario
42
+ @scenarioDoc("""
43
+ Test discriminated union with envelope serialization.
44
+ When value of query parameter "kind" is "cat" or no query parameter input, the expected response is:
45
+ ```json
46
+ {
47
+ "kind": "cat",
48
+ "value": {
49
+ "name": "Whiskers",
50
+ "meow": true
51
+ }
52
+ }
53
+ ```
54
+ When it is "dog", expected response is:
55
+ ```json
56
+ {
57
+ "kind": "dog",
58
+ "value": {
59
+ "name": "Rex",
60
+ "bark": false
61
+ }
62
+ }
63
+ ```
64
+ """)
65
+ @get
66
+ get(@query kind?: string): PetWithEnvelope;
67
+
68
+ @scenario
69
+ @scenarioDoc("""
70
+ Test discriminated union with envelope serialization.
71
+ Send the union as:
72
+ ```json
73
+ {
74
+ "kind": "cat",
75
+ "value": {
76
+ "name": "Whiskers",
77
+ "meow": true
78
+ }
79
+ }
80
+ ```
81
+ """)
82
+ @put
83
+ put(@body input: PetWithEnvelope): PetWithEnvelope;
84
+ }
85
+
86
+ @route("/custom-properties")
87
+ interface CustomProperties {
88
+ @scenario
89
+ @scenarioDoc("""
90
+ Test discriminated union with custom property names.
91
+ When value of query parameter "petType" is "cat" or no query parameter input, the expected response is:
92
+ ```json
93
+ {
94
+ "petType": "cat",
95
+ "petData": {
96
+ "name": "Whiskers",
97
+ "meow": true
98
+ }
99
+ }
100
+ ```
101
+ When it is "dog", expected response is:
102
+ ```json
103
+ {
104
+ "petType": "dog",
105
+ "petData": {
106
+ "name": "Rex",
107
+ "bark": false
108
+ }
109
+ }
110
+ ```
111
+ """)
112
+ @get
113
+ get(@query petType?: string): PetWithCustomNames;
114
+
115
+ @scenario
116
+ @scenarioDoc("""
117
+ Test discriminated union with custom property names.
118
+ Send the union as:
119
+ ```json
120
+ {
121
+ "petType": "cat",
122
+ "petData": {
123
+ "name": "Whiskers",
124
+ "meow": true
125
+ }
126
+ }
127
+ ```
128
+ """)
129
+ @put
130
+ put(@body input: PetWithCustomNames): PetWithCustomNames;
131
+ }
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Test discriminated union with custom property names.
137
+ * The discriminated union should serialize with custom discriminator
138
+ * and envelope property names.
139
+ */
140
+ @discriminated(#{ discriminatorPropertyName: "petType", envelopePropertyName: "petData" })
141
+ union PetWithCustomNames {
142
+ cat: Cat,
143
+ dog: Dog,
144
+ }
145
+
146
+ /**
147
+ * Test discriminated union with inline discriminator (no envelope).
148
+ * The discriminated union should serialize with discriminator property
149
+ * injected directly into the variant object.
150
+ */
151
+ @discriminated(#{ envelope: "none" })
152
+ union PetInline {
153
+ cat: Cat,
154
+ dog: Dog,
155
+ }
156
+
157
+ /**
158
+ * Test discriminated union with inline discriminator and custom discriminator property name.
159
+ * The discriminated union should serialize with custom discriminator property
160
+ * injected directly into the variant object.
161
+ */
162
+ @discriminated(#{ envelope: "none", discriminatorPropertyName: "type" })
163
+ union PetInlineWithCustomDiscriminator {
164
+ cat: Cat,
165
+ dog: Dog,
166
+ }
167
+
168
+ @route("/no-envelope")
169
+ namespace NoEnvelope {
170
+ @route("/default")
171
+ interface Default {
172
+ @scenario
173
+ @scenarioDoc("""
174
+ Test discriminated union with inline discriminator.
175
+ When value of query parameter "kind" is "cat" or no query parameter input, the expected response is:
176
+ ```json
177
+ {
178
+ "kind": "cat",
179
+ "name": "Whiskers",
180
+ "meow": true
181
+ }
182
+ ```
183
+ When it is "dog", expected response is:
184
+ ```json
185
+ {
186
+ "kind": "dog",
187
+ "name": "Rex",
188
+ "bark": false
189
+ }
190
+ ```
191
+ """)
192
+ @get
193
+ get(@query kind?: string): PetInline;
194
+
195
+ @scenario
196
+ @scenarioDoc("""
197
+ Test discriminated union with inline discriminator.
198
+ Send the union as:
199
+ ```json
200
+ {
201
+ "kind": "cat",
202
+ "name": "Whiskers",
203
+ "meow": true
204
+ }
205
+ ```
206
+ """)
207
+ @put
208
+ put(@body input: PetInline): PetInline;
209
+ }
210
+
211
+ @route("/custom-discriminator")
212
+ interface CustomDiscriminator {
213
+ @scenario
214
+ @scenarioDoc("""
215
+ Test discriminated union with inline discriminator and custom discriminator property name.
216
+ When value of query parameter "type" is "cat" or no query parameter input, the expected response is:
217
+ ```json
218
+ {
219
+ "type": "cat",
220
+ "name": "Whiskers",
221
+ "meow": true
222
+ }
223
+ ```
224
+ When it is "dog", expected response is:
225
+ ```json
226
+ {
227
+ "type": "dog",
228
+ "name": "Rex",
229
+ "bark": false
230
+ }
231
+ ```
232
+ """)
233
+ @get
234
+ get(@query type?: string): PetInlineWithCustomDiscriminator;
235
+
236
+ @scenario
237
+ @scenarioDoc("""
238
+ Test discriminated union with inline discriminator and custom discriminator property name.
239
+ Send the union as:
240
+ ```json
241
+ {
242
+ "type": "cat",
243
+ "name": "Whiskers",
244
+ "meow": true
245
+ }
246
+ ```
247
+ """)
248
+ @put
249
+ put(@body input: PetInlineWithCustomDiscriminator): PetInlineWithCustomDiscriminator;
250
+ }
251
+ }