Skip to content

Commit f7fdb32

Browse files
authored
refactor: replace Map type with Record (#1173)
1 parent 86e0613 commit f7fdb32

File tree

1 file changed

+52
-55
lines changed
  • packages/docusaurus-plugin-openapi-docs/src/openapi

1 file changed

+52
-55
lines changed

packages/docusaurus-plugin-openapi-docs/src/openapi/types.ts

Lines changed: 52 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ import type {
1212
JSONSchema7TypeName,
1313
} from "json-schema";
1414

15-
interface Map<T> {
16-
[key: string]: T;
17-
}
18-
1915
export interface OpenApiObject {
2016
openapi: string;
2117
info: InfoObject;
@@ -74,7 +70,7 @@ export interface LicenseObject {
7470
export interface ServerObject {
7571
url: string;
7672
description?: string;
77-
variables?: Map<ServerVariable>;
73+
variables?: Record<string, ServerVariable>;
7874
}
7975

8076
export interface ServerVariable {
@@ -84,32 +80,32 @@ export interface ServerVariable {
8480
}
8581

8682
export interface ComponentsObject {
87-
schemas?: Map<SchemaObject>;
88-
responses?: Map<ResponseObject>;
89-
parameters?: Map<ParameterObject>;
90-
examples?: Map<ExampleObject>;
91-
requestBodies?: Map<RequestBodyObject>;
92-
headers?: Map<HeaderObject>;
93-
securitySchemes?: Map<SecuritySchemeObject>;
94-
links?: Map<LinkObject>;
95-
callbacks?: Map<CallbackObject>;
83+
schemas?: Record<string, SchemaObject>;
84+
responses?: Record<string, ResponseObject>;
85+
parameters?: Record<string, ParameterObject>;
86+
examples?: Record<string, ExampleObject>;
87+
requestBodies?: Record<string, RequestBodyObject>;
88+
headers?: Record<string, HeaderObject>;
89+
securitySchemes?: Record<string, SecuritySchemeObject>;
90+
links?: Record<string, LinkObject>;
91+
callbacks?: Record<string, CallbackObject>;
9692
}
9793

9894
export interface ComponentsObjectWithRef {
99-
schemas?: Map<SchemaObjectWithRef | ReferenceObject>;
100-
responses?: Map<ResponseObjectWithRef | ReferenceObject>;
101-
parameters?: Map<ParameterObjectWithRef | ReferenceObject>;
102-
examples?: Map<ExampleObject | ReferenceObject>;
103-
requestBodies?: Map<RequestBodyObjectWithRef | ReferenceObject>;
104-
headers?: Map<HeaderObjectWithRef | ReferenceObject>;
105-
securitySchemes?: Map<SecuritySchemeObject | ReferenceObject>;
106-
links?: Map<LinkObject | ReferenceObject>;
107-
callbacks?: Map<CallbackObjectWithRef | ReferenceObject>;
95+
schemas?: Record<string, SchemaObjectWithRef | ReferenceObject>;
96+
responses?: Record<string, ResponseObjectWithRef | ReferenceObject>;
97+
parameters?: Record<string, ParameterObjectWithRef | ReferenceObject>;
98+
examples?: Record<string, ExampleObject | ReferenceObject>;
99+
requestBodies?: Record<string, RequestBodyObjectWithRef | ReferenceObject>;
100+
headers?: Record<string, HeaderObjectWithRef | ReferenceObject>;
101+
securitySchemes?: Record<string, SecuritySchemeObject | ReferenceObject>;
102+
links?: Record<string, LinkObject | ReferenceObject>;
103+
callbacks?: Record<string, CallbackObjectWithRef | ReferenceObject>;
108104
}
109105

110-
export type PathsObject = Map<PathItemObject>;
106+
export type PathsObject = Record<string, PathItemObject>;
111107

112-
export type PathsObjectWithRef = Map<PathItemObjectWithRef>;
108+
export type PathsObjectWithRef = Record<string, PathItemObjectWithRef>;
113109

114110
export interface PathItemObject {
115111
$ref?: string;
@@ -152,7 +148,7 @@ export interface OperationObject {
152148
parameters?: ParameterObject[];
153149
requestBody?: RequestBodyObject;
154150
responses: ResponsesObject;
155-
callbacks?: Map<CallbackObject>;
151+
callbacks?: Record<string, CallbackObject>;
156152
deprecated?: boolean;
157153
security?: SecurityRequirementObject[];
158154
servers?: ServerObject[];
@@ -170,7 +166,7 @@ export interface OperationObjectWithRef {
170166
parameters?: (ParameterObjectWithRef | ReferenceObject)[];
171167
requestBody?: RequestBodyObjectWithRef | ReferenceObject;
172168
responses: ResponsesObjectWithRef;
173-
callbacks?: Map<CallbackObjectWithRef | ReferenceObject>;
169+
callbacks?: Record<string, CallbackObjectWithRef | ReferenceObject>;
174170
deprecated?: boolean;
175171
security?: SecurityRequirementObject[];
176172
servers?: ServerObject[];
@@ -197,9 +193,9 @@ export interface ParameterObject {
197193
allowReserved?: boolean;
198194
schema?: SchemaObject;
199195
example?: any;
200-
examples?: Map<ExampleObject>;
196+
examples?: Record<string, ExampleObject>;
201197
//
202-
content?: Map<MediaTypeObject>;
198+
content?: Record<string, MediaTypeObject>;
203199
param?: Object;
204200
// ignoring stylings: matrix, label, form, simple, spaceDelimited,
205201
// pipeDelimited and deepObject
@@ -219,79 +215,80 @@ export interface ParameterObjectWithRef {
219215
allowReserved?: boolean;
220216
schema?: SchemaObjectWithRef | ReferenceObject;
221217
example?: any;
222-
examples?: Map<ExampleObject | ReferenceObject>;
218+
examples?: Record<string, ExampleObject | ReferenceObject>;
223219
//
224-
content?: Map<MediaTypeObjectWithRef>;
220+
content?: Record<string, MediaTypeObjectWithRef>;
225221
// ignoring stylings: matrix, label, form, simple, spaceDelimited,
226222
// pipeDelimited and deepObject
227223
}
228224

229225
export interface RequestBodyObject {
230226
description?: string;
231-
content: Map<MediaTypeObject>;
227+
content: Record<string, MediaTypeObject>;
232228
required?: boolean;
233229
}
234230

235231
export interface RequestBodyObjectWithRef {
236232
description?: string;
237-
content: Map<MediaTypeObjectWithRef>;
233+
content: Record<string, MediaTypeObjectWithRef>;
238234
required?: boolean;
239235
}
240236

241237
export interface MediaTypeObject {
242238
schema?: SchemaObject;
243239
example?: any;
244-
examples?: Map<ExampleObject>;
245-
encoding?: Map<EncodingObject>;
240+
examples?: Record<string, ExampleObject>;
241+
encoding?: Record<string, EncodingObject>;
246242
type?: any;
247243
}
248244

249245
export interface MediaTypeObjectWithRef {
250246
schema?: SchemaObjectWithRef | ReferenceObject;
251247
example?: any;
252-
examples?: Map<ExampleObject | ReferenceObject>;
253-
encoding?: Map<EncodingObjectWithRef>;
248+
examples?: Record<string, ExampleObject | ReferenceObject>;
249+
encoding?: Record<string, EncodingObjectWithRef>;
254250
}
255251

256252
export interface EncodingObject {
257253
contentType?: string;
258-
headers?: Map<HeaderObject>;
254+
headers?: Record<string, HeaderObject>;
259255
style?: string;
260256
explode?: boolean;
261257
allowReserved?: boolean;
262258
}
263259

264260
export interface EncodingObjectWithRef {
265261
contentType?: string;
266-
headers?: Map<HeaderObjectWithRef | ReferenceObject>;
262+
headers?: Record<string, HeaderObjectWithRef | ReferenceObject>;
267263
style?: string;
268264
explode?: boolean;
269265
allowReserved?: boolean;
270266
}
271267

272-
export type ResponsesObject = Map<ResponseObject>;
268+
export type ResponsesObject = Record<string, ResponseObject>;
273269

274-
export type ResponsesObjectWithRef = Map<
270+
export type ResponsesObjectWithRef = Record<
271+
string,
275272
ResponseObjectWithRef | ReferenceObject
276273
>;
277274

278275
export interface ResponseObject {
279276
description: string;
280-
headers?: Map<HeaderObject>;
281-
content?: Map<MediaTypeObject>;
282-
links?: Map<LinkObject>;
277+
headers?: Record<string, HeaderObject>;
278+
content?: Record<string, MediaTypeObject>;
279+
links?: Record<string, LinkObject>;
283280
}
284281

285282
export interface ResponseObjectWithRef {
286283
description: string;
287-
headers?: Map<HeaderObjectWithRef | ReferenceObject>;
288-
content?: Map<MediaTypeObjectWithRef>;
289-
links?: Map<LinkObject | ReferenceObject>;
284+
headers?: Record<string, HeaderObjectWithRef | ReferenceObject>;
285+
content?: Record<string, MediaTypeObjectWithRef>;
286+
links?: Record<string, LinkObject | ReferenceObject>;
290287
}
291288

292-
export type CallbackObject = Map<PathItemObject>;
289+
export type CallbackObject = Record<string, PathItemObject>;
293290

294-
export type CallbackObjectWithRef = Map<PathItemObjectWithRef>;
291+
export type CallbackObjectWithRef = Record<string, PathItemObjectWithRef>;
295292

296293
export interface ExampleObject {
297294
summary?: string;
@@ -303,7 +300,7 @@ export interface ExampleObject {
303300
export interface LinkObject {
304301
operationRef?: string;
305302
operationId?: string;
306-
parameters?: Map<any>;
303+
parameters?: Record<string, any>;
307304
requestBody?: any;
308305
description?: string;
309306
server?: ServerObject;
@@ -349,7 +346,7 @@ export type SchemaObject = Omit<
349346
anyOf?: SchemaObject[];
350347
not?: SchemaObject;
351348
items?: SchemaObject;
352-
properties?: Map<SchemaObject>;
349+
properties?: Record<string, SchemaObject>;
353350
additionalProperties?: boolean | SchemaObject;
354351

355352
// OpenAPI additions
@@ -383,7 +380,7 @@ export type SchemaObjectWithRef = Omit<
383380
anyOf?: (SchemaObject | ReferenceObject)[];
384381
not?: SchemaObject | ReferenceObject;
385382
items?: SchemaObject | ReferenceObject;
386-
properties?: Map<SchemaObject | ReferenceObject>;
383+
properties?: Record<string, SchemaObject | ReferenceObject>;
387384
additionalProperties?: boolean | SchemaObject | ReferenceObject;
388385

389386
// OpenAPI additions
@@ -399,7 +396,7 @@ export type SchemaObjectWithRef = Omit<
399396

400397
export interface DiscriminatorObject {
401398
propertyName: string;
402-
mapping?: Map<string>;
399+
mapping?: Record<string, string>;
403400
}
404401

405402
export interface XMLObject {
@@ -455,7 +452,7 @@ export interface OAuthFlowObject {
455452
authorizationUrl?: string; // required for some
456453
tokenUrl?: string; // required for some
457454
refreshUrl?: string;
458-
scopes: Map<string>;
455+
scopes: Record<string, string>;
459456
}
460457

461-
export type SecurityRequirementObject = Map<string[]>;
458+
export type SecurityRequirementObject = Record<string, string[]>;

0 commit comments

Comments
 (0)