@kubb/plugin-oas 3.16.1 → 3.16.3
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/Oas-CuqAnIw-.js +60 -0
- package/dist/Oas-CuqAnIw-.js.map +1 -0
- package/dist/Oas-Cv_pyXRM.cjs +78 -0
- package/dist/Oas-Cv_pyXRM.cjs.map +1 -0
- package/dist/OperationGenerator-CgbXErhW.d.cts +900 -0
- package/dist/OperationGenerator-OtLcGk2y.d.ts +900 -0
- package/dist/Schema-DJshqHto.d.cts +38 -0
- package/dist/Schema-DOXGUW1m.d.ts +38 -0
- package/dist/SchemaGenerator-8205BXCp.cjs +942 -0
- package/dist/SchemaGenerator-8205BXCp.cjs.map +1 -0
- package/dist/SchemaGenerator-B8Io6kky.js +930 -0
- package/dist/SchemaGenerator-B8Io6kky.js.map +1 -0
- package/dist/SchemaMapper-BaZQKrQB.js +54 -0
- package/dist/SchemaMapper-BaZQKrQB.js.map +1 -0
- package/dist/SchemaMapper-BiagBQN4.d.cts +388 -0
- package/dist/SchemaMapper-C2J2d3o4.d.ts +388 -0
- package/dist/SchemaMapper-D8J0V9Pj.cjs +66 -0
- package/dist/SchemaMapper-D8J0V9Pj.cjs.map +1 -0
- package/dist/chunk-CUT6urMc.cjs +30 -0
- package/dist/components.cjs +4 -19
- package/dist/components.d.cts +42 -35
- package/dist/components.d.ts +42 -35
- package/dist/components.js +3 -3
- package/dist/generators-BhLMlRNk.js +137 -0
- package/dist/generators-BhLMlRNk.js.map +1 -0
- package/dist/generators-DLH2kvlh.cjs +155 -0
- package/dist/generators-DLH2kvlh.cjs.map +1 -0
- package/dist/generators.cjs +4 -13
- package/dist/generators.d.cts +5 -7
- package/dist/generators.d.ts +5 -7
- package/dist/generators.js +5 -5
- package/dist/getFooter-BChY2kC1.cjs +43 -0
- package/dist/getFooter-BChY2kC1.cjs.map +1 -0
- package/dist/getFooter-T7_pZ6f8.js +31 -0
- package/dist/getFooter-T7_pZ6f8.js.map +1 -0
- package/dist/getSchemas-D8mP129c.cjs +67 -0
- package/dist/getSchemas-D8mP129c.cjs.map +1 -0
- package/dist/getSchemas-WoSBIxG8.js +55 -0
- package/dist/getSchemas-WoSBIxG8.js.map +1 -0
- package/dist/hooks.cjs +213 -195
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +91 -86
- package/dist/hooks.d.ts +91 -86
- package/dist/hooks.js +212 -193
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +280 -344
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -10
- package/dist/index.d.ts +7 -10
- package/dist/index.js +274 -318
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +802 -737
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.cts +12 -11
- package/dist/mocks.d.ts +12 -11
- package/dist/mocks.js +802 -735
- package/dist/mocks.js.map +1 -1
- package/dist/parseFromConfig-CMNGsef2.cjs +33 -0
- package/dist/parseFromConfig-CMNGsef2.cjs.map +1 -0
- package/dist/parseFromConfig-yAiFK03V.js +27 -0
- package/dist/parseFromConfig-yAiFK03V.js.map +1 -0
- package/dist/utils.cjs +58 -74
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +96 -42
- package/dist/utils.d.ts +96 -42
- package/dist/utils.js +47 -46
- package/dist/utils.js.map +1 -1
- package/package.json +28 -36
- package/src/SchemaGenerator.ts +6 -1
- package/src/components/Operation.tsx +1 -2
- package/src/mocks/schemas.ts +39 -0
- package/src/utils/getBanner.ts +5 -5
- package/src/utils/getFooter.ts +4 -4
- package/dist/OperationGenerator-C7NPZtOM.d.ts +0 -288
- package/dist/OperationGenerator-DJE2XQ83.d.cts +0 -288
- package/dist/Schema-AjebpeVY.d.ts +0 -32
- package/dist/Schema-M6983FL1.d.cts +0 -32
- package/dist/SchemaMapper-B21ZmWag.d.cts +0 -275
- package/dist/SchemaMapper-B21ZmWag.d.ts +0 -275
- package/dist/chunk-6S7YFY6F.js +0 -33
- package/dist/chunk-6S7YFY6F.js.map +0 -1
- package/dist/chunk-76E35IZ2.js +0 -56
- package/dist/chunk-76E35IZ2.js.map +0 -1
- package/dist/chunk-7RFNM43R.cjs +0 -41
- package/dist/chunk-7RFNM43R.cjs.map +0 -1
- package/dist/chunk-DTD4ZUDA.cjs +0 -36
- package/dist/chunk-DTD4ZUDA.cjs.map +0 -1
- package/dist/chunk-G3FDK7YW.js +0 -35
- package/dist/chunk-G3FDK7YW.js.map +0 -1
- package/dist/chunk-JNN4JPWK.js +0 -28
- package/dist/chunk-JNN4JPWK.js.map +0 -1
- package/dist/chunk-MBX66JAT.js +0 -93
- package/dist/chunk-MBX66JAT.js.map +0 -1
- package/dist/chunk-NFLZLRQS.cjs +0 -869
- package/dist/chunk-NFLZLRQS.cjs.map +0 -1
- package/dist/chunk-P2VXWGXZ.js +0 -862
- package/dist/chunk-P2VXWGXZ.js.map +0 -1
- package/dist/chunk-PORSNYI5.js +0 -47
- package/dist/chunk-PORSNYI5.js.map +0 -1
- package/dist/chunk-QJMOOF2A.cjs +0 -97
- package/dist/chunk-QJMOOF2A.cjs.map +0 -1
- package/dist/chunk-YWMMI3MO.cjs +0 -59
- package/dist/chunk-YWMMI3MO.cjs.map +0 -1
- package/dist/chunk-Z2NREI4X.cjs +0 -32
- package/dist/chunk-Z2NREI4X.cjs.map +0 -1
- package/dist/chunk-ZVFL3NXX.cjs +0 -50
- package/dist/chunk-ZVFL3NXX.cjs.map +0 -1
- package/dist/components.cjs.map +0 -1
- package/dist/components.js.map +0 -1
- package/dist/generators.cjs.map +0 -1
- package/dist/generators.js.map +0 -1
package/dist/chunk-NFLZLRQS.cjs
DELETED
|
@@ -1,869 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var chunkYWMMI3MO_cjs = require('./chunk-YWMMI3MO.cjs');
|
|
4
|
-
var chunkZVFL3NXX_cjs = require('./chunk-ZVFL3NXX.cjs');
|
|
5
|
-
var core = require('@kubb/core');
|
|
6
|
-
var transformers = require('@kubb/core/transformers');
|
|
7
|
-
var utils = require('@kubb/core/utils');
|
|
8
|
-
var oas = require('@kubb/oas');
|
|
9
|
-
var remeda = require('remeda');
|
|
10
|
-
var pLimit = require('p-limit');
|
|
11
|
-
|
|
12
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
-
|
|
14
|
-
var transformers__default = /*#__PURE__*/_interopDefault(transformers);
|
|
15
|
-
var pLimit__default = /*#__PURE__*/_interopDefault(pLimit);
|
|
16
|
-
|
|
17
|
-
var SchemaGenerator = class _SchemaGenerator extends core.BaseGenerator {
|
|
18
|
-
// Collect the types of all referenced schemas, so we can export them later
|
|
19
|
-
refs = {};
|
|
20
|
-
// Keep track of already used type aliases
|
|
21
|
-
#usedAliasNames = {};
|
|
22
|
-
/**
|
|
23
|
-
* Creates a type node from a given schema.
|
|
24
|
-
* Delegates to getBaseTypeFromSchema internally and
|
|
25
|
-
* optionally adds a union with null.
|
|
26
|
-
*/
|
|
27
|
-
parse(props) {
|
|
28
|
-
const options = this.#getOptions(props);
|
|
29
|
-
const defaultSchemas = this.#parseSchemaObject(props);
|
|
30
|
-
const schemas = options.transformers?.schema?.(props, defaultSchemas) || defaultSchemas || [];
|
|
31
|
-
return remeda.uniqueWith(schemas, remeda.isDeepEqual);
|
|
32
|
-
}
|
|
33
|
-
deepSearch(tree, keyword) {
|
|
34
|
-
return _SchemaGenerator.deepSearch(tree, keyword);
|
|
35
|
-
}
|
|
36
|
-
find(tree, keyword) {
|
|
37
|
-
return _SchemaGenerator.find(tree, keyword);
|
|
38
|
-
}
|
|
39
|
-
static deepSearch(tree, keyword) {
|
|
40
|
-
const foundItems = [];
|
|
41
|
-
tree?.forEach((schema) => {
|
|
42
|
-
if (schema.keyword === keyword) {
|
|
43
|
-
foundItems.push(schema);
|
|
44
|
-
}
|
|
45
|
-
if (chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.object)) {
|
|
46
|
-
Object.values(schema.args?.properties || {}).forEach((entrySchema) => {
|
|
47
|
-
foundItems.push(..._SchemaGenerator.deepSearch(entrySchema, keyword));
|
|
48
|
-
});
|
|
49
|
-
Object.values(schema.args?.additionalProperties || {}).forEach((entrySchema) => {
|
|
50
|
-
foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
if (chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.array)) {
|
|
54
|
-
schema.args.items.forEach((entrySchema) => {
|
|
55
|
-
foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
if (chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.and)) {
|
|
59
|
-
schema.args.forEach((entrySchema) => {
|
|
60
|
-
foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
if (chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.tuple)) {
|
|
64
|
-
schema.args.items.forEach((entrySchema) => {
|
|
65
|
-
foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
if (chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.union)) {
|
|
69
|
-
schema.args.forEach((entrySchema) => {
|
|
70
|
-
foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
return foundItems;
|
|
75
|
-
}
|
|
76
|
-
static findInObject(tree, keyword) {
|
|
77
|
-
let foundItem;
|
|
78
|
-
tree?.forEach((schema) => {
|
|
79
|
-
if (!foundItem && schema.keyword === keyword) {
|
|
80
|
-
foundItem = schema;
|
|
81
|
-
}
|
|
82
|
-
if (chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.object)) {
|
|
83
|
-
Object.values(schema.args?.properties || {}).forEach((entrySchema) => {
|
|
84
|
-
if (!foundItem) {
|
|
85
|
-
foundItem = _SchemaGenerator.find(entrySchema, keyword);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
Object.values(schema.args?.additionalProperties || {}).forEach((entrySchema) => {
|
|
89
|
-
if (!foundItem) {
|
|
90
|
-
foundItem = _SchemaGenerator.find([entrySchema], keyword);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
return foundItem;
|
|
96
|
-
}
|
|
97
|
-
static find(tree, keyword) {
|
|
98
|
-
let foundItem;
|
|
99
|
-
tree?.forEach((schema) => {
|
|
100
|
-
if (!foundItem && schema.keyword === keyword) {
|
|
101
|
-
foundItem = schema;
|
|
102
|
-
}
|
|
103
|
-
if (chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.array)) {
|
|
104
|
-
schema.args.items.forEach((entrySchema) => {
|
|
105
|
-
if (!foundItem) {
|
|
106
|
-
foundItem = _SchemaGenerator.find([entrySchema], keyword);
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
if (chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.and)) {
|
|
111
|
-
schema.args.forEach((entrySchema) => {
|
|
112
|
-
if (!foundItem) {
|
|
113
|
-
foundItem = _SchemaGenerator.find([entrySchema], keyword);
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
if (chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.tuple)) {
|
|
118
|
-
schema.args.items.forEach((entrySchema) => {
|
|
119
|
-
if (!foundItem) {
|
|
120
|
-
foundItem = _SchemaGenerator.find([entrySchema], keyword);
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
if (chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.union)) {
|
|
125
|
-
schema.args.forEach((entrySchema) => {
|
|
126
|
-
if (!foundItem) {
|
|
127
|
-
foundItem = _SchemaGenerator.find([entrySchema], keyword);
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
return foundItem;
|
|
133
|
-
}
|
|
134
|
-
static combineObjects(tree) {
|
|
135
|
-
if (!tree) {
|
|
136
|
-
return [];
|
|
137
|
-
}
|
|
138
|
-
return tree.map((schema) => {
|
|
139
|
-
if (!chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.and)) {
|
|
140
|
-
return schema;
|
|
141
|
-
}
|
|
142
|
-
let mergedProperties = null;
|
|
143
|
-
let mergedAdditionalProps = [];
|
|
144
|
-
const newArgs = [];
|
|
145
|
-
for (const subSchema of schema.args) {
|
|
146
|
-
if (chunkYWMMI3MO_cjs.isKeyword(subSchema, chunkYWMMI3MO_cjs.schemaKeywords.object)) {
|
|
147
|
-
const { properties = {}, additionalProperties = [] } = subSchema.args ?? {};
|
|
148
|
-
if (!mergedProperties) {
|
|
149
|
-
mergedProperties = {};
|
|
150
|
-
}
|
|
151
|
-
for (const [key, value] of Object.entries(properties)) {
|
|
152
|
-
mergedProperties[key] = value;
|
|
153
|
-
}
|
|
154
|
-
if (additionalProperties.length > 0) {
|
|
155
|
-
mergedAdditionalProps = additionalProperties;
|
|
156
|
-
}
|
|
157
|
-
} else {
|
|
158
|
-
newArgs.push(subSchema);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
if (mergedProperties) {
|
|
162
|
-
newArgs.push({
|
|
163
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.object,
|
|
164
|
-
args: {
|
|
165
|
-
properties: mergedProperties,
|
|
166
|
-
additionalProperties: mergedAdditionalProps
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
return {
|
|
171
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.and,
|
|
172
|
-
args: newArgs
|
|
173
|
-
};
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
#getUsedEnumNames(props) {
|
|
177
|
-
const options = this.#getOptions(props);
|
|
178
|
-
return options.usedEnumNames || {};
|
|
179
|
-
}
|
|
180
|
-
#getOptions({ name }) {
|
|
181
|
-
const { override = [] } = this.context;
|
|
182
|
-
return {
|
|
183
|
-
...this.options,
|
|
184
|
-
...override.find(({ pattern, type }) => {
|
|
185
|
-
if (name && type === "schemaName") {
|
|
186
|
-
return !!name.match(pattern);
|
|
187
|
-
}
|
|
188
|
-
return false;
|
|
189
|
-
})?.options || {}
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
#getUnknownType(props) {
|
|
193
|
-
const options = this.#getOptions(props);
|
|
194
|
-
if (options.unknownType === "any") {
|
|
195
|
-
return chunkYWMMI3MO_cjs.schemaKeywords.any;
|
|
196
|
-
}
|
|
197
|
-
if (options.unknownType === "void") {
|
|
198
|
-
return chunkYWMMI3MO_cjs.schemaKeywords.void;
|
|
199
|
-
}
|
|
200
|
-
return chunkYWMMI3MO_cjs.schemaKeywords.unknown;
|
|
201
|
-
}
|
|
202
|
-
#getEmptyType(props) {
|
|
203
|
-
const options = this.#getOptions(props);
|
|
204
|
-
if (options.emptySchemaType === "any") {
|
|
205
|
-
return chunkYWMMI3MO_cjs.schemaKeywords.any;
|
|
206
|
-
}
|
|
207
|
-
if (options.emptySchemaType === "void") {
|
|
208
|
-
return chunkYWMMI3MO_cjs.schemaKeywords.void;
|
|
209
|
-
}
|
|
210
|
-
return chunkYWMMI3MO_cjs.schemaKeywords.unknown;
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Recursively creates a type literal with the given props.
|
|
214
|
-
*/
|
|
215
|
-
#parseProperties({ schemaObject, name }) {
|
|
216
|
-
const properties = schemaObject?.properties || {};
|
|
217
|
-
const additionalProperties = schemaObject?.additionalProperties;
|
|
218
|
-
const required = schemaObject?.required;
|
|
219
|
-
const propertiesSchemas = Object.keys(properties).map((propertyName) => {
|
|
220
|
-
const validationFunctions = [];
|
|
221
|
-
const propertySchema = properties[propertyName];
|
|
222
|
-
const isRequired = Array.isArray(required) ? required?.includes(propertyName) : !!required;
|
|
223
|
-
const nullable = propertySchema.nullable ?? propertySchema["x-nullable"] ?? false;
|
|
224
|
-
validationFunctions.push(...this.parse({ schemaObject: propertySchema, name: propertyName, parentName: name }));
|
|
225
|
-
validationFunctions.push({
|
|
226
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.name,
|
|
227
|
-
args: propertyName
|
|
228
|
-
});
|
|
229
|
-
if (!isRequired && nullable) {
|
|
230
|
-
validationFunctions.push({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.nullish });
|
|
231
|
-
} else if (!isRequired) {
|
|
232
|
-
validationFunctions.push({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.optional });
|
|
233
|
-
}
|
|
234
|
-
return {
|
|
235
|
-
[propertyName]: validationFunctions
|
|
236
|
-
};
|
|
237
|
-
}).reduce((acc, curr) => ({ ...acc, ...curr }), {});
|
|
238
|
-
let additionalPropertiesSchemas = [];
|
|
239
|
-
if (additionalProperties) {
|
|
240
|
-
additionalPropertiesSchemas = additionalProperties === true || !Object.keys(additionalProperties).length ? [{ keyword: this.#getUnknownType({ schemaObject, name }) }] : this.parse({ schemaObject: additionalProperties, parentName: name });
|
|
241
|
-
}
|
|
242
|
-
return [
|
|
243
|
-
{
|
|
244
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.object,
|
|
245
|
-
args: {
|
|
246
|
-
properties: propertiesSchemas,
|
|
247
|
-
additionalProperties: additionalPropertiesSchemas
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
];
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Create a type alias for the schema referenced by the given ReferenceObject
|
|
254
|
-
*/
|
|
255
|
-
#getRefAlias(schemaObject, name) {
|
|
256
|
-
const { $ref } = schemaObject;
|
|
257
|
-
const ref = this.refs[$ref];
|
|
258
|
-
if (ref) {
|
|
259
|
-
const dereferencedSchema = this.context.oas.dereferenceWithRef(schemaObject);
|
|
260
|
-
if (dereferencedSchema && oas.isDiscriminator(dereferencedSchema)) {
|
|
261
|
-
const [key] = Object.entries(dereferencedSchema.discriminator.mapping || {}).find(([_key, value]) => value.replace(/.+\//, "") === name) || [];
|
|
262
|
-
if (key) {
|
|
263
|
-
return [
|
|
264
|
-
{
|
|
265
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.and,
|
|
266
|
-
args: [
|
|
267
|
-
{
|
|
268
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.ref,
|
|
269
|
-
args: { name: ref.propertyName, $ref, path: ref.path, isImportable: !!this.context.oas.get($ref) }
|
|
270
|
-
},
|
|
271
|
-
{
|
|
272
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.object,
|
|
273
|
-
args: {
|
|
274
|
-
properties: {
|
|
275
|
-
[dereferencedSchema.discriminator.propertyName]: [
|
|
276
|
-
{
|
|
277
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.const,
|
|
278
|
-
args: {
|
|
279
|
-
name: key,
|
|
280
|
-
format: "string",
|
|
281
|
-
value: key
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
]
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
]
|
|
289
|
-
}
|
|
290
|
-
];
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
return [
|
|
294
|
-
{
|
|
295
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.ref,
|
|
296
|
-
args: { name: ref.propertyName, $ref, path: ref.path, isImportable: !!this.context.oas.get($ref) }
|
|
297
|
-
}
|
|
298
|
-
];
|
|
299
|
-
}
|
|
300
|
-
const originalName = utils.getUniqueName($ref.replace(/.+\//, ""), this.#usedAliasNames);
|
|
301
|
-
const propertyName = this.context.pluginManager.resolveName({
|
|
302
|
-
name: originalName,
|
|
303
|
-
pluginKey: this.context.plugin.key,
|
|
304
|
-
type: "function"
|
|
305
|
-
});
|
|
306
|
-
const fileName = this.context.pluginManager.resolveName({
|
|
307
|
-
name: originalName,
|
|
308
|
-
pluginKey: this.context.plugin.key,
|
|
309
|
-
type: "file"
|
|
310
|
-
});
|
|
311
|
-
const file = this.context.pluginManager.getFile({
|
|
312
|
-
name: fileName,
|
|
313
|
-
pluginKey: this.context.plugin.key,
|
|
314
|
-
extname: ".ts"
|
|
315
|
-
});
|
|
316
|
-
this.refs[$ref] = {
|
|
317
|
-
propertyName,
|
|
318
|
-
originalName,
|
|
319
|
-
path: file.path
|
|
320
|
-
};
|
|
321
|
-
return this.#getRefAlias(schemaObject, name);
|
|
322
|
-
}
|
|
323
|
-
#getParsedSchemaObject(schema) {
|
|
324
|
-
return chunkZVFL3NXX_cjs.getSchemaFactory(this.context.oas)(schema);
|
|
325
|
-
}
|
|
326
|
-
#addDiscriminatorToSchema({
|
|
327
|
-
schema,
|
|
328
|
-
schemaObject,
|
|
329
|
-
discriminator
|
|
330
|
-
}) {
|
|
331
|
-
if (!chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.union)) {
|
|
332
|
-
return schema;
|
|
333
|
-
}
|
|
334
|
-
const objectPropertySchema = _SchemaGenerator.find(this.parse({ schemaObject }), chunkYWMMI3MO_cjs.schemaKeywords.object);
|
|
335
|
-
return {
|
|
336
|
-
...schema,
|
|
337
|
-
args: Object.entries(discriminator.mapping || {}).map(([key, value]) => {
|
|
338
|
-
const arg = schema.args.find((item) => chunkYWMMI3MO_cjs.isKeyword(item, chunkYWMMI3MO_cjs.schemaKeywords.ref) && item.args.$ref === value);
|
|
339
|
-
return {
|
|
340
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.and,
|
|
341
|
-
args: [
|
|
342
|
-
arg,
|
|
343
|
-
{
|
|
344
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.object,
|
|
345
|
-
args: {
|
|
346
|
-
properties: {
|
|
347
|
-
...objectPropertySchema?.args?.properties || {},
|
|
348
|
-
[discriminator.propertyName]: [
|
|
349
|
-
{
|
|
350
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.const,
|
|
351
|
-
args: {
|
|
352
|
-
name: key,
|
|
353
|
-
format: "string",
|
|
354
|
-
value: key
|
|
355
|
-
}
|
|
356
|
-
},
|
|
357
|
-
//enum and literal will conflict
|
|
358
|
-
...objectPropertySchema?.args?.properties[discriminator.propertyName] || []
|
|
359
|
-
].filter((item) => !chunkYWMMI3MO_cjs.isKeyword(item, chunkYWMMI3MO_cjs.schemaKeywords.enum))
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
]
|
|
364
|
-
};
|
|
365
|
-
})
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* This is the very core of the OpenAPI to TS conversion - it takes a
|
|
370
|
-
* schema and returns the appropriate type.
|
|
371
|
-
*/
|
|
372
|
-
#parseSchemaObject({ schemaObject: _schemaObject, name, parentName }) {
|
|
373
|
-
const { schemaObject, version } = this.#getParsedSchemaObject(_schemaObject);
|
|
374
|
-
const options = this.#getOptions({ schemaObject, name });
|
|
375
|
-
const emptyType = this.#getEmptyType({ schemaObject, name });
|
|
376
|
-
if (!schemaObject) {
|
|
377
|
-
return [{ keyword: emptyType }];
|
|
378
|
-
}
|
|
379
|
-
const baseItems = [
|
|
380
|
-
{
|
|
381
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.schema,
|
|
382
|
-
args: {
|
|
383
|
-
type: schemaObject.type,
|
|
384
|
-
format: schemaObject.format
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
];
|
|
388
|
-
const min = schemaObject.minimum ?? schemaObject.minLength ?? schemaObject.minItems ?? void 0;
|
|
389
|
-
const max = schemaObject.maximum ?? schemaObject.maxLength ?? schemaObject.maxItems ?? void 0;
|
|
390
|
-
const nullable = oas.isNullable(schemaObject);
|
|
391
|
-
const defaultNullAndNullable = schemaObject.default === null && nullable;
|
|
392
|
-
if (schemaObject.default !== void 0 && !defaultNullAndNullable && !Array.isArray(schemaObject.default)) {
|
|
393
|
-
if (typeof schemaObject.default === "string") {
|
|
394
|
-
baseItems.push({
|
|
395
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.default,
|
|
396
|
-
args: transformers__default.default.stringify(schemaObject.default)
|
|
397
|
-
});
|
|
398
|
-
} else if (typeof schemaObject.default === "boolean") {
|
|
399
|
-
baseItems.push({
|
|
400
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.default,
|
|
401
|
-
args: schemaObject.default ?? false
|
|
402
|
-
});
|
|
403
|
-
} else {
|
|
404
|
-
baseItems.push({
|
|
405
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.default,
|
|
406
|
-
args: schemaObject.default
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
if (schemaObject.deprecated) {
|
|
411
|
-
baseItems.push({
|
|
412
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.deprecated
|
|
413
|
-
});
|
|
414
|
-
}
|
|
415
|
-
if (schemaObject.description) {
|
|
416
|
-
baseItems.push({
|
|
417
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.describe,
|
|
418
|
-
args: schemaObject.description
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
if (max !== void 0) {
|
|
422
|
-
baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.max, args: max });
|
|
423
|
-
}
|
|
424
|
-
if (min !== void 0) {
|
|
425
|
-
baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.min, args: min });
|
|
426
|
-
}
|
|
427
|
-
if (nullable) {
|
|
428
|
-
baseItems.push({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.nullable });
|
|
429
|
-
}
|
|
430
|
-
if (schemaObject.type && Array.isArray(schemaObject.type)) {
|
|
431
|
-
const items = schemaObject.type.filter((value) => value !== "null");
|
|
432
|
-
const hasNull = schemaObject.type.includes("null");
|
|
433
|
-
if (hasNull && !nullable) {
|
|
434
|
-
baseItems.push({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.nullable });
|
|
435
|
-
}
|
|
436
|
-
if (items.length > 1) {
|
|
437
|
-
const parsedItems = [
|
|
438
|
-
{
|
|
439
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.union,
|
|
440
|
-
args: items.map(
|
|
441
|
-
(item) => this.parse({
|
|
442
|
-
schemaObject: { ...schemaObject, type: item },
|
|
443
|
-
name,
|
|
444
|
-
parentName
|
|
445
|
-
})[0]
|
|
446
|
-
).filter(Boolean).filter((item) => !chunkYWMMI3MO_cjs.isKeyword(item, chunkYWMMI3MO_cjs.schemaKeywords.unknown)).map((item) => chunkYWMMI3MO_cjs.isKeyword(item, chunkYWMMI3MO_cjs.schemaKeywords.object) ? { ...item, args: { ...item.args, strict: true } } : item)
|
|
447
|
-
}
|
|
448
|
-
];
|
|
449
|
-
return [...parsedItems, ...baseItems].filter(Boolean);
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
if (schemaObject.readOnly) {
|
|
453
|
-
baseItems.push({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.readOnly });
|
|
454
|
-
}
|
|
455
|
-
if (schemaObject.writeOnly) {
|
|
456
|
-
baseItems.push({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.writeOnly });
|
|
457
|
-
}
|
|
458
|
-
if (oas.isReference(schemaObject)) {
|
|
459
|
-
return [
|
|
460
|
-
...this.#getRefAlias(schemaObject, name),
|
|
461
|
-
schemaObject.description && {
|
|
462
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.describe,
|
|
463
|
-
args: schemaObject.description
|
|
464
|
-
},
|
|
465
|
-
nullable && { keyword: chunkYWMMI3MO_cjs.schemaKeywords.nullable },
|
|
466
|
-
schemaObject.readOnly && { keyword: chunkYWMMI3MO_cjs.schemaKeywords.readOnly },
|
|
467
|
-
schemaObject.writeOnly && { keyword: chunkYWMMI3MO_cjs.schemaKeywords.writeOnly },
|
|
468
|
-
{
|
|
469
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.schema,
|
|
470
|
-
args: {
|
|
471
|
-
type: schemaObject.type,
|
|
472
|
-
format: schemaObject.format
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
].filter(Boolean);
|
|
476
|
-
}
|
|
477
|
-
if (schemaObject.oneOf || schemaObject.anyOf) {
|
|
478
|
-
const schemaWithoutOneOf = { ...schemaObject, oneOf: void 0, anyOf: void 0 };
|
|
479
|
-
const discriminator = this.context.oas.getDiscriminator(schemaObject);
|
|
480
|
-
const union = {
|
|
481
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.union,
|
|
482
|
-
args: (schemaObject.oneOf || schemaObject.anyOf).map((item) => {
|
|
483
|
-
return item && this.parse({ schemaObject: item, name, parentName })[0];
|
|
484
|
-
}).filter(Boolean).filter((item) => !chunkYWMMI3MO_cjs.isKeyword(item, chunkYWMMI3MO_cjs.schemaKeywords.unknown))
|
|
485
|
-
};
|
|
486
|
-
if (discriminator) {
|
|
487
|
-
if (this.context) return [this.#addDiscriminatorToSchema({ schemaObject: schemaWithoutOneOf, schema: union, discriminator }), ...baseItems];
|
|
488
|
-
}
|
|
489
|
-
if (schemaWithoutOneOf.properties) {
|
|
490
|
-
const propertySchemas = this.parse({ schemaObject: schemaWithoutOneOf, name, parentName });
|
|
491
|
-
union.args = [
|
|
492
|
-
...union.args.map((arg) => {
|
|
493
|
-
return {
|
|
494
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.and,
|
|
495
|
-
args: [arg, ...propertySchemas]
|
|
496
|
-
};
|
|
497
|
-
})
|
|
498
|
-
];
|
|
499
|
-
return [union, ...baseItems];
|
|
500
|
-
}
|
|
501
|
-
return [union, ...baseItems];
|
|
502
|
-
}
|
|
503
|
-
if (schemaObject.allOf) {
|
|
504
|
-
const schemaWithoutAllOf = { ...schemaObject, allOf: void 0 };
|
|
505
|
-
const and = {
|
|
506
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.and,
|
|
507
|
-
args: schemaObject.allOf.map((item) => {
|
|
508
|
-
return item && this.parse({ schemaObject: item, name, parentName })[0];
|
|
509
|
-
}).filter(Boolean).filter((item) => !chunkYWMMI3MO_cjs.isKeyword(item, chunkYWMMI3MO_cjs.schemaKeywords.unknown))
|
|
510
|
-
};
|
|
511
|
-
if (schemaWithoutAllOf.required?.length) {
|
|
512
|
-
const allOfItems = schemaObject.allOf;
|
|
513
|
-
const resolvedSchemas = [];
|
|
514
|
-
for (const item of allOfItems) {
|
|
515
|
-
const resolved = oas.isReference(item) ? this.context.oas.get(item.$ref) : item;
|
|
516
|
-
if (resolved) {
|
|
517
|
-
resolvedSchemas.push(resolved);
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
const existingKeys = schemaWithoutAllOf.properties ? new Set(Object.keys(schemaWithoutAllOf.properties)) : null;
|
|
521
|
-
const parsedItems = [];
|
|
522
|
-
for (const key of schemaWithoutAllOf.required) {
|
|
523
|
-
if (existingKeys?.has(key)) {
|
|
524
|
-
continue;
|
|
525
|
-
}
|
|
526
|
-
for (const schema of resolvedSchemas) {
|
|
527
|
-
if (schema.properties?.[key]) {
|
|
528
|
-
parsedItems.push({
|
|
529
|
-
properties: {
|
|
530
|
-
[key]: schema.properties[key]
|
|
531
|
-
},
|
|
532
|
-
required: [key]
|
|
533
|
-
});
|
|
534
|
-
break;
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
for (const item of parsedItems) {
|
|
539
|
-
const parsed = this.parse({ schemaObject: item, name, parentName });
|
|
540
|
-
if (Array.isArray(parsed)) {
|
|
541
|
-
and.args = and.args ? and.args.concat(parsed) : parsed;
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
if (schemaWithoutAllOf.properties) {
|
|
546
|
-
and.args = [...and.args || [], ...this.parse({ schemaObject: schemaWithoutAllOf, name, parentName })];
|
|
547
|
-
}
|
|
548
|
-
return _SchemaGenerator.combineObjects([and, ...baseItems]);
|
|
549
|
-
}
|
|
550
|
-
if (schemaObject.enum) {
|
|
551
|
-
if (options.enumSuffix === "") {
|
|
552
|
-
this.context.pluginManager.logger.emit("info", "EnumSuffix set to an empty string does not work");
|
|
553
|
-
}
|
|
554
|
-
const enumName = utils.getUniqueName(transformers.pascalCase([parentName, name, options.enumSuffix].join(" ")), this.#getUsedEnumNames({ schemaObject, name }));
|
|
555
|
-
const typeName = this.context.pluginManager.resolveName({
|
|
556
|
-
name: enumName,
|
|
557
|
-
pluginKey: this.context.plugin.key,
|
|
558
|
-
type: "type"
|
|
559
|
-
});
|
|
560
|
-
const nullableEnum = schemaObject.enum.includes(null);
|
|
561
|
-
if (nullableEnum) {
|
|
562
|
-
baseItems.push({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.nullable });
|
|
563
|
-
}
|
|
564
|
-
const filteredValues = schemaObject.enum.filter((value) => value !== null);
|
|
565
|
-
const extensionEnums = ["x-enumNames", "x-enum-varnames"].filter((extensionKey) => extensionKey in schemaObject).map((extensionKey) => {
|
|
566
|
-
return [
|
|
567
|
-
{
|
|
568
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.enum,
|
|
569
|
-
args: {
|
|
570
|
-
name,
|
|
571
|
-
typeName,
|
|
572
|
-
asConst: false,
|
|
573
|
-
items: [...new Set(schemaObject[extensionKey])].map((name2, index) => ({
|
|
574
|
-
name: transformers__default.default.stringify(name2),
|
|
575
|
-
value: schemaObject.enum?.[index],
|
|
576
|
-
format: remeda.isNumber(schemaObject.enum?.[index]) ? "number" : "string"
|
|
577
|
-
}))
|
|
578
|
-
}
|
|
579
|
-
},
|
|
580
|
-
...baseItems.filter(
|
|
581
|
-
(item) => item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.min && item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.max && item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.matches
|
|
582
|
-
)
|
|
583
|
-
];
|
|
584
|
-
});
|
|
585
|
-
if (schemaObject.type === "number" || schemaObject.type === "integer") {
|
|
586
|
-
const enumNames = extensionEnums[0]?.find((item) => chunkYWMMI3MO_cjs.isKeyword(item, chunkYWMMI3MO_cjs.schemaKeywords.enum));
|
|
587
|
-
return [
|
|
588
|
-
{
|
|
589
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.enum,
|
|
590
|
-
args: {
|
|
591
|
-
name: enumName,
|
|
592
|
-
typeName,
|
|
593
|
-
asConst: true,
|
|
594
|
-
items: enumNames?.args?.items ? [...new Set(enumNames.args.items)].map(({ name: name2, value }) => ({
|
|
595
|
-
name: name2,
|
|
596
|
-
value,
|
|
597
|
-
format: "number"
|
|
598
|
-
})) : [...new Set(filteredValues)].map((value) => {
|
|
599
|
-
return {
|
|
600
|
-
name: value,
|
|
601
|
-
value,
|
|
602
|
-
format: "number"
|
|
603
|
-
};
|
|
604
|
-
})
|
|
605
|
-
}
|
|
606
|
-
},
|
|
607
|
-
...baseItems.filter((item) => item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.min && item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.max && item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.matches)
|
|
608
|
-
];
|
|
609
|
-
}
|
|
610
|
-
if (schemaObject.type === "boolean") {
|
|
611
|
-
const enumNames = extensionEnums[0]?.find((item) => chunkYWMMI3MO_cjs.isKeyword(item, chunkYWMMI3MO_cjs.schemaKeywords.enum));
|
|
612
|
-
return [
|
|
613
|
-
{
|
|
614
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.enum,
|
|
615
|
-
args: {
|
|
616
|
-
name: enumName,
|
|
617
|
-
typeName,
|
|
618
|
-
asConst: true,
|
|
619
|
-
items: enumNames?.args?.items ? [...new Set(enumNames.args.items)].map(({ name: name2, value }) => ({
|
|
620
|
-
name: name2,
|
|
621
|
-
value,
|
|
622
|
-
format: "boolean"
|
|
623
|
-
})) : [...new Set(filteredValues)].map((value) => {
|
|
624
|
-
return {
|
|
625
|
-
name: value,
|
|
626
|
-
value,
|
|
627
|
-
format: "boolean"
|
|
628
|
-
};
|
|
629
|
-
})
|
|
630
|
-
}
|
|
631
|
-
},
|
|
632
|
-
...baseItems.filter((item) => item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.matches)
|
|
633
|
-
];
|
|
634
|
-
}
|
|
635
|
-
if (extensionEnums.length > 0 && extensionEnums[0]) {
|
|
636
|
-
return extensionEnums[0];
|
|
637
|
-
}
|
|
638
|
-
return [
|
|
639
|
-
{
|
|
640
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.enum,
|
|
641
|
-
args: {
|
|
642
|
-
name: enumName,
|
|
643
|
-
typeName,
|
|
644
|
-
asConst: false,
|
|
645
|
-
items: [...new Set(filteredValues)].map((value) => ({
|
|
646
|
-
name: transformers__default.default.stringify(value),
|
|
647
|
-
value,
|
|
648
|
-
format: remeda.isNumber(value) ? "number" : "string"
|
|
649
|
-
}))
|
|
650
|
-
}
|
|
651
|
-
},
|
|
652
|
-
...baseItems.filter((item) => item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.min && item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.max && item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.matches)
|
|
653
|
-
];
|
|
654
|
-
}
|
|
655
|
-
if ("prefixItems" in schemaObject) {
|
|
656
|
-
const prefixItems = schemaObject.prefixItems;
|
|
657
|
-
const items = "items" in schemaObject ? schemaObject.items : [];
|
|
658
|
-
const min2 = schemaObject.minimum ?? schemaObject.minLength ?? schemaObject.minItems ?? void 0;
|
|
659
|
-
const max2 = schemaObject.maximum ?? schemaObject.maxLength ?? schemaObject.maxItems ?? void 0;
|
|
660
|
-
return [
|
|
661
|
-
{
|
|
662
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.tuple,
|
|
663
|
-
args: {
|
|
664
|
-
min: min2,
|
|
665
|
-
max: max2,
|
|
666
|
-
items: prefixItems.map((item) => {
|
|
667
|
-
return this.parse({ schemaObject: item, name, parentName })[0];
|
|
668
|
-
}).filter(Boolean),
|
|
669
|
-
rest: this.parse({
|
|
670
|
-
schemaObject: items,
|
|
671
|
-
name,
|
|
672
|
-
parentName
|
|
673
|
-
})[0]
|
|
674
|
-
}
|
|
675
|
-
},
|
|
676
|
-
...baseItems.filter((item) => item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.min && item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.max)
|
|
677
|
-
];
|
|
678
|
-
}
|
|
679
|
-
if (version === "3.1" && "const" in schemaObject) {
|
|
680
|
-
if (schemaObject["const"] === null) {
|
|
681
|
-
return [{ keyword: chunkYWMMI3MO_cjs.schemaKeywords.null }];
|
|
682
|
-
}
|
|
683
|
-
if (schemaObject["const"] === void 0) {
|
|
684
|
-
return [{ keyword: chunkYWMMI3MO_cjs.schemaKeywords.undefined }];
|
|
685
|
-
}
|
|
686
|
-
let format = typeof schemaObject["const"];
|
|
687
|
-
if (format !== "number" && format !== "boolean") {
|
|
688
|
-
format = "string";
|
|
689
|
-
}
|
|
690
|
-
return [
|
|
691
|
-
{
|
|
692
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.const,
|
|
693
|
-
args: {
|
|
694
|
-
name: schemaObject["const"],
|
|
695
|
-
format,
|
|
696
|
-
value: schemaObject["const"]
|
|
697
|
-
}
|
|
698
|
-
},
|
|
699
|
-
...baseItems
|
|
700
|
-
];
|
|
701
|
-
}
|
|
702
|
-
if (schemaObject.format) {
|
|
703
|
-
if (schemaObject.type === "integer" && (schemaObject.format === "int32" || schemaObject.format === "int64")) {
|
|
704
|
-
baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.integer });
|
|
705
|
-
return baseItems;
|
|
706
|
-
}
|
|
707
|
-
if (schemaObject.type === "number" && (schemaObject.format === "float" || schemaObject.format === "double")) {
|
|
708
|
-
baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.number });
|
|
709
|
-
return baseItems;
|
|
710
|
-
}
|
|
711
|
-
switch (schemaObject.format) {
|
|
712
|
-
case "binary":
|
|
713
|
-
baseItems.push({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.blob });
|
|
714
|
-
return baseItems;
|
|
715
|
-
case "date-time":
|
|
716
|
-
if (options.dateType) {
|
|
717
|
-
if (options.dateType === "date") {
|
|
718
|
-
baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.date, args: { type: "date" } });
|
|
719
|
-
return baseItems;
|
|
720
|
-
}
|
|
721
|
-
if (options.dateType === "stringOffset") {
|
|
722
|
-
baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.datetime, args: { offset: true } });
|
|
723
|
-
return baseItems;
|
|
724
|
-
}
|
|
725
|
-
if (options.dateType === "stringLocal") {
|
|
726
|
-
baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.datetime, args: { local: true } });
|
|
727
|
-
return baseItems;
|
|
728
|
-
}
|
|
729
|
-
baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.datetime, args: { offset: false } });
|
|
730
|
-
return baseItems;
|
|
731
|
-
}
|
|
732
|
-
break;
|
|
733
|
-
case "date":
|
|
734
|
-
if (options.dateType) {
|
|
735
|
-
if (options.dateType === "date") {
|
|
736
|
-
baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.date, args: { type: "date" } });
|
|
737
|
-
return baseItems;
|
|
738
|
-
}
|
|
739
|
-
baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.date, args: { type: "string" } });
|
|
740
|
-
return baseItems;
|
|
741
|
-
}
|
|
742
|
-
break;
|
|
743
|
-
case "time":
|
|
744
|
-
if (options.dateType) {
|
|
745
|
-
if (options.dateType === "date") {
|
|
746
|
-
baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.time, args: { type: "date" } });
|
|
747
|
-
return baseItems;
|
|
748
|
-
}
|
|
749
|
-
baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.time, args: { type: "string" } });
|
|
750
|
-
return baseItems;
|
|
751
|
-
}
|
|
752
|
-
break;
|
|
753
|
-
case "uuid":
|
|
754
|
-
baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.uuid });
|
|
755
|
-
return baseItems;
|
|
756
|
-
case "email":
|
|
757
|
-
case "idn-email":
|
|
758
|
-
baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.email });
|
|
759
|
-
return baseItems;
|
|
760
|
-
case "uri":
|
|
761
|
-
case "ipv4":
|
|
762
|
-
case "ipv6":
|
|
763
|
-
case "uri-reference":
|
|
764
|
-
case "hostname":
|
|
765
|
-
case "idn-hostname":
|
|
766
|
-
baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.url });
|
|
767
|
-
return baseItems;
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
if (schemaObject.pattern && schemaObject.type === "string") {
|
|
771
|
-
baseItems.unshift({
|
|
772
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.matches,
|
|
773
|
-
args: schemaObject.pattern
|
|
774
|
-
});
|
|
775
|
-
return baseItems;
|
|
776
|
-
}
|
|
777
|
-
if ("items" in schemaObject || schemaObject.type === "array") {
|
|
778
|
-
const min2 = schemaObject.minimum ?? schemaObject.minLength ?? schemaObject.minItems ?? void 0;
|
|
779
|
-
const max2 = schemaObject.maximum ?? schemaObject.maxLength ?? schemaObject.maxItems ?? void 0;
|
|
780
|
-
const items = this.parse({ schemaObject: "items" in schemaObject ? schemaObject.items : [], name, parentName });
|
|
781
|
-
const unique = !!schemaObject.uniqueItems;
|
|
782
|
-
return [
|
|
783
|
-
{
|
|
784
|
-
keyword: chunkYWMMI3MO_cjs.schemaKeywords.array,
|
|
785
|
-
args: {
|
|
786
|
-
items,
|
|
787
|
-
min: min2,
|
|
788
|
-
max: max2,
|
|
789
|
-
unique
|
|
790
|
-
}
|
|
791
|
-
},
|
|
792
|
-
...baseItems.filter((item) => item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.min && item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.max)
|
|
793
|
-
];
|
|
794
|
-
}
|
|
795
|
-
if (schemaObject.properties || schemaObject.additionalProperties) {
|
|
796
|
-
if (oas.isDiscriminator(schemaObject)) {
|
|
797
|
-
const schemaObjectOverriden = Object.keys(schemaObject.properties || {}).reduce((acc, propertyName) => {
|
|
798
|
-
if (acc.properties?.[propertyName] && propertyName === schemaObject.discriminator.propertyName) {
|
|
799
|
-
return {
|
|
800
|
-
...acc,
|
|
801
|
-
properties: {
|
|
802
|
-
...acc.properties,
|
|
803
|
-
[propertyName]: {
|
|
804
|
-
...acc.properties[propertyName] || {},
|
|
805
|
-
enum: schemaObject.discriminator.mapping ? Object.keys(schemaObject.discriminator.mapping) : void 0
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
};
|
|
809
|
-
}
|
|
810
|
-
return acc;
|
|
811
|
-
}, schemaObject || {});
|
|
812
|
-
return [
|
|
813
|
-
...this.#parseProperties({
|
|
814
|
-
schemaObject: schemaObjectOverriden,
|
|
815
|
-
name
|
|
816
|
-
}),
|
|
817
|
-
...baseItems
|
|
818
|
-
];
|
|
819
|
-
}
|
|
820
|
-
return [...this.#parseProperties({ schemaObject, name }), ...baseItems];
|
|
821
|
-
}
|
|
822
|
-
if (schemaObject.type) {
|
|
823
|
-
const type = Array.isArray(schemaObject.type) ? schemaObject.type.filter((item) => item !== "null")[0] : schemaObject.type;
|
|
824
|
-
if (!["boolean", "object", "number", "string", "integer", "null"].includes(type)) {
|
|
825
|
-
this.context.pluginManager.logger.emit("warning", `Schema type '${schemaObject.type}' is not valid for schema ${parentName}.${name}`);
|
|
826
|
-
}
|
|
827
|
-
return [{ keyword: type }, ...baseItems];
|
|
828
|
-
}
|
|
829
|
-
return [{ keyword: emptyType }];
|
|
830
|
-
}
|
|
831
|
-
async build(...generators) {
|
|
832
|
-
const { oas, contentType, include } = this.context;
|
|
833
|
-
const schemas = chunkZVFL3NXX_cjs.getSchemas({ oas, contentType, includes: include });
|
|
834
|
-
const schemaEntries = Object.entries(schemas);
|
|
835
|
-
const generatorLimit = pLimit__default.default(1);
|
|
836
|
-
const schemaLimit = pLimit__default.default(10);
|
|
837
|
-
const writeTasks = generators.map(
|
|
838
|
-
(generator) => generatorLimit(async () => {
|
|
839
|
-
const schemaTasks = schemaEntries.map(
|
|
840
|
-
([name, schemaObject]) => schemaLimit(async () => {
|
|
841
|
-
const options = this.#getOptions({ name });
|
|
842
|
-
const tree = this.parse({ name, schemaObject });
|
|
843
|
-
const result = await generator.schema?.({
|
|
844
|
-
instance: this,
|
|
845
|
-
schema: {
|
|
846
|
-
name,
|
|
847
|
-
value: schemaObject,
|
|
848
|
-
tree
|
|
849
|
-
},
|
|
850
|
-
options: {
|
|
851
|
-
...this.options,
|
|
852
|
-
...options
|
|
853
|
-
}
|
|
854
|
-
});
|
|
855
|
-
return result ?? [];
|
|
856
|
-
})
|
|
857
|
-
);
|
|
858
|
-
const schemaResults = await Promise.all(schemaTasks);
|
|
859
|
-
return schemaResults.flat();
|
|
860
|
-
})
|
|
861
|
-
);
|
|
862
|
-
const nestedResults = await Promise.all(writeTasks);
|
|
863
|
-
return nestedResults.flat();
|
|
864
|
-
}
|
|
865
|
-
};
|
|
866
|
-
|
|
867
|
-
exports.SchemaGenerator = SchemaGenerator;
|
|
868
|
-
//# sourceMappingURL=chunk-NFLZLRQS.cjs.map
|
|
869
|
-
//# sourceMappingURL=chunk-NFLZLRQS.cjs.map
|