-12
packages/openapi-ts/src/ir/types.d.ts
-12
packages/openapi-ts/src/ir/types.d.ts
···
27
27
}
28
28
29
29
export interface IROperationObject {
30
-
/**
31
-
* OpenAPI extension fields (x-*) from the original operation.
32
-
* These are custom fields that can be used by plugins.
33
-
*/
34
30
[extension: `x-${string}`]: unknown;
35
31
body?: IRBodyObject;
36
32
deprecated?: boolean;
···
56
52
57
53
interface IRParameterObject
58
54
extends Pick<JsonSchemaDraft2020_12, 'deprecated' | 'description'> {
59
-
/**
60
-
* OpenAPI extension fields (x-*) from the original parameter.
61
-
* These are custom fields that can be used by plugins.
62
-
*/
63
55
[extension: `x-${string}`]: unknown;
64
56
/**
65
57
* Determines whether the parameter value SHOULD allow reserved characters, as defined by RFC3986 `:/?#[]@!$&'()*+,;=` to be included without percent-encoding. The default value is `false`. This property SHALL be ignored if the request body media type is not `application/x-www-form-urlencoded` or `multipart/form-data`. If a value is explicitly defined, then the value of `contentType` (implicit or explicit) SHALL be ignored.
···
153
145
| 'title'
154
146
| 'example'
155
147
> {
156
-
/**
157
-
* OpenAPI extension fields (x-*) from the original schema.
158
-
* These are custom fields that can be used by plugins.
159
-
*/
160
148
[extension: `x-${string}`]: unknown;
161
149
/**
162
150
* If the schema is intended to be used as an object property, it can be
+5
-8
packages/openapi-ts/src/openApi/2.0.x/parser/operation.ts
+5
-8
packages/openapi-ts/src/openApi/2.0.x/parser/operation.ts
···
13
13
} from '../types/spec';
14
14
import { contentToSchema, mediaTypeObjects } from './mediaType';
15
15
import { paginationField } from './pagination';
16
-
import { schemaToIrSchema } from './schema';
16
+
import { parseExtensions, schemaToIrSchema } from './schema';
17
17
18
18
interface Operation
19
19
extends Omit<OperationObject, 'parameters'>,
···
77
77
operation,
78
78
});
79
79
80
-
// Copy extension fields
81
-
for (const key in operation) {
82
-
if (key.startsWith('x-')) {
83
-
(irOperation as unknown as Record<string, unknown>)[key] =
84
-
operation[key as keyof Operation];
85
-
}
86
-
}
80
+
parseExtensions({
81
+
source: operation,
82
+
target: irOperation,
83
+
});
87
84
88
85
return irOperation;
89
86
};
+5
-8
packages/openapi-ts/src/openApi/2.0.x/parser/parameter.ts
+5
-8
packages/openapi-ts/src/openApi/2.0.x/parser/parameter.ts
···
8
8
SchemaObject,
9
9
} from '../types/spec';
10
10
import { paginationField } from './pagination';
11
-
import { schemaToIrSchema } from './schema';
11
+
import { parseExtensions, schemaToIrSchema } from './schema';
12
12
13
13
type Parameter = Exclude<ParameterObject, { in: 'body' }>;
14
14
···
165
165
irParameter.required = parameter.required;
166
166
}
167
167
168
-
// Copy extension fields
169
-
for (const key in parameter) {
170
-
if (key.startsWith('x-')) {
171
-
(irParameter as unknown as Record<string, unknown>)[key] =
172
-
parameter[key as keyof ParameterObject];
173
-
}
174
-
}
168
+
parseExtensions({
169
+
source: parameter,
170
+
target: irParameter,
171
+
});
175
172
176
173
return irParameter;
177
174
};
+9
-11
packages/openapi-ts/src/openApi/2.0.x/parser/schema.ts
+9
-11
packages/openapi-ts/src/openApi/2.0.x/parser/schema.ts
···
270
270
return irSchema;
271
271
};
272
272
273
-
const parseExtensions = ({
274
-
irSchema,
275
-
schema,
273
+
export const parseExtensions = <T extends Record<string, unknown>>({
274
+
source,
275
+
target,
276
276
}: {
277
-
irSchema: IR.SchemaObject;
278
-
schema: SchemaObject;
277
+
source: T;
278
+
target: Record<string, unknown>;
279
279
}) => {
280
-
// Copy all x-* extension fields from the source schema to the IR schema
281
-
for (const key in schema) {
280
+
for (const key in source) {
282
281
if (key.startsWith('x-')) {
283
-
(irSchema as unknown as Record<string, unknown>)[key] =
284
-
schema[key as keyof SchemaObject];
282
+
target[key] = source[key];
285
283
}
286
284
}
287
285
};
···
299
297
});
300
298
301
299
parseExtensions({
302
-
irSchema,
303
-
schema,
300
+
source: schema,
301
+
target: irSchema,
304
302
});
305
303
306
304
return irSchema;
+5
-8
packages/openapi-ts/src/openApi/3.0.x/parser/operation.ts
+5
-8
packages/openapi-ts/src/openApi/3.0.x/parser/operation.ts
···
12
12
} from '../types/spec';
13
13
import { contentToSchema, mediaTypeObjects } from './mediaType';
14
14
import { paginationField } from './pagination';
15
-
import { schemaToIrSchema } from './schema';
15
+
import { parseExtensions, schemaToIrSchema } from './schema';
16
16
17
17
interface Operation
18
18
extends Omit<OperationObject, 'parameters'>,
···
74
74
operation,
75
75
});
76
76
77
-
// Copy extension fields
78
-
for (const key in operation) {
79
-
if (key.startsWith('x-')) {
80
-
(irOperation as unknown as Record<string, unknown>)[key] =
81
-
operation[key as keyof Operation];
82
-
}
83
-
}
77
+
parseExtensions({
78
+
source: operation,
79
+
target: irOperation,
80
+
});
84
81
85
82
return irOperation;
86
83
};
+5
-8
packages/openapi-ts/src/openApi/3.0.x/parser/parameter.ts
+5
-8
packages/openapi-ts/src/openApi/3.0.x/parser/parameter.ts
···
9
9
} from '../types/spec';
10
10
import { mediaTypeObjects } from './mediaType';
11
11
import { paginationField } from './pagination';
12
-
import { schemaToIrSchema } from './schema';
12
+
import { parseExtensions, schemaToIrSchema } from './schema';
13
13
14
14
/**
15
15
* Returns default parameter `allowReserved` based on value of `in`.
···
173
173
irParameter.required = parameter.required;
174
174
}
175
175
176
-
// Copy extension fields
177
-
for (const key in parameter) {
178
-
if (key.startsWith('x-')) {
179
-
(irParameter as unknown as Record<string, unknown>)[key] =
180
-
parameter[key as keyof ParameterObject];
181
-
}
182
-
}
176
+
parseExtensions({
177
+
source: parameter,
178
+
target: irParameter,
179
+
});
183
180
184
181
return irParameter;
185
182
};
+9
-11
packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts
+9
-11
packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts
···
276
276
return irSchema;
277
277
};
278
278
279
-
const parseExtensions = ({
280
-
irSchema,
281
-
schema,
279
+
export const parseExtensions = <T extends Record<string, unknown>>({
280
+
source,
281
+
target,
282
282
}: {
283
-
irSchema: IR.SchemaObject;
284
-
schema: SchemaObject;
283
+
source: T;
284
+
target: Record<string, unknown>;
285
285
}) => {
286
-
// Copy all x-* extension fields from the source schema to the IR schema
287
-
for (const key in schema) {
286
+
for (const key in source) {
288
287
if (key.startsWith('x-')) {
289
-
(irSchema as unknown as Record<string, unknown>)[key] =
290
-
schema[key as keyof SchemaObject];
288
+
target[key] = source[key];
291
289
}
292
290
}
293
291
};
···
305
303
});
306
304
307
305
parseExtensions({
308
-
irSchema,
309
-
schema,
306
+
source: schema,
307
+
target: irSchema,
310
308
});
311
309
312
310
return irSchema;
-12
packages/openapi-ts/src/openApi/3.0.x/types/spec.d.ts
-12
packages/openapi-ts/src/openApi/3.0.x/types/spec.d.ts
···
452
452
* TODO: examples
453
453
*/
454
454
export interface OperationObject {
455
-
/**
456
-
* OpenAPI extension fields (x-*) from the original operation.
457
-
* Specification Extensions may be used to add additional metadata.
458
-
*/
459
455
[extension: `x-${string}`]: unknown;
460
456
/**
461
457
* A map of possible out-of band callbacks related to the parent operation. The key is a unique identifier for the Callback Object. Each value in the map is a {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#callback-object Callback Object} that describes a request that may be initiated by the API provider and the expected responses.
···
552
548
* TODO: examples
553
549
*/
554
550
export interface ParameterObject {
555
-
/**
556
-
* OpenAPI extension fields (x-*) from the original parameter.
557
-
* Specification Extensions may be used to add additional metadata.
558
-
*/
559
551
[extension: `x-${string}`]: unknown;
560
552
/**
561
553
* If `true`, clients MAY pass a zero-length string value in place of parameters that would otherwise be omitted entirely, which the server SHOULD interpret as the parameter being unused. Default value is `false`. If {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#parameter-style `style`} is used, and if {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#style-examples behavior is _n/a_ (cannot be serialized)}, the value of `allowEmptyValue` SHALL be ignored. Interactions between this field and the parameter's {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#schema-object Schema Object} are implementation-defined. This field is valid only for `query` parameters. Use of this field is NOT RECOMMENDED, and it is likely to be removed in a later revision.
···
855
847
* TODO: content, examples
856
848
*/
857
849
export interface SchemaObject extends EnumExtensions {
858
-
/**
859
-
* OpenAPI extension fields (x-*) from the original schema.
860
-
* Specification Extensions may be used to add additional metadata.
861
-
*/
862
850
[extension: `x-${string}`]: unknown;
863
851
/**
864
852
* The value of "additionalProperties" MUST be a boolean or a schema.
+4
-7
packages/openapi-ts/src/openApi/3.1.x/parser/operation.ts
+4
-7
packages/openapi-ts/src/openApi/3.1.x/parser/operation.ts
···
74
74
operation,
75
75
});
76
76
77
-
// Copy extension fields
78
-
for (const key in operation) {
79
-
if (key.startsWith('x-')) {
80
-
(irOperation as unknown as Record<string, unknown>)[key] =
81
-
operation[key as keyof Operation];
82
-
}
83
-
}
77
+
parseExtensions({
78
+
source: operation,
79
+
target: irOperation,
80
+
});
84
81
85
82
return irOperation;
86
83
};
+4
-7
packages/openapi-ts/src/openApi/3.1.x/parser/parameter.ts
+4
-7
packages/openapi-ts/src/openApi/3.1.x/parser/parameter.ts
···
166
166
irParameter.required = parameter.required;
167
167
}
168
168
169
-
// Copy extension fields
170
-
for (const key in parameter) {
171
-
if (key.startsWith('x-')) {
172
-
(irParameter as unknown as Record<string, unknown>)[key] =
173
-
parameter[key as keyof ParameterObject];
174
-
}
175
-
}
169
+
parseExtensions({
170
+
source: parameter,
171
+
target: irParameter,
172
+
});
176
173
177
174
return irParameter;
178
175
};
+9
-11
packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts
+9
-11
packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts
···
357
357
return irSchema;
358
358
};
359
359
360
-
const parseExtensions = ({
361
-
irSchema,
362
-
schema,
360
+
export const parseExtensions = <T extends Record<string, unknown>>({
361
+
source,
362
+
target,
363
363
}: {
364
-
irSchema: IR.SchemaObject;
365
-
schema: SchemaObject;
364
+
source: T;
365
+
target: Record<string, unknown>;
366
366
}) => {
367
-
// Copy all x-* extension fields from the source schema to the IR schema
368
-
for (const key in schema) {
367
+
for (const key in source) {
369
368
if (key.startsWith('x-')) {
370
-
(irSchema as unknown as Record<string, unknown>)[key] =
371
-
schema[key as keyof SchemaObject];
369
+
target[key] = source[key];
372
370
}
373
371
}
374
372
};
···
386
384
});
387
385
388
386
parseExtensions({
389
-
irSchema,
390
-
schema,
387
+
source: schema,
388
+
target: irSchema,
391
389
});
392
390
393
391
return irSchema;
-4
packages/openapi-ts/src/openApi/3.1.x/types/json-schema-draft-2020-12.d.ts
-4
packages/openapi-ts/src/openApi/3.1.x/types/json-schema-draft-2020-12.d.ts
···
11
11
StringKeywords,
12
12
EnumExtensions,
13
13
OpenApiSchemaExtensions {
14
-
/**
15
-
* OpenAPI extension fields (x-*) from the original schema.
16
-
* Specification Extensions may be used to add additional metadata.
17
-
*/
18
14
[extension: `x-${string}`]: unknown;
19
15
/**
20
16
* The `$comment` {@link https://json-schema.org/learn/glossary#keyword keyword} is strictly intended for adding comments to a schema. Its value must always be a string. Unlike the annotations `title`, `description`, and `examples`, JSON schema {@link https://json-schema.org/learn/glossary#implementation implementations} aren't allowed to attach any meaning or behavior to it whatsoever, and may even strip them at any time. Therefore, they are useful for leaving notes to future editors of a JSON schema, but should not be used to communicate to users of the schema.
-8
packages/openapi-ts/src/openApi/3.1.x/types/spec.d.ts
-8
packages/openapi-ts/src/openApi/3.1.x/types/spec.d.ts
···
1046
1046
* ```
1047
1047
*/
1048
1048
export interface OperationObject {
1049
-
/**
1050
-
* OpenAPI extension fields (x-*) from the original operation.
1051
-
* Specification Extensions may be used to add additional metadata.
1052
-
*/
1053
1049
[extension: `x-${string}`]: unknown;
1054
1050
/**
1055
1051
* A map of possible out-of band callbacks related to the parent operation. The key is a unique identifier for the Callback Object. Each value in the map is a {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callback-object Callback Object} that describes a request that may be initiated by the API provider and the expected responses.
···
1199
1195
* ```
1200
1196
*/
1201
1197
export interface ParameterObject {
1202
-
/**
1203
-
* OpenAPI extension fields (x-*) from the original parameter.
1204
-
* Specification Extensions may be used to add additional metadata.
1205
-
*/
1206
1198
[extension: `x-${string}`]: unknown;
1207
1199
/**
1208
1200
* Sets the ability to pass empty-valued parameters. This is valid only for `query` parameters and allows sending a parameter with an empty value. Default value is `false`. If {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterStyle `style`} is used, and if behavior is `n/a` (cannot be serialized), the value of `allowEmptyValue` SHALL be ignored. Use of this property is NOT RECOMMENDED, as it is likely to be removed in a later revision.