@kubb/plugin-faker 3.0.0-alpha.10 → 3.0.0-alpha.12

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/index.cjs CHANGED
@@ -1,38 +1,22 @@
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; }// src/plugin.ts
2
- var _path = require('path'); var _path2 = _interopRequireDefault(_path);
3
- var _core = require('@kubb/core');
4
- var _transformers = require('@kubb/core/transformers'); var _transformers2 = _interopRequireDefault(_transformers);
5
- var _utils = require('@kubb/core/utils');
6
- var _pluginoas = require('@kubb/plugin-oas');
7
- var _plugints = require('@kubb/plugin-ts');
1
+ 'use strict';
8
2
 
9
- // src/OperationGenerator.tsx
3
+ var path = require('path');
4
+ var core = require('@kubb/core');
5
+ var transformers = require('@kubb/core/transformers');
6
+ var utils = require('@kubb/core/utils');
7
+ var pluginOas = require('@kubb/plugin-oas');
8
+ var pluginTs = require('@kubb/plugin-ts');
9
+ var components = require('@kubb/plugin-oas/components');
10
+ var react = require('@kubb/react');
11
+ var hooks = require('@kubb/plugin-oas/hooks');
12
+ var jsxRuntime = require('@kubb/react/jsx-runtime');
10
13
 
11
- var _components = require('@kubb/plugin-oas/components');
12
- var _react = require('@kubb/react');
13
-
14
- // src/components/OperationSchema.tsx
15
-
16
- var _hooks = require('@kubb/plugin-oas/hooks');
17
-
18
-
19
-
20
- // src/SchemaGenerator.tsx
21
-
22
-
23
-
24
-
25
- // src/components/Schema.tsx
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
- // src/parser/index.ts
14
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
34
15
 
16
+ var path__default = /*#__PURE__*/_interopDefault(path);
17
+ var transformers__default = /*#__PURE__*/_interopDefault(transformers);
35
18
 
19
+ // src/plugin.ts
36
20
  var fakerKeywordMapper = {
37
21
  any: () => "undefined",
38
22
  unknown: () => "unknown",
@@ -118,9 +102,9 @@ var fakerKeywordMapper = {
118
102
  ref: () => "ref",
119
103
  matches: (value = "", regexGenerator = "faker") => {
120
104
  if (regexGenerator === "randexp") {
121
- return `${_transformers2.default.toRegExpString(value, "RandExp")}.gen()`;
105
+ return `${transformers__default.default.toRegExpString(value, "RandExp")}.gen()`;
122
106
  }
123
- return `faker.helpers.fromRegExp(${_transformers2.default.toRegExpString(value)})`;
107
+ return `faker.helpers.fromRegExp(${transformers__default.default.toRegExpString(value)})`;
124
108
  },
125
109
  email: () => "faker.internet.email()",
126
110
  firstName: () => "faker.person.firstName()",
@@ -130,7 +114,7 @@ var fakerKeywordMapper = {
130
114
  blob: () => "faker.image.imageUrl() as unknown as Blob",
131
115
  default: void 0,
132
116
  describe: void 0,
133
- const: (value) => _nullishCoalesce(value, () => ( "")),
117
+ const: (value) => value ?? "",
134
118
  max: void 0,
135
119
  min: void 0,
136
120
  nullable: void 0,
@@ -165,27 +149,27 @@ function parse(parent, current, options) {
165
149
  if (!value) {
166
150
  return void 0;
167
151
  }
168
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.union)) {
152
+ if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.union)) {
169
153
  return fakerKeywordMapper.union(current.args.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean));
170
154
  }
171
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.and)) {
155
+ if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.and)) {
172
156
  return fakerKeywordMapper.and(current.args.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean));
173
157
  }
174
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.array)) {
158
+ if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.array)) {
175
159
  return fakerKeywordMapper.array(current.args.items.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean));
176
160
  }
177
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.enum)) {
161
+ if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.enum)) {
178
162
  return fakerKeywordMapper.enum(
179
163
  current.args.items.map((schema) => {
180
164
  if (schema.format === "number") {
181
165
  return schema.name;
182
166
  }
183
- return _transformers2.default.stringify(schema.name);
167
+ return transformers__default.default.stringify(schema.name);
184
168
  })
185
169
  );
186
170
  }
187
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.ref)) {
188
- if (!_optionalChain([current, 'access', _ => _.args, 'optionalAccess', _2 => _2.name])) {
171
+ if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.ref)) {
172
+ if (!current.args?.name) {
189
173
  throw new Error(`Name not defined for keyword ${current.keyword}`);
190
174
  }
191
175
  if (options.withData) {
@@ -193,15 +177,15 @@ function parse(parent, current, options) {
193
177
  }
194
178
  return `${current.args.name}()`;
195
179
  }
196
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.object)) {
197
- const argsObject = Object.entries(_optionalChain([current, 'access', _3 => _3.args, 'optionalAccess', _4 => _4.properties]) || {}).filter((item) => {
180
+ if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.object)) {
181
+ const argsObject = Object.entries(current.args?.properties || {}).filter((item) => {
198
182
  const schema = item[1];
199
183
  return schema && typeof schema.map === "function";
200
184
  }).map(([name, schemas]) => {
201
- const nameSchema = schemas.find((schema) => schema.keyword === _pluginoas.schemaKeywords.name);
202
- const mappedName = _optionalChain([nameSchema, 'optionalAccess', _5 => _5.args]) || name;
203
- if (_optionalChain([options, 'access', _6 => _6.mapper, 'optionalAccess', _7 => _7[mappedName]])) {
204
- return `"${name}": ${_optionalChain([options, 'access', _8 => _8.mapper, 'optionalAccess', _9 => _9[mappedName]])}`;
185
+ const nameSchema = schemas.find((schema) => schema.keyword === pluginOas.schemaKeywords.name);
186
+ const mappedName = nameSchema?.args || name;
187
+ if (options.mapper?.[mappedName]) {
188
+ return `"${name}": ${options.mapper?.[mappedName]}`;
205
189
  }
206
190
  return `"${name}": ${joinItems(
207
191
  schemas.sort(schemaKeywordsorter).map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean)
@@ -209,55 +193,55 @@ function parse(parent, current, options) {
209
193
  }).join(",");
210
194
  return `{${argsObject}}`;
211
195
  }
212
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.tuple)) {
196
+ if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.tuple)) {
213
197
  if (Array.isArray(current.args.items)) {
214
198
  return fakerKeywordMapper.tuple(current.args.items.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean));
215
199
  }
216
200
  return parse(current, current.args.items, { ...options, withData: false });
217
201
  }
218
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.const)) {
202
+ if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.const)) {
219
203
  if (current.args.format === "number" && current.args.name !== void 0) {
220
- return fakerKeywordMapper.const(_optionalChain([current, 'access', _10 => _10.args, 'access', _11 => _11.name, 'optionalAccess', _12 => _12.toString, 'call', _13 => _13()]));
204
+ return fakerKeywordMapper.const(current.args.name?.toString());
221
205
  }
222
- return fakerKeywordMapper.const(_transformers2.default.stringify(current.args.value));
206
+ return fakerKeywordMapper.const(transformers__default.default.stringify(current.args.value));
223
207
  }
224
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.matches) && current.args) {
208
+ if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.matches) && current.args) {
225
209
  return fakerKeywordMapper.matches(current.args, options.regexGenerator);
226
210
  }
227
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.null) || _pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.undefined) || _pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.any)) {
211
+ if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.null) || pluginOas.isKeyword(current, pluginOas.schemaKeywords.undefined) || pluginOas.isKeyword(current, pluginOas.schemaKeywords.any)) {
228
212
  return value() || "";
229
213
  }
230
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.string)) {
214
+ if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.string)) {
231
215
  if (parent) {
232
- const minSchema = _pluginoas.SchemaGenerator.find([parent], _pluginoas.schemaKeywords.min);
233
- const maxSchema = _pluginoas.SchemaGenerator.find([parent], _pluginoas.schemaKeywords.max);
234
- return fakerKeywordMapper.string(_optionalChain([minSchema, 'optionalAccess', _14 => _14.args]), _optionalChain([maxSchema, 'optionalAccess', _15 => _15.args]));
216
+ const minSchema = pluginOas.SchemaGenerator.find([parent], pluginOas.schemaKeywords.min);
217
+ const maxSchema = pluginOas.SchemaGenerator.find([parent], pluginOas.schemaKeywords.max);
218
+ return fakerKeywordMapper.string(minSchema?.args, maxSchema?.args);
235
219
  }
236
220
  return fakerKeywordMapper.string();
237
221
  }
238
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.number)) {
222
+ if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.number)) {
239
223
  if (parent) {
240
- const minSchema = _pluginoas.SchemaGenerator.find([parent], _pluginoas.schemaKeywords.min);
241
- const maxSchema = _pluginoas.SchemaGenerator.find([parent], _pluginoas.schemaKeywords.max);
242
- return fakerKeywordMapper.number(_optionalChain([minSchema, 'optionalAccess', _16 => _16.args]), _optionalChain([maxSchema, 'optionalAccess', _17 => _17.args]));
224
+ const minSchema = pluginOas.SchemaGenerator.find([parent], pluginOas.schemaKeywords.min);
225
+ const maxSchema = pluginOas.SchemaGenerator.find([parent], pluginOas.schemaKeywords.max);
226
+ return fakerKeywordMapper.number(minSchema?.args, maxSchema?.args);
243
227
  }
244
228
  return fakerKeywordMapper.number();
245
229
  }
246
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.integer)) {
230
+ if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.integer)) {
247
231
  if (parent) {
248
- const minSchema = _pluginoas.SchemaGenerator.find([parent], _pluginoas.schemaKeywords.min);
249
- const maxSchema = _pluginoas.SchemaGenerator.find([parent], _pluginoas.schemaKeywords.max);
250
- return fakerKeywordMapper.integer(_optionalChain([minSchema, 'optionalAccess', _18 => _18.args]), _optionalChain([maxSchema, 'optionalAccess', _19 => _19.args]));
232
+ const minSchema = pluginOas.SchemaGenerator.find([parent], pluginOas.schemaKeywords.min);
233
+ const maxSchema = pluginOas.SchemaGenerator.find([parent], pluginOas.schemaKeywords.max);
234
+ return fakerKeywordMapper.integer(minSchema?.args, maxSchema?.args);
251
235
  }
252
236
  return fakerKeywordMapper.integer();
253
237
  }
254
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.datetime)) {
238
+ if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.datetime)) {
255
239
  return fakerKeywordMapper.datetime();
256
240
  }
257
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.date)) {
241
+ if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.date)) {
258
242
  return fakerKeywordMapper.date(current.args.type, options.dateParser);
259
243
  }
260
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.time)) {
244
+ if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.time)) {
261
245
  return fakerKeywordMapper.time(current.args.type, options.dateParser);
262
246
  }
263
247
  if (current.keyword in fakerKeywordMapper && "args" in current) {
@@ -270,18 +254,15 @@ function parse(parent, current, options) {
270
254
  }
271
255
  return void 0;
272
256
  }
273
-
274
- // src/components/Schema.tsx
275
- var _jsxruntime = require('@kubb/react/jsx-runtime');
276
257
  function Schema(props) {
277
258
  const { withData, description } = props;
278
- const { tree, name } = _hooks.useSchema.call(void 0, );
259
+ const { tree, name } = hooks.useSchema();
279
260
  const {
280
261
  pluginManager,
281
262
  plugin: {
282
263
  options: { dateParser, regexGenerator, mapper, seed }
283
264
  }
284
- } = _react.useApp.call(void 0, );
265
+ } = react.useApp();
285
266
  const resolvedName = pluginManager.resolveName({
286
267
  name,
287
268
  pluginKey: [pluginFakerName],
@@ -289,7 +270,7 @@ function Schema(props) {
289
270
  });
290
271
  const typeName = pluginManager.resolveName({
291
272
  name,
292
- pluginKey: [_plugints.pluginTsName],
273
+ pluginKey: [pluginTs.pluginTsName],
293
274
  type: "type"
294
275
  });
295
276
  const fakerText = joinItems(
@@ -312,34 +293,38 @@ function Schema(props) {
312
293
  ]`;
313
294
  }
314
295
  const params = fakerDefaultOverride ? `data: NonNullable<Partial<${typeName}>> = ${fakerDefaultOverride}` : `data?: NonNullable<Partial<${typeName}>>`;
315
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File.Source, { name: resolvedName, isExportable: true, isIndexable: true, children: [
316
- /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
317
- _react.Function,
318
- {
319
- export: true,
320
- name: resolvedName,
321
- JSDoc: { comments: [description ? `@description ${_transformers2.default.jsStringEscape(description)}` : void 0].filter(Boolean) },
322
- params: withData ? params : "",
323
- returnType: typeName ? `NonNullable<${typeName}>` : "",
324
- children: [
325
- seed ? `faker.seed(${JSON.stringify(seed)})` : "",
326
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "br", {}),
327
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Function.Return, { children: fakerTextWithOverride })
328
- ]
329
- }
330
- ),
331
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "br", {})
296
+ const containsFaker = !!fakerTextWithOverride.match(/faker/) || !!seed;
297
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
298
+ containsFaker && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["faker"], path: "@faker-js/faker" }),
299
+ /* @__PURE__ */ jsxRuntime.jsxs(react.File.Source, { name: resolvedName, isExportable: true, isIndexable: true, children: [
300
+ /* @__PURE__ */ jsxRuntime.jsxs(
301
+ react.Function,
302
+ {
303
+ export: true,
304
+ name: resolvedName,
305
+ JSDoc: { comments: [description ? `@description ${transformers__default.default.jsStringEscape(description)}` : void 0].filter(Boolean) },
306
+ params: withData ? params : "",
307
+ returnType: typeName ? `NonNullable<${typeName}>` : "",
308
+ children: [
309
+ seed ? `faker.seed(${JSON.stringify(seed)})` : "",
310
+ /* @__PURE__ */ jsxRuntime.jsx("br", {}),
311
+ /* @__PURE__ */ jsxRuntime.jsx(react.Function.Return, { children: fakerTextWithOverride })
312
+ ]
313
+ }
314
+ ),
315
+ /* @__PURE__ */ jsxRuntime.jsx("br", {})
316
+ ] })
332
317
  ] });
333
318
  }
334
319
  Schema.File = function({}) {
335
- const { pluginManager } = _react.useApp.call(void 0, );
336
- const { tree, schema } = _hooks.useSchema.call(void 0, );
320
+ const { pluginManager } = react.useApp();
321
+ const { tree, schema } = hooks.useSchema();
337
322
  const withData = tree.some(
338
- (schema2) => schema2.keyword === _pluginoas.schemaKeywords.array || schema2.keyword === _pluginoas.schemaKeywords.and || schema2.keyword === _pluginoas.schemaKeywords.object || schema2.keyword === _pluginoas.schemaKeywords.union || schema2.keyword === _pluginoas.schemaKeywords.tuple
323
+ (schema2) => schema2.keyword === pluginOas.schemaKeywords.array || schema2.keyword === pluginOas.schemaKeywords.and || schema2.keyword === pluginOas.schemaKeywords.object || schema2.keyword === pluginOas.schemaKeywords.union || schema2.keyword === pluginOas.schemaKeywords.tuple
339
324
  );
340
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _components.Oas.Schema.File, { output: pluginManager.config.output.path, children: [
341
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema.Imports, {}),
342
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema, { description: _optionalChain([schema, 'optionalAccess', _20 => _20.description]), withData })
325
+ return /* @__PURE__ */ jsxRuntime.jsxs(components.Oas.Schema.File, { output: pluginManager.config.output.path, children: [
326
+ /* @__PURE__ */ jsxRuntime.jsx(Schema.Imports, {}),
327
+ /* @__PURE__ */ jsxRuntime.jsx(Schema, { description: schema?.description, withData })
343
328
  ] });
344
329
  };
345
330
  Schema.Imports = () => {
@@ -348,57 +333,50 @@ Schema.Imports = () => {
348
333
  plugin: {
349
334
  options: { extName, dateParser, regexGenerator }
350
335
  }
351
- } = _react.useApp.call(void 0, );
352
- const { path: root } = _react.useFile.call(void 0, );
353
- const { name, tree, schema } = _hooks.useSchema.call(void 0, );
336
+ } = react.useApp();
337
+ const { path: root } = react.useFile();
338
+ const { name, tree, schema } = hooks.useSchema();
354
339
  const typeName = pluginManager.resolveName({
355
340
  name,
356
- pluginKey: [_plugints.pluginTsName],
341
+ pluginKey: [pluginTs.pluginTsName],
357
342
  type: "type"
358
343
  });
359
344
  const typeFileName = pluginManager.resolveName({
360
345
  name,
361
- pluginKey: [_plugints.pluginTsName],
346
+ pluginKey: [pluginTs.pluginTsName],
362
347
  type: "file"
363
348
  });
364
349
  const typePath = pluginManager.resolvePath({
365
350
  baseName: typeFileName,
366
- pluginKey: [_plugints.pluginTsName]
351
+ pluginKey: [pluginTs.pluginTsName]
367
352
  });
368
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
369
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["faker"], path: "@faker-js/faker" }),
370
- regexGenerator === "randexp" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: "RandExp", path: "randexp" }),
371
- dateParser && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { path: dateParser, name: dateParser }),
372
- typeName && typePath && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { isTypeOnly: true, root, path: typePath, name: [typeName] })
353
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
354
+ regexGenerator === "randexp" && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: "RandExp", path: "randexp" }),
355
+ dateParser && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { path: dateParser, name: dateParser }),
356
+ typeName && typePath && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { isTypeOnly: true, root, path: typePath, name: [typeName] })
373
357
  ] });
374
358
  };
375
-
376
- // src/SchemaGenerator.tsx
377
-
378
- var SchemaGenerator2 = class extends _pluginoas.SchemaGenerator {
359
+ var SchemaGenerator2 = class extends pluginOas.SchemaGenerator {
379
360
  async schema(name, schema, options) {
380
361
  const { oas, pluginManager, plugin, mode, output } = this.context;
381
- const root = _react.createRoot.call(void 0, {
362
+ const root = react.createRoot({
382
363
  logger: pluginManager.logger
383
364
  });
384
365
  const tree = this.parse({ schema, name });
385
366
  root.render(
386
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Schema, { name, value: schema, tree, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema.File, {}) }) }) })
367
+ /* @__PURE__ */ jsxRuntime.jsx(react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsxRuntime.jsx(components.Oas, { oas, children: /* @__PURE__ */ jsxRuntime.jsx(components.Oas.Schema, { name, value: schema, tree, children: /* @__PURE__ */ jsxRuntime.jsx(Schema.File, {}) }) }) })
387
368
  );
388
369
  return root.files;
389
370
  }
390
371
  };
391
-
392
- // src/components/OperationSchema.tsx
393
-
394
372
  function OperationSchema({ description }) {
395
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema, { withData: false, description });
373
+ return /* @__PURE__ */ jsxRuntime.jsx(Schema, { withData: false, description });
396
374
  }
397
375
  OperationSchema.File = function({}) {
398
- const { plugin, pluginManager, mode } = _react.useApp.call(void 0, );
399
- const oas = _hooks.useOas.call(void 0, );
400
- const { getSchemas, getFile } = _hooks.useOperationManager.call(void 0, );
401
- const operation = _hooks.useOperation.call(void 0, );
376
+ const { plugin, pluginManager, mode } = react.useApp();
377
+ const oas = hooks.useOas();
378
+ const { getSchemas, getFile } = hooks.useOperationManager();
379
+ const operation = hooks.useOperation();
402
380
  const file = getFile(operation);
403
381
  const schemas = getSchemas(operation);
404
382
  const generator = new SchemaGenerator2(plugin.options, {
@@ -412,44 +390,40 @@ OperationSchema.File = function({}) {
412
390
  const mapItem = ({ name, schema, description, ...options }, i) => {
413
391
  const typeName = pluginManager.resolveName({
414
392
  name,
415
- pluginKey: [_plugints.pluginTsName],
393
+ pluginKey: [pluginTs.pluginTsName],
416
394
  type: "type"
417
395
  });
418
396
  const typeFileName = pluginManager.resolveName({
419
397
  name: options.operationName || name,
420
- pluginKey: [_plugints.pluginTsName],
398
+ pluginKey: [pluginTs.pluginTsName],
421
399
  type: "file"
422
400
  });
423
401
  const typePath = pluginManager.resolvePath({
424
402
  baseName: typeFileName,
425
- pluginKey: [_plugints.pluginTsName],
426
- options: { tag: _optionalChain([options, 'access', _21 => _21.operation, 'optionalAccess', _22 => _22.getTags, 'call', _23 => _23(), 'access', _24 => _24[0], 'optionalAccess', _25 => _25.name]) }
403
+ pluginKey: [pluginTs.pluginTsName],
404
+ options: { tag: options.operation?.getTags()[0]?.name }
427
405
  });
428
406
  const tree = generator.parse({ schema, name });
429
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _components.Oas.Schema, { name, value: schema, tree, children: [
430
- typeName && typePath && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { isTypeOnly: true, root: file.path, path: typePath, name: [typeName] }),
431
- plugin.options.dateParser && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { path: plugin.options.dateParser, name: plugin.options.dateParser }),
432
- mode === "split" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Schema.Imports, {}),
433
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, OperationSchema, { description })
407
+ return /* @__PURE__ */ jsxRuntime.jsxs(components.Oas.Schema, { name, value: schema, tree, children: [
408
+ typeName && typePath && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { isTypeOnly: true, root: file.path, path: typePath, name: [typeName] }),
409
+ plugin.options.dateParser && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { path: plugin.options.dateParser, name: plugin.options.dateParser }),
410
+ mode === "split" && /* @__PURE__ */ jsxRuntime.jsx(components.Oas.Schema.Imports, {}),
411
+ /* @__PURE__ */ jsxRuntime.jsx(OperationSchema, { description })
434
412
  ] }, i);
435
413
  };
436
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
437
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["faker"], path: "@faker-js/faker" }),
438
- plugin.options.regexGenerator === "randexp" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: "RandExp", path: "randexp" }),
414
+ return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
415
+ plugin.options.regexGenerator === "randexp" && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: "RandExp", path: "randexp" }),
439
416
  items.map(mapItem)
440
417
  ] });
441
418
  };
442
-
443
- // src/OperationGenerator.tsx
444
-
445
- var OperationGenerator = class extends _pluginoas.OperationGenerator {
419
+ var OperationGenerator = class extends pluginOas.OperationGenerator {
446
420
  async operation(operation, options) {
447
421
  const { oas, pluginManager, plugin, mode } = this.context;
448
- const root = _react.createRoot.call(void 0, {
422
+ const root = react.createRoot({
449
423
  logger: pluginManager.logger
450
424
  });
451
425
  root.render(
452
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Operation, { operation, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, OperationSchema.File, {}) }) }) })
426
+ /* @__PURE__ */ jsxRuntime.jsx(react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsxRuntime.jsx(components.Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsxRuntime.jsx(components.Oas.Operation, { operation, children: /* @__PURE__ */ jsxRuntime.jsx(OperationSchema.File, {}) }) }) })
453
427
  );
454
428
  return root.files;
455
429
  }
@@ -457,7 +431,7 @@ var OperationGenerator = class extends _pluginoas.OperationGenerator {
457
431
 
458
432
  // src/plugin.ts
459
433
  var pluginFakerName = "plugin-faker";
460
- var pluginFaker = _core.createPlugin.call(void 0, (options) => {
434
+ var pluginFaker = core.createPlugin((options) => {
461
435
  const {
462
436
  output = { path: "mocks" },
463
437
  seed,
@@ -472,7 +446,7 @@ var pluginFaker = _core.createPlugin.call(void 0, (options) => {
472
446
  dateParser,
473
447
  regexGenerator = "faker"
474
448
  } = options;
475
- const template = _optionalChain([group, 'optionalAccess', _26 => _26.output]) ? group.output : `${output.path}/{{tag}}Controller`;
449
+ const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
476
450
  return {
477
451
  name: pluginFakerName,
478
452
  output: {
@@ -490,34 +464,34 @@ var pluginFaker = _core.createPlugin.call(void 0, (options) => {
490
464
  override,
491
465
  regexGenerator
492
466
  },
493
- pre: [_pluginoas.pluginOasName, _plugints.pluginTsName],
467
+ pre: [pluginOas.pluginOasName, pluginTs.pluginTsName],
494
468
  resolvePath(baseName, pathMode, options2) {
495
- const root = _path2.default.resolve(this.config.root, this.config.output.path);
496
- const mode = _nullishCoalesce(pathMode, () => ( _core.FileManager.getMode(_path2.default.resolve(root, output.path))));
469
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
470
+ const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
497
471
  if (mode === "single") {
498
- return _path2.default.resolve(root, output.path);
472
+ return path__default.default.resolve(root, output.path);
499
473
  }
500
- if (_optionalChain([options2, 'optionalAccess', _27 => _27.tag]) && _optionalChain([group, 'optionalAccess', _28 => _28.type]) === "tag") {
501
- const tag = _transformers.camelCase.call(void 0, options2.tag);
502
- return _path2.default.resolve(root, _utils.renderTemplate.call(void 0, template, { tag }), baseName);
474
+ if (options2?.tag && group?.type === "tag") {
475
+ const tag = transformers.camelCase(options2.tag);
476
+ return path__default.default.resolve(root, utils.renderTemplate(template, { tag }), baseName);
503
477
  }
504
- return _path2.default.resolve(root, output.path, baseName);
478
+ return path__default.default.resolve(root, output.path, baseName);
505
479
  },
506
480
  resolveName(name, type) {
507
- const resolvedName = _transformers.camelCase.call(void 0, name, {
481
+ const resolvedName = transformers.camelCase(name, {
508
482
  prefix: type ? "create" : void 0,
509
483
  isFile: type === "file"
510
484
  });
511
485
  if (type) {
512
- return _optionalChain([transformers3, 'optionalAccess', _29 => _29.name, 'optionalCall', _30 => _30(resolvedName, type)]) || resolvedName;
486
+ return transformers3?.name?.(resolvedName, type) || resolvedName;
513
487
  }
514
488
  return resolvedName;
515
489
  },
516
490
  async buildStart() {
517
- const [swaggerPlugin] = _core.PluginManager.getDependedPlugins(this.plugins, [_pluginoas.pluginOasName]);
491
+ const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
518
492
  const oas = await swaggerPlugin.context.getOas();
519
- const root = _path2.default.resolve(this.config.root, this.config.output.path);
520
- const mode = _core.FileManager.getMode(_path2.default.resolve(root, output.path));
493
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
494
+ const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
521
495
  const schemaGenerator = new SchemaGenerator2(this.plugin.options, {
522
496
  oas,
523
497
  pluginManager: this.pluginManager,
@@ -558,7 +532,7 @@ var pluginFaker = _core.createPlugin.call(void 0, (options) => {
558
532
  };
559
533
  });
560
534
 
561
-
562
-
563
- exports.pluginFaker = pluginFaker; exports.pluginFakerName = pluginFakerName;
535
+ exports.pluginFaker = pluginFaker;
536
+ exports.pluginFakerName = pluginFakerName;
537
+ //# sourceMappingURL=index.cjs.map
564
538
  //# sourceMappingURL=index.cjs.map