@kubb/plugin-oas 3.0.0-alpha.1 → 3.0.0-alpha.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/OperationGenerator-D7rSlflc.d.cts +158 -0
- package/dist/OperationGenerator-vw0Zf-Mi.d.ts +158 -0
- package/dist/{Schema-an5hOrjZ.d.cts → Schema-DxyOIX7q.d.cts} +1 -1
- package/dist/{Schema-DefwBJMc.d.ts → Schema-gHgN14i2.d.ts} +1 -1
- package/dist/{SchemaMapper-CsBQ6eEx.d.cts → SchemaMapper-BM1IGWqD.d.cts} +1 -1
- package/dist/{SchemaMapper-CsBQ6eEx.d.ts → SchemaMapper-BM1IGWqD.d.ts} +1 -1
- package/dist/{chunk-DRLYORTT.cjs → chunk-264TCCJF.cjs} +715 -7
- package/dist/chunk-264TCCJF.cjs.map +1 -0
- package/dist/chunk-7KIEQOVZ.cjs +7 -0
- package/dist/chunk-7KIEQOVZ.cjs.map +1 -0
- package/dist/{chunk-LEACSHKT.js → chunk-FZN3PBEK.js} +713 -5
- package/dist/chunk-FZN3PBEK.js.map +1 -0
- package/dist/chunk-TWKZEVSM.js +7 -0
- package/dist/chunk-TWKZEVSM.js.map +1 -0
- package/dist/components.cjs +4 -9
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +12 -6
- package/dist/components.d.ts +12 -6
- package/dist/components.js +3 -8
- package/dist/components.js.map +1 -1
- package/dist/hooks.cjs +6 -7
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +3 -3
- package/dist/hooks.d.ts +3 -3
- package/dist/hooks.js +1 -2
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +225 -159
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -77
- package/dist/index.d.ts +8 -77
- package/dist/index.js +207 -141
- package/dist/index.js.map +1 -1
- package/dist/{types-Dte3MA6H.d.cts → types-C2RXaY0_.d.cts} +1 -1
- package/dist/{types-Dte3MA6H.d.ts → types-C2RXaY0_.d.ts} +1 -1
- package/dist/utils.d.cts +2 -2
- package/dist/utils.d.ts +2 -2
- package/package.json +9 -9
- package/src/OperationGenerator.ts +62 -31
- package/src/SchemaGenerator.ts +23 -4
- package/src/components/Oas.tsx +8 -2
- package/src/index.ts +3 -9
- package/src/parser.tsx +120 -0
- package/src/plugin.ts +1 -9
- package/dist/OperationGenerator-CeM_9pxW.d.cts +0 -60
- package/dist/OperationGenerator-DhUhvRJE.d.ts +0 -60
- package/dist/chunk-CJXRFYEF.cjs +0 -698
- package/dist/chunk-CJXRFYEF.cjs.map +0 -1
- package/dist/chunk-DRLYORTT.cjs.map +0 -1
- package/dist/chunk-K6KUETAI.js +0 -698
- package/dist/chunk-K6KUETAI.js.map +0 -1
- package/dist/chunk-LEACSHKT.js.map +0 -1
package/dist/chunk-CJXRFYEF.cjs
DELETED
|
@@ -1,698 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _chunkP42X362Ucjs = require('./chunk-P42X362U.cjs');
|
|
9
|
-
|
|
10
|
-
// src/SchemaMapper.ts
|
|
11
|
-
_chunkP42X362Ucjs.init_cjs_shims.call(void 0, );
|
|
12
|
-
var schemaKeywords = {
|
|
13
|
-
any: "any",
|
|
14
|
-
strict: "strict",
|
|
15
|
-
unknown: "unknown",
|
|
16
|
-
number: "number",
|
|
17
|
-
integer: "integer",
|
|
18
|
-
string: "string",
|
|
19
|
-
boolean: "boolean",
|
|
20
|
-
undefined: "undefined",
|
|
21
|
-
nullable: "nullable",
|
|
22
|
-
null: "null",
|
|
23
|
-
nullish: "nullish",
|
|
24
|
-
array: "array",
|
|
25
|
-
tuple: "tuple",
|
|
26
|
-
enum: "enum",
|
|
27
|
-
union: "union",
|
|
28
|
-
datetime: "datetime",
|
|
29
|
-
date: "date",
|
|
30
|
-
email: "email",
|
|
31
|
-
uuid: "uuid",
|
|
32
|
-
url: "url",
|
|
33
|
-
/* intersection */
|
|
34
|
-
default: "default",
|
|
35
|
-
const: "const",
|
|
36
|
-
and: "and",
|
|
37
|
-
describe: "describe",
|
|
38
|
-
min: "min",
|
|
39
|
-
max: "max",
|
|
40
|
-
optional: "optional",
|
|
41
|
-
readOnly: "readOnly",
|
|
42
|
-
// custom ones
|
|
43
|
-
object: "object",
|
|
44
|
-
ref: "ref",
|
|
45
|
-
matches: "matches",
|
|
46
|
-
firstName: "firstName",
|
|
47
|
-
lastName: "lastName",
|
|
48
|
-
password: "password",
|
|
49
|
-
phone: "phone",
|
|
50
|
-
blob: "blob",
|
|
51
|
-
deprecated: "deprecated",
|
|
52
|
-
example: "example",
|
|
53
|
-
schema: "schema",
|
|
54
|
-
catchall: "catchall",
|
|
55
|
-
time: "time",
|
|
56
|
-
name: "name"
|
|
57
|
-
};
|
|
58
|
-
function isKeyword(meta, keyword) {
|
|
59
|
-
return meta.keyword === keyword;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// src/SchemaGenerator.ts
|
|
63
|
-
_chunkP42X362Ucjs.init_cjs_shims.call(void 0, );
|
|
64
|
-
var _core = require('@kubb/core');
|
|
65
|
-
var _transformers = require('@kubb/core/transformers'); var _transformers2 = _interopRequireDefault(_transformers);
|
|
66
|
-
var _utils = require('@kubb/core/utils');
|
|
67
|
-
var _oas = require('@kubb/oas');
|
|
68
|
-
var _remeda = require('remeda');
|
|
69
|
-
var _usedAliasNames, _SchemaGenerator_instances, getUsedEnumNames_fn, getOptions_fn, getUnknownReturn_fn, parseProperties_fn, getRefAlias_fn, getParsedSchemaObject_fn, parseSchemaObject_fn;
|
|
70
|
-
var _SchemaGenerator = class _SchemaGenerator extends _core.Generator {
|
|
71
|
-
constructor() {
|
|
72
|
-
super(...arguments);
|
|
73
|
-
_chunkP42X362Ucjs.__privateAdd.call(void 0, this, _SchemaGenerator_instances);
|
|
74
|
-
// Collect the types of all referenced schemas, so we can export them later
|
|
75
|
-
this.refs = {};
|
|
76
|
-
// Keep track of already used type aliases
|
|
77
|
-
_chunkP42X362Ucjs.__privateAdd.call(void 0, this, _usedAliasNames, {});
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Creates a type node from a given schema.
|
|
81
|
-
* Delegates to getBaseTypeFromSchema internally and
|
|
82
|
-
* optionally adds a union with null.
|
|
83
|
-
*/
|
|
84
|
-
parse(props) {
|
|
85
|
-
const options = _chunkP42X362Ucjs.__privateMethod.call(void 0, this, _SchemaGenerator_instances, getOptions_fn).call(this, props);
|
|
86
|
-
const defaultSchemas = _chunkP42X362Ucjs.__privateMethod.call(void 0, this, _SchemaGenerator_instances, parseSchemaObject_fn).call(this, props);
|
|
87
|
-
const schemas = _optionalChain([options, 'access', _ => _.transformers, 'optionalAccess', _2 => _2.schema, 'optionalCall', _3 => _3(props, defaultSchemas)]) || defaultSchemas || [];
|
|
88
|
-
return _remeda.uniqueWith.call(void 0, schemas, _remeda.isDeepEqual);
|
|
89
|
-
}
|
|
90
|
-
deepSearch(tree, keyword) {
|
|
91
|
-
return _SchemaGenerator.deepSearch(tree, keyword);
|
|
92
|
-
}
|
|
93
|
-
find(tree, keyword) {
|
|
94
|
-
return _SchemaGenerator.find(tree, keyword);
|
|
95
|
-
}
|
|
96
|
-
static deepSearch(tree, keyword) {
|
|
97
|
-
const foundItems = [];
|
|
98
|
-
_optionalChain([tree, 'optionalAccess', _4 => _4.forEach, 'call', _5 => _5((schema) => {
|
|
99
|
-
if (schema.keyword === keyword) {
|
|
100
|
-
foundItems.push(schema);
|
|
101
|
-
}
|
|
102
|
-
if (schema.keyword === schemaKeywords.object) {
|
|
103
|
-
const subItem = schema;
|
|
104
|
-
Object.values(_optionalChain([subItem, 'access', _6 => _6.args, 'optionalAccess', _7 => _7.properties]) || {}).forEach((entrySchema) => {
|
|
105
|
-
foundItems.push(..._SchemaGenerator.deepSearch(entrySchema, keyword));
|
|
106
|
-
});
|
|
107
|
-
Object.values(_optionalChain([subItem, 'access', _8 => _8.args, 'optionalAccess', _9 => _9.additionalProperties]) || {}).forEach((entrySchema) => {
|
|
108
|
-
foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
if (schema.keyword === schemaKeywords.array) {
|
|
112
|
-
const subItem = schema;
|
|
113
|
-
subItem.args.items.forEach((entrySchema) => {
|
|
114
|
-
foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
if (schema.keyword === schemaKeywords.and) {
|
|
118
|
-
const subItem = schema;
|
|
119
|
-
subItem.args.forEach((entrySchema) => {
|
|
120
|
-
foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
if (schema.keyword === schemaKeywords.tuple) {
|
|
124
|
-
const subItem = schema;
|
|
125
|
-
subItem.args.items.forEach((entrySchema) => {
|
|
126
|
-
foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
if (schema.keyword === schemaKeywords.union) {
|
|
130
|
-
const subItem = schema;
|
|
131
|
-
subItem.args.forEach((entrySchema) => {
|
|
132
|
-
foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
})]);
|
|
136
|
-
return foundItems;
|
|
137
|
-
}
|
|
138
|
-
static findInObject(tree, keyword) {
|
|
139
|
-
let foundItem = void 0;
|
|
140
|
-
_optionalChain([tree, 'optionalAccess', _10 => _10.forEach, 'call', _11 => _11((schema) => {
|
|
141
|
-
if (!foundItem && schema.keyword === keyword) {
|
|
142
|
-
foundItem = schema;
|
|
143
|
-
}
|
|
144
|
-
if (schema.keyword === schemaKeywords.object) {
|
|
145
|
-
const subItem = schema;
|
|
146
|
-
Object.values(_optionalChain([subItem, 'access', _12 => _12.args, 'optionalAccess', _13 => _13.properties]) || {}).forEach((entrySchema) => {
|
|
147
|
-
if (!foundItem) {
|
|
148
|
-
foundItem = _SchemaGenerator.find(entrySchema, keyword);
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
Object.values(_optionalChain([subItem, 'access', _14 => _14.args, 'optionalAccess', _15 => _15.additionalProperties]) || {}).forEach((entrySchema) => {
|
|
152
|
-
if (!foundItem) {
|
|
153
|
-
foundItem = _SchemaGenerator.find([entrySchema], keyword);
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
})]);
|
|
158
|
-
return foundItem;
|
|
159
|
-
}
|
|
160
|
-
static find(tree, keyword) {
|
|
161
|
-
let foundItem = void 0;
|
|
162
|
-
_optionalChain([tree, 'optionalAccess', _16 => _16.forEach, 'call', _17 => _17((schema) => {
|
|
163
|
-
if (!foundItem && schema.keyword === keyword) {
|
|
164
|
-
foundItem = schema;
|
|
165
|
-
}
|
|
166
|
-
if (schema.keyword === schemaKeywords.array) {
|
|
167
|
-
const subItem = schema;
|
|
168
|
-
subItem.args.items.forEach((entrySchema) => {
|
|
169
|
-
if (!foundItem) {
|
|
170
|
-
foundItem = _SchemaGenerator.find([entrySchema], keyword);
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
if (schema.keyword === schemaKeywords.and) {
|
|
175
|
-
const subItem = schema;
|
|
176
|
-
subItem.args.forEach((entrySchema) => {
|
|
177
|
-
if (!foundItem) {
|
|
178
|
-
foundItem = _SchemaGenerator.find([entrySchema], keyword);
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
if (schema.keyword === schemaKeywords.tuple) {
|
|
183
|
-
const subItem = schema;
|
|
184
|
-
subItem.args.items.forEach((entrySchema) => {
|
|
185
|
-
if (!foundItem) {
|
|
186
|
-
foundItem = _SchemaGenerator.find([entrySchema], keyword);
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
if (schema.keyword === schemaKeywords.union) {
|
|
191
|
-
const subItem = schema;
|
|
192
|
-
subItem.args.forEach((entrySchema) => {
|
|
193
|
-
if (!foundItem) {
|
|
194
|
-
foundItem = _SchemaGenerator.find([entrySchema], keyword);
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
})]);
|
|
199
|
-
return foundItem;
|
|
200
|
-
}
|
|
201
|
-
async build() {
|
|
202
|
-
const { oas, contentType, include } = this.context;
|
|
203
|
-
const schemas = _chunkP42X362Ucjs.getSchemas.call(void 0, { oas, contentType, includes: include });
|
|
204
|
-
const promises = Object.entries(schemas).reduce((acc, [name, schema]) => {
|
|
205
|
-
const options = _chunkP42X362Ucjs.__privateMethod.call(void 0, this, _SchemaGenerator_instances, getOptions_fn).call(this, { name });
|
|
206
|
-
const promiseOperation = this.schema.call(this, name, schema, {
|
|
207
|
-
...this.options,
|
|
208
|
-
...options
|
|
209
|
-
});
|
|
210
|
-
if (promiseOperation) {
|
|
211
|
-
acc.push(promiseOperation);
|
|
212
|
-
}
|
|
213
|
-
return acc;
|
|
214
|
-
}, []);
|
|
215
|
-
const files = await Promise.all(promises);
|
|
216
|
-
return files.flat().filter(Boolean);
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
_usedAliasNames = new WeakMap();
|
|
220
|
-
_SchemaGenerator_instances = new WeakSet();
|
|
221
|
-
getUsedEnumNames_fn = function(props) {
|
|
222
|
-
const options = _chunkP42X362Ucjs.__privateMethod.call(void 0, this, _SchemaGenerator_instances, getOptions_fn).call(this, props);
|
|
223
|
-
return options.usedEnumNames || {};
|
|
224
|
-
};
|
|
225
|
-
getOptions_fn = function({ name }) {
|
|
226
|
-
const { override = [] } = this.context;
|
|
227
|
-
return {
|
|
228
|
-
...this.options,
|
|
229
|
-
..._optionalChain([override, 'access', _18 => _18.find, 'call', _19 => _19(({ pattern, type }) => {
|
|
230
|
-
if (name && type === "schemaName") {
|
|
231
|
-
return !!name.match(pattern);
|
|
232
|
-
}
|
|
233
|
-
return false;
|
|
234
|
-
}), 'optionalAccess', _20 => _20.options]) || {}
|
|
235
|
-
};
|
|
236
|
-
};
|
|
237
|
-
getUnknownReturn_fn = function(props) {
|
|
238
|
-
const options = _chunkP42X362Ucjs.__privateMethod.call(void 0, this, _SchemaGenerator_instances, getOptions_fn).call(this, props);
|
|
239
|
-
if (options.unknownType === "any") {
|
|
240
|
-
return schemaKeywords.any;
|
|
241
|
-
}
|
|
242
|
-
return schemaKeywords.unknown;
|
|
243
|
-
};
|
|
244
|
-
/**
|
|
245
|
-
* Recursively creates a type literal with the given props.
|
|
246
|
-
*/
|
|
247
|
-
parseProperties_fn = function({ schema, name }) {
|
|
248
|
-
const properties = _optionalChain([schema, 'optionalAccess', _21 => _21.properties]) || {};
|
|
249
|
-
const additionalProperties = _optionalChain([schema, 'optionalAccess', _22 => _22.additionalProperties]);
|
|
250
|
-
const required = _optionalChain([schema, 'optionalAccess', _23 => _23.required]);
|
|
251
|
-
const propertiesSchemas = Object.keys(properties).map((propertyName) => {
|
|
252
|
-
const validationFunctions = [];
|
|
253
|
-
const propertySchema = properties[propertyName];
|
|
254
|
-
const isRequired = Array.isArray(required) ? _optionalChain([required, 'optionalAccess', _24 => _24.includes, 'call', _25 => _25(propertyName)]) : !!required;
|
|
255
|
-
const nullable = _nullishCoalesce(_nullishCoalesce(propertySchema.nullable, () => ( propertySchema["x-nullable"])), () => ( false));
|
|
256
|
-
validationFunctions.push(...this.parse({ schema: propertySchema, name: propertyName, parentName: name }));
|
|
257
|
-
validationFunctions.push({
|
|
258
|
-
keyword: schemaKeywords.name,
|
|
259
|
-
args: propertyName
|
|
260
|
-
});
|
|
261
|
-
if (!isRequired && nullable) {
|
|
262
|
-
validationFunctions.push({ keyword: schemaKeywords.nullish });
|
|
263
|
-
} else if (!isRequired) {
|
|
264
|
-
validationFunctions.push({ keyword: schemaKeywords.optional });
|
|
265
|
-
}
|
|
266
|
-
return {
|
|
267
|
-
[propertyName]: validationFunctions
|
|
268
|
-
};
|
|
269
|
-
}).reduce((acc, curr) => ({ ...acc, ...curr }), {});
|
|
270
|
-
let additionalPropertiesSchemas = [];
|
|
271
|
-
if (additionalProperties) {
|
|
272
|
-
additionalPropertiesSchemas = additionalProperties === true ? [{ keyword: _chunkP42X362Ucjs.__privateMethod.call(void 0, this, _SchemaGenerator_instances, getUnknownReturn_fn).call(this, { schema, name }) }] : this.parse({ schema: additionalProperties, parentName: name });
|
|
273
|
-
}
|
|
274
|
-
return [
|
|
275
|
-
{
|
|
276
|
-
keyword: schemaKeywords.object,
|
|
277
|
-
args: {
|
|
278
|
-
properties: propertiesSchemas,
|
|
279
|
-
additionalProperties: additionalPropertiesSchemas
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
];
|
|
283
|
-
};
|
|
284
|
-
/**
|
|
285
|
-
* Create a type alias for the schema referenced by the given ReferenceObject
|
|
286
|
-
*/
|
|
287
|
-
getRefAlias_fn = function(obj) {
|
|
288
|
-
const { $ref } = obj;
|
|
289
|
-
let ref = this.refs[$ref];
|
|
290
|
-
const originalName = _utils.getUniqueName.call(void 0, $ref.replace(/.+\//, ""), _chunkP42X362Ucjs.__privateGet.call(void 0, this, _usedAliasNames));
|
|
291
|
-
const propertyName = this.context.pluginManager.resolveName({
|
|
292
|
-
name: originalName,
|
|
293
|
-
pluginKey: this.context.plugin.key,
|
|
294
|
-
type: "function"
|
|
295
|
-
});
|
|
296
|
-
if (ref) {
|
|
297
|
-
return [
|
|
298
|
-
{
|
|
299
|
-
keyword: schemaKeywords.ref,
|
|
300
|
-
args: { name: ref.propertyName, path: ref.path }
|
|
301
|
-
}
|
|
302
|
-
];
|
|
303
|
-
}
|
|
304
|
-
const fileName = this.context.pluginManager.resolveName({
|
|
305
|
-
name: originalName,
|
|
306
|
-
pluginKey: this.context.plugin.key,
|
|
307
|
-
type: "file"
|
|
308
|
-
});
|
|
309
|
-
const file = this.context.pluginManager.getFile({
|
|
310
|
-
name: fileName,
|
|
311
|
-
pluginKey: this.context.plugin.key,
|
|
312
|
-
extName: ".ts"
|
|
313
|
-
});
|
|
314
|
-
ref = this.refs[$ref] = {
|
|
315
|
-
propertyName,
|
|
316
|
-
originalName,
|
|
317
|
-
path: file.path
|
|
318
|
-
};
|
|
319
|
-
return [
|
|
320
|
-
{
|
|
321
|
-
keyword: schemaKeywords.ref,
|
|
322
|
-
args: { name: ref.propertyName, path: _optionalChain([ref, 'optionalAccess', _26 => _26.path]), isTypeOnly: false }
|
|
323
|
-
}
|
|
324
|
-
];
|
|
325
|
-
};
|
|
326
|
-
getParsedSchemaObject_fn = function(schema) {
|
|
327
|
-
const parsedSchema = _chunkP42X362Ucjs.getSchemaFactory.call(void 0, this.context.oas)(schema);
|
|
328
|
-
return parsedSchema;
|
|
329
|
-
};
|
|
330
|
-
/**
|
|
331
|
-
* This is the very core of the OpenAPI to TS conversion - it takes a
|
|
332
|
-
* schema and returns the appropriate type.
|
|
333
|
-
*/
|
|
334
|
-
parseSchemaObject_fn = function({ schema: _schema, name, parentName }) {
|
|
335
|
-
const options = _chunkP42X362Ucjs.__privateMethod.call(void 0, this, _SchemaGenerator_instances, getOptions_fn).call(this, { schema: _schema, name });
|
|
336
|
-
const unknownReturn = _chunkP42X362Ucjs.__privateMethod.call(void 0, this, _SchemaGenerator_instances, getUnknownReturn_fn).call(this, { schema: _schema, name });
|
|
337
|
-
const { schema, version } = _chunkP42X362Ucjs.__privateMethod.call(void 0, this, _SchemaGenerator_instances, getParsedSchemaObject_fn).call(this, _schema);
|
|
338
|
-
const resolvedName = this.context.pluginManager.resolveName({
|
|
339
|
-
name: `${parentName || ""} ${name}`,
|
|
340
|
-
pluginKey: this.context.plugin.key,
|
|
341
|
-
type: "type"
|
|
342
|
-
});
|
|
343
|
-
if (!schema) {
|
|
344
|
-
return [{ keyword: unknownReturn }];
|
|
345
|
-
}
|
|
346
|
-
const baseItems = [
|
|
347
|
-
{
|
|
348
|
-
keyword: schemaKeywords.schema,
|
|
349
|
-
args: {
|
|
350
|
-
type: schema.type,
|
|
351
|
-
format: schema.format
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
];
|
|
355
|
-
const min = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(schema.minimum, () => ( schema.minLength)), () => ( schema.minItems)), () => ( void 0));
|
|
356
|
-
const max = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(schema.maximum, () => ( schema.maxLength)), () => ( schema.maxItems)), () => ( void 0));
|
|
357
|
-
const nullable = _nullishCoalesce(_nullishCoalesce(schema.nullable, () => ( schema["x-nullable"])), () => ( false));
|
|
358
|
-
if (schema.default !== void 0 && !Array.isArray(schema.default)) {
|
|
359
|
-
if (typeof schema.default === "string") {
|
|
360
|
-
baseItems.push({
|
|
361
|
-
keyword: schemaKeywords.default,
|
|
362
|
-
args: _transformers2.default.stringify(schema.default)
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
if (typeof schema.default === "boolean") {
|
|
366
|
-
baseItems.push({
|
|
367
|
-
keyword: schemaKeywords.default,
|
|
368
|
-
args: _nullishCoalesce(schema.default, () => ( false))
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
if (schema.description) {
|
|
373
|
-
baseItems.push({
|
|
374
|
-
keyword: schemaKeywords.describe,
|
|
375
|
-
args: schema.description
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
if (schema.pattern) {
|
|
379
|
-
baseItems.unshift({
|
|
380
|
-
keyword: schemaKeywords.matches,
|
|
381
|
-
args: schema.pattern
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
if (max !== void 0) {
|
|
385
|
-
baseItems.unshift({ keyword: schemaKeywords.max, args: max });
|
|
386
|
-
}
|
|
387
|
-
if (min !== void 0) {
|
|
388
|
-
baseItems.unshift({ keyword: schemaKeywords.min, args: min });
|
|
389
|
-
}
|
|
390
|
-
if (nullable) {
|
|
391
|
-
baseItems.push({ keyword: schemaKeywords.nullable });
|
|
392
|
-
}
|
|
393
|
-
if (schema.type && Array.isArray(schema.type)) {
|
|
394
|
-
const [_schema2, nullable2] = schema.type;
|
|
395
|
-
if (nullable2 === "null") {
|
|
396
|
-
baseItems.push({ keyword: schemaKeywords.nullable });
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
if (schema.readOnly) {
|
|
400
|
-
baseItems.push({ keyword: schemaKeywords.readOnly });
|
|
401
|
-
}
|
|
402
|
-
if (_oas.isReference.call(void 0, schema)) {
|
|
403
|
-
return [
|
|
404
|
-
..._chunkP42X362Ucjs.__privateMethod.call(void 0, this, _SchemaGenerator_instances, getRefAlias_fn).call(this, schema),
|
|
405
|
-
nullable && { keyword: schemaKeywords.nullable },
|
|
406
|
-
{
|
|
407
|
-
keyword: schemaKeywords.schema,
|
|
408
|
-
args: {
|
|
409
|
-
type: schema.type,
|
|
410
|
-
format: schema.format
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
].filter(Boolean);
|
|
414
|
-
}
|
|
415
|
-
if (schema.oneOf) {
|
|
416
|
-
const schemaWithoutOneOf = { ...schema, oneOf: void 0 };
|
|
417
|
-
const union = {
|
|
418
|
-
keyword: schemaKeywords.union,
|
|
419
|
-
args: schema.oneOf.map((item) => {
|
|
420
|
-
return item && this.parse({ schema: item, name, parentName })[0];
|
|
421
|
-
}).filter(Boolean).filter((item) => {
|
|
422
|
-
return item && item.keyword !== unknownReturn;
|
|
423
|
-
})
|
|
424
|
-
};
|
|
425
|
-
if (schemaWithoutOneOf.properties) {
|
|
426
|
-
return [...this.parse({ schema: schemaWithoutOneOf, name, parentName }), union, ...baseItems];
|
|
427
|
-
}
|
|
428
|
-
return [union, ...baseItems];
|
|
429
|
-
}
|
|
430
|
-
if (schema.anyOf) {
|
|
431
|
-
const schemaWithoutAnyOf = { ...schema, anyOf: void 0 };
|
|
432
|
-
const union = {
|
|
433
|
-
keyword: schemaKeywords.union,
|
|
434
|
-
args: schema.anyOf.map((item) => {
|
|
435
|
-
return item && this.parse({ schema: item, name, parentName })[0];
|
|
436
|
-
}).filter(Boolean).filter((item) => {
|
|
437
|
-
return item && item.keyword !== unknownReturn;
|
|
438
|
-
}).map((item) => {
|
|
439
|
-
if (isKeyword(item, schemaKeywords.object)) {
|
|
440
|
-
return {
|
|
441
|
-
...item,
|
|
442
|
-
args: {
|
|
443
|
-
...item.args,
|
|
444
|
-
strict: true
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
return item;
|
|
449
|
-
})
|
|
450
|
-
};
|
|
451
|
-
if (schemaWithoutAnyOf.properties) {
|
|
452
|
-
return [...this.parse({ schema: schemaWithoutAnyOf, name, parentName }), union, ...baseItems];
|
|
453
|
-
}
|
|
454
|
-
return [union, ...baseItems];
|
|
455
|
-
}
|
|
456
|
-
if (schema.allOf) {
|
|
457
|
-
const schemaWithoutAllOf = { ...schema, allOf: void 0 };
|
|
458
|
-
const and = {
|
|
459
|
-
keyword: schemaKeywords.and,
|
|
460
|
-
args: schema.allOf.map((item) => {
|
|
461
|
-
return item && this.parse({ schema: item, name, parentName })[0];
|
|
462
|
-
}).filter(Boolean).filter((item) => {
|
|
463
|
-
return item && item.keyword !== unknownReturn;
|
|
464
|
-
})
|
|
465
|
-
};
|
|
466
|
-
if (schemaWithoutAllOf.properties) {
|
|
467
|
-
return [
|
|
468
|
-
{
|
|
469
|
-
...and,
|
|
470
|
-
args: [...and.args || [], ...this.parse({ schema: schemaWithoutAllOf, name, parentName })]
|
|
471
|
-
},
|
|
472
|
-
...baseItems
|
|
473
|
-
];
|
|
474
|
-
}
|
|
475
|
-
return [and, ...baseItems];
|
|
476
|
-
}
|
|
477
|
-
if (schema.enum) {
|
|
478
|
-
const enumName = _utils.getUniqueName.call(void 0, _transformers.pascalCase.call(void 0, [parentName, name, options.enumSuffix].join(" ")), _chunkP42X362Ucjs.__privateMethod.call(void 0, this, _SchemaGenerator_instances, getUsedEnumNames_fn).call(this, { schema, name }));
|
|
479
|
-
const typeName = this.context.pluginManager.resolveName({
|
|
480
|
-
name: enumName,
|
|
481
|
-
pluginKey: this.context.plugin.key,
|
|
482
|
-
type: "type"
|
|
483
|
-
});
|
|
484
|
-
const nullableEnum = schema.enum.includes(null);
|
|
485
|
-
if (nullableEnum) {
|
|
486
|
-
baseItems.push({ keyword: schemaKeywords.nullable });
|
|
487
|
-
}
|
|
488
|
-
const filteredValues = schema.enum.filter((value) => value !== null);
|
|
489
|
-
const extensionEnums = ["x-enumNames", "x-enum-varnames"].filter((extensionKey) => extensionKey in schema).map((extensionKey) => {
|
|
490
|
-
return [
|
|
491
|
-
{
|
|
492
|
-
keyword: schemaKeywords.enum,
|
|
493
|
-
args: {
|
|
494
|
-
name,
|
|
495
|
-
typeName,
|
|
496
|
-
asConst: false,
|
|
497
|
-
items: [...new Set(schema[extensionKey])].map((name2, index) => ({
|
|
498
|
-
name: _transformers2.default.stringify(name2),
|
|
499
|
-
value: _optionalChain([schema, 'access', _27 => _27.enum, 'optionalAccess', _28 => _28[index]]),
|
|
500
|
-
format: _remeda.isNumber.call(void 0, _optionalChain([schema, 'access', _29 => _29.enum, 'optionalAccess', _30 => _30[index]])) ? "number" : "string"
|
|
501
|
-
}))
|
|
502
|
-
}
|
|
503
|
-
},
|
|
504
|
-
...baseItems.filter(
|
|
505
|
-
(item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches
|
|
506
|
-
)
|
|
507
|
-
];
|
|
508
|
-
});
|
|
509
|
-
if (schema.type === "number" || schema.type === "integer") {
|
|
510
|
-
const enumNames = _optionalChain([extensionEnums, 'access', _31 => _31[0], 'optionalAccess', _32 => _32.find, 'call', _33 => _33((item) => isKeyword(item, schemaKeywords.enum))]);
|
|
511
|
-
return [
|
|
512
|
-
{
|
|
513
|
-
keyword: schemaKeywords.enum,
|
|
514
|
-
args: {
|
|
515
|
-
name: enumName,
|
|
516
|
-
typeName,
|
|
517
|
-
asConst: true,
|
|
518
|
-
items: _optionalChain([enumNames, 'optionalAccess', _34 => _34.args, 'optionalAccess', _35 => _35.items]) ? [...new Set(enumNames.args.items)].map(({ name: name2, value }) => ({
|
|
519
|
-
name: name2,
|
|
520
|
-
value,
|
|
521
|
-
format: "number"
|
|
522
|
-
})) : [...new Set(filteredValues)].map((value) => {
|
|
523
|
-
return {
|
|
524
|
-
name: value,
|
|
525
|
-
value,
|
|
526
|
-
format: "number"
|
|
527
|
-
};
|
|
528
|
-
})
|
|
529
|
-
}
|
|
530
|
-
},
|
|
531
|
-
...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches)
|
|
532
|
-
];
|
|
533
|
-
}
|
|
534
|
-
if (extensionEnums.length > 0 && extensionEnums[0]) {
|
|
535
|
-
return extensionEnums[0];
|
|
536
|
-
}
|
|
537
|
-
return [
|
|
538
|
-
{
|
|
539
|
-
keyword: schemaKeywords.enum,
|
|
540
|
-
args: {
|
|
541
|
-
name: enumName,
|
|
542
|
-
typeName,
|
|
543
|
-
asConst: false,
|
|
544
|
-
items: [...new Set(filteredValues)].map((value) => ({
|
|
545
|
-
name: _transformers2.default.stringify(value),
|
|
546
|
-
value,
|
|
547
|
-
format: _remeda.isNumber.call(void 0, value) ? "number" : "string"
|
|
548
|
-
}))
|
|
549
|
-
}
|
|
550
|
-
},
|
|
551
|
-
...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches)
|
|
552
|
-
];
|
|
553
|
-
}
|
|
554
|
-
if ("prefixItems" in schema) {
|
|
555
|
-
const prefixItems = schema.prefixItems;
|
|
556
|
-
const min2 = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(schema.minimum, () => ( schema.minLength)), () => ( schema.minItems)), () => ( void 0));
|
|
557
|
-
const max2 = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(schema.maximum, () => ( schema.maxLength)), () => ( schema.maxItems)), () => ( void 0));
|
|
558
|
-
return [
|
|
559
|
-
{
|
|
560
|
-
keyword: schemaKeywords.tuple,
|
|
561
|
-
args: {
|
|
562
|
-
min: min2,
|
|
563
|
-
max: max2,
|
|
564
|
-
items: prefixItems.map((item) => {
|
|
565
|
-
return this.parse({ schema: item, name, parentName })[0];
|
|
566
|
-
}).filter(Boolean)
|
|
567
|
-
}
|
|
568
|
-
},
|
|
569
|
-
...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max)
|
|
570
|
-
];
|
|
571
|
-
}
|
|
572
|
-
if (version === "3.1" && "const" in schema) {
|
|
573
|
-
if (schema["const"]) {
|
|
574
|
-
return [
|
|
575
|
-
{
|
|
576
|
-
keyword: schemaKeywords.const,
|
|
577
|
-
args: {
|
|
578
|
-
name: schema["const"],
|
|
579
|
-
format: typeof schema["const"] === "number" ? "number" : "string",
|
|
580
|
-
value: schema["const"]
|
|
581
|
-
}
|
|
582
|
-
},
|
|
583
|
-
...baseItems
|
|
584
|
-
];
|
|
585
|
-
}
|
|
586
|
-
return [{ keyword: schemaKeywords.null }];
|
|
587
|
-
}
|
|
588
|
-
if (schema.format) {
|
|
589
|
-
switch (schema.format) {
|
|
590
|
-
case "binary":
|
|
591
|
-
baseItems.push({ keyword: schemaKeywords.blob });
|
|
592
|
-
return baseItems;
|
|
593
|
-
case "date-time":
|
|
594
|
-
if (options.dateType) {
|
|
595
|
-
if (options.dateType === "date") {
|
|
596
|
-
baseItems.unshift({ keyword: schemaKeywords.date, args: { type: "date" } });
|
|
597
|
-
return baseItems;
|
|
598
|
-
}
|
|
599
|
-
if (options.dateType === "stringOffset") {
|
|
600
|
-
baseItems.unshift({ keyword: schemaKeywords.datetime, args: { offset: true } });
|
|
601
|
-
return baseItems;
|
|
602
|
-
}
|
|
603
|
-
if (options.dateType === "stringLocal") {
|
|
604
|
-
baseItems.unshift({ keyword: schemaKeywords.datetime, args: { local: true } });
|
|
605
|
-
return baseItems;
|
|
606
|
-
}
|
|
607
|
-
baseItems.unshift({ keyword: schemaKeywords.datetime, args: { offset: false } });
|
|
608
|
-
return baseItems;
|
|
609
|
-
}
|
|
610
|
-
break;
|
|
611
|
-
case "date":
|
|
612
|
-
if (options.dateType) {
|
|
613
|
-
if (options.dateType === "date") {
|
|
614
|
-
baseItems.unshift({ keyword: schemaKeywords.date, args: { type: "date" } });
|
|
615
|
-
return baseItems;
|
|
616
|
-
}
|
|
617
|
-
baseItems.unshift({ keyword: schemaKeywords.date, args: { type: "string" } });
|
|
618
|
-
return baseItems;
|
|
619
|
-
}
|
|
620
|
-
break;
|
|
621
|
-
case "time":
|
|
622
|
-
if (options.dateType) {
|
|
623
|
-
if (options.dateType === "date") {
|
|
624
|
-
baseItems.unshift({ keyword: schemaKeywords.time, args: { type: "date" } });
|
|
625
|
-
return baseItems;
|
|
626
|
-
}
|
|
627
|
-
baseItems.unshift({ keyword: schemaKeywords.time, args: { type: "string" } });
|
|
628
|
-
return baseItems;
|
|
629
|
-
}
|
|
630
|
-
break;
|
|
631
|
-
case "uuid":
|
|
632
|
-
baseItems.unshift({ keyword: schemaKeywords.uuid });
|
|
633
|
-
break;
|
|
634
|
-
case "email":
|
|
635
|
-
case "idn-email":
|
|
636
|
-
baseItems.unshift({ keyword: schemaKeywords.email });
|
|
637
|
-
break;
|
|
638
|
-
case "uri":
|
|
639
|
-
case "ipv4":
|
|
640
|
-
case "ipv6":
|
|
641
|
-
case "uri-reference":
|
|
642
|
-
case "hostname":
|
|
643
|
-
case "idn-hostname":
|
|
644
|
-
baseItems.unshift({ keyword: schemaKeywords.url });
|
|
645
|
-
break;
|
|
646
|
-
default:
|
|
647
|
-
break;
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
if ("items" in schema || schema.type === "array") {
|
|
651
|
-
const min2 = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(schema.minimum, () => ( schema.minLength)), () => ( schema.minItems)), () => ( void 0));
|
|
652
|
-
const max2 = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(schema.maximum, () => ( schema.maxLength)), () => ( schema.maxItems)), () => ( void 0));
|
|
653
|
-
const items = this.parse({ schema: "items" in schema ? schema.items : [], name, parentName });
|
|
654
|
-
return [
|
|
655
|
-
{
|
|
656
|
-
keyword: schemaKeywords.array,
|
|
657
|
-
args: {
|
|
658
|
-
items,
|
|
659
|
-
min: min2,
|
|
660
|
-
max: max2
|
|
661
|
-
}
|
|
662
|
-
},
|
|
663
|
-
...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max)
|
|
664
|
-
];
|
|
665
|
-
}
|
|
666
|
-
if (schema.properties || schema.additionalProperties) {
|
|
667
|
-
return [..._chunkP42X362Ucjs.__privateMethod.call(void 0, this, _SchemaGenerator_instances, parseProperties_fn).call(this, { schema, name }), ...baseItems];
|
|
668
|
-
}
|
|
669
|
-
if (schema.type) {
|
|
670
|
-
if (Array.isArray(schema.type)) {
|
|
671
|
-
const [type] = schema.type;
|
|
672
|
-
return [
|
|
673
|
-
...this.parse({
|
|
674
|
-
schema: {
|
|
675
|
-
...schema,
|
|
676
|
-
type
|
|
677
|
-
},
|
|
678
|
-
name,
|
|
679
|
-
parentName
|
|
680
|
-
}),
|
|
681
|
-
...baseItems
|
|
682
|
-
].filter(Boolean);
|
|
683
|
-
}
|
|
684
|
-
if (!["boolean", "object", "number", "string", "integer"].includes(schema.type)) {
|
|
685
|
-
this.context.pluginManager.logger.emit("warning", `Schema type '${schema.type}' is not valid for schema ${parentName}.${name}`);
|
|
686
|
-
}
|
|
687
|
-
return [{ keyword: schema.type }, ...baseItems];
|
|
688
|
-
}
|
|
689
|
-
return [{ keyword: unknownReturn }];
|
|
690
|
-
};
|
|
691
|
-
var SchemaGenerator = _SchemaGenerator;
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
exports.schemaKeywords = schemaKeywords; exports.isKeyword = isKeyword; exports.SchemaGenerator = SchemaGenerator;
|
|
698
|
-
//# sourceMappingURL=chunk-CJXRFYEF.cjs.map
|