Skip to content

Commit a52c3d0

Browse files
committed
OpenApi type improvements
1 parent c4117ea commit a52c3d0

File tree

2 files changed

+150
-31
lines changed

2 files changed

+150
-31
lines changed

openapi-3-1/index.d.ts

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,55 @@ type ExternalDocumentation = {
180180
url: string;
181181
};
182182

183-
type Parameter = {
183+
export type Parameter = {
184184
name: string;
185-
in: "query" | "header" | "path" | "cookie";
186185
description?: string;
187186
required?: boolean;
188187
deprecated?: boolean;
189188
allowEmptyValue?: boolean;
190-
style?: "matrix" | "label" | "form" | "simple" | "spaceDelimited" | "pipeDelimited" | "deepObject";
189+
} & (
190+
(
191+
{
192+
in: "path";
193+
required: true;
194+
} & (
195+
({ style?: "matrix" | "label" | "simple" } & SchemaParameter)
196+
| ContentParameter
197+
)
198+
) | (
199+
{
200+
in: "query";
201+
} & (
202+
({ style?: "form" | "spaceDelimited" | "pipeDelimited" | "deepObject" } & SchemaParameter)
203+
| ContentParameter
204+
)
205+
) | (
206+
{
207+
in: "header";
208+
} & (
209+
({ style?: "simple" } & SchemaParameter)
210+
| ContentParameter
211+
)
212+
) | (
213+
{
214+
in: "cookie";
215+
} & (
216+
({ style?: "form" } & SchemaParameter)
217+
| ContentParameter
218+
)
219+
)
220+
);
221+
222+
type ContentParameter = {
223+
schema?: never;
224+
content: Record<string, MediaType | Reference>;
225+
};
226+
227+
type SchemaParameter = {
191228
explode?: boolean;
192229
allowReserved?: boolean;
193-
schema?: OasSchema31;
194-
content?: Content;
230+
schema: OasSchema32;
231+
content?: never;
195232
} & Examples;
196233

197234
type RequestBody = {
@@ -263,14 +300,26 @@ type Reference = {
263300
};
264301

265302
type SecurityScheme = {
266-
type: "apiKey" | "http" | "mutualTLS" | "oauth2" | "openIdConnect";
303+
type: "apiKey";
267304
description?: string;
268-
name?: string;
269-
in?: "query" | "header" | "cookie";
270-
scheme?: string;
305+
name: string;
306+
in: "query" | "header" | "cookie";
307+
} | {
308+
type: "http";
309+
description?: string;
310+
scheme: string;
271311
bearerFormat?: string;
272-
flows?: OauthFlows;
273-
openIdConnectUrl?: string;
312+
} | {
313+
type: "mutualTLS";
314+
description?: string;
315+
} | {
316+
type: "oauth2";
317+
description?: string;
318+
flows: OauthFlows;
319+
} | {
320+
type: "openIdConnect";
321+
description?: string;
322+
openIdConnectUrl: string;
274323
};
275324

276325
type OauthFlows = {

openapi-3-2/index.d.ts

Lines changed: 90 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,58 @@ type Operation = {
183183
servers?: Server[];
184184
};
185185

186-
type Parameter = {
186+
export type Parameter = {
187187
name: string;
188-
in: "query" | "querystring" | "header" | "path" | "cookie";
189188
description?: string;
190189
required?: boolean;
191190
deprecated?: boolean;
192191
allowEmptyValue?: boolean;
193-
} & Examples & ({
194-
style?: "matrix" | "label" | "form" | "simple" | "spaceDelimited" | "pipeDelimited" | "deepObject";
192+
} & Examples & (
193+
(
194+
{
195+
in: "path";
196+
required: true;
197+
} & (
198+
({ style?: "matrix" | "label" | "simple" } & SchemaParameter)
199+
| ContentParameter
200+
)
201+
) | (
202+
{
203+
in: "query";
204+
} & (
205+
({ style?: "form" | "spaceDelimited" | "pipeDelimited" | "deepObject" } & SchemaParameter)
206+
| ContentParameter
207+
)
208+
) | (
209+
{
210+
in: "header";
211+
} & (
212+
({ style?: "simple" } & SchemaParameter)
213+
| ContentParameter
214+
)
215+
) | (
216+
{
217+
in: "cookie";
218+
} & (
219+
({ style?: "cookie" } & SchemaParameter)
220+
| ContentParameter
221+
)
222+
) | (
223+
{ in: "querystring" } & ContentParameter
224+
)
225+
);
226+
227+
type ContentParameter = {
228+
schema?: never;
229+
content: Record<string, MediaType | Reference>;
230+
};
231+
232+
type SchemaParameter = {
195233
explode?: boolean;
234+
allowReserved?: boolean;
196235
schema: OasSchema32;
197-
} | {
198-
content: Record<string, MediaType | Reference>;
199-
});
236+
content?: never;
237+
};
200238

201239
type RequestBody = {
202240
description?: string;
@@ -207,21 +245,31 @@ type RequestBody = {
207245
type MediaType = {
208246
schema?: OasSchema32;
209247
itemSchema?: OasSchema32;
248+
} & Examples & ({
210249
encoding?: Record<string, Encoding>;
250+
prefixEncoding?: never;
251+
itemEncoding?: never;
252+
} | {
253+
encoding?: never;
211254
prefixEncoding?: Encoding[];
212255
itemEncoding?: Encoding;
213-
} & Examples;
256+
});
214257

215258
type Encoding = {
216259
contentType?: string;
217260
headers?: Record<string, Header | Reference>;
218-
encoding?: Record<string, Encoding>;
219-
prefixEncoding?: Encoding[];
220-
itemEncoding?: Encoding;
221261
style?: "form" | "spaceDelimited" | "pipeDelimited" | "deepObject";
222262
explode?: boolean;
223263
allowReserved?: boolean;
224-
};
264+
} & ({
265+
encoding?: Record<string, Encoding>;
266+
prefixEncoding?: never;
267+
itemEncoding?: never;
268+
} | {
269+
encoding?: never;
270+
prefixEncoding?: Encoding[];
271+
itemEncoding?: Encoding;
272+
});
225273

226274
type Responses = {
227275
default?: Response | Reference;
@@ -245,11 +293,17 @@ type Examples = {
245293
type Example = {
246294
summary?: string;
247295
description?: string;
296+
} & ({
297+
value?: Json;
298+
dataValue?: never;
299+
serializedValue?: never;
300+
externalValue?: never;
301+
} | {
302+
value?: never;
248303
dataValue?: Json;
249304
serializedValue?: string;
250305
externalValue?: string;
251-
value?: Json;
252-
};
306+
});
253307

254308
type Link = {
255309
operationRef?: string;
@@ -288,16 +342,32 @@ type Reference = {
288342
};
289343

290344
type SecurityScheme = {
291-
type: "apiKey" | "http" | "mutualTLS" | "oauth2" | "openIdConnect";
345+
type: "apiKey";
292346
description?: string;
293-
name?: string;
294-
in?: "query" | "header" | "cookie";
295-
scheme?: string;
347+
name: string;
348+
in: "query" | "header" | "cookie";
349+
deprecated?: boolean;
350+
} | {
351+
type: "http";
352+
description?: string;
353+
scheme: string;
296354
bearerFormat?: string;
297-
flows?: OauthFlows;
298-
openIdConnectUrl?: string;
355+
deprecated?: boolean;
356+
} | {
357+
type: "mutualTLS";
358+
description?: string;
359+
deprecated?: boolean;
360+
} | {
361+
type: "oauth2";
362+
description?: string;
363+
flows: OauthFlows;
299364
oauth2MetadataUrl?: string;
300365
deprecated?: boolean;
366+
} | {
367+
type: "openIdConnect";
368+
description?: string;
369+
openIdConnectUrl: string;
370+
deprecated?: boolean;
301371
};
302372

303373
type OauthFlows = {

0 commit comments

Comments
 (0)