@kubb/agent 5.0.0-alpha.10 → 5.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.
@@ -14,12 +14,13 @@ import process$1, { version as version$2 } from 'node:process';
14
14
  import { Logtail } from '@logtail/node';
15
15
  import { consola } from 'consola';
16
16
  import { access, rm, readFile as readFile$1, readdir as readdir$1, mkdir, writeFile as writeFile$1 } from 'node:fs/promises';
17
- import { createFabric, createReactFabric, Fabric, File, Function as Function$1, Const, FunctionParams, Type as Type$2, useFabric } from '@kubb/react-fabric';
17
+ import { createFabric, createReactFabric, Fabric, File, Function as Function$1, Const, FunctionParams, Type as Type$1, useFabric } from '@kubb/react-fabric';
18
18
  import { typescriptParser } from '@kubb/react-fabric/parsers';
19
19
  import { fsPlugin } from '@kubb/react-fabric/plugins';
20
20
  import { performance as performance$1 } from 'node:perf_hooks';
21
21
  import { deflateSync } from 'fflate';
22
22
  import { x } from 'tinyexec';
23
+ import { jsx, jsxs, Fragment } from '@kubb/react-fabric/jsx-runtime';
23
24
  import { sortBy, isFunction, mergeDeep, isPlainObject as isPlainObject$1, uniqueWith, isDeepEqual, isNumber, difference } from 'remeda';
24
25
  import * as pkg from 'empathic/package';
25
26
  import { coerce, satisfies } from 'semver';
@@ -33,7 +34,6 @@ import yaml from '@stoplight/yaml';
33
34
  import { isRef } from 'oas/types';
34
35
  import OASNormalize from 'oas-normalize';
35
36
  import swagger2openapi from 'swagger2openapi';
36
- import { jsx, jsxs, Fragment } from '@kubb/react-fabric/jsx-runtime';
37
37
  import { safePrint } from '@kubb/fabric-core/parsers/typescript';
38
38
  import * as fs from 'fs';
39
39
  import * as path$1 from 'path';
@@ -120,6 +120,7 @@ const ENC_CARET_RE = /%5e/gi;
120
120
  const ENC_BACKTICK_RE = /%60/gi;
121
121
  const ENC_PIPE_RE = /%7c/gi;
122
122
  const ENC_SPACE_RE = /%20/gi;
123
+ const ENC_SLASH_RE = /%2f/gi;
123
124
  function encode(text) {
124
125
  return encodeURI("" + text).replace(ENC_PIPE_RE, "|");
125
126
  }
@@ -136,6 +137,9 @@ function decode(text = "") {
136
137
  return "" + text;
137
138
  }
138
139
  }
140
+ function decodePath(text) {
141
+ return decode(text.replace(ENC_SLASH_RE, "%252F"));
142
+ }
139
143
  function decodeQueryKey(text) {
140
144
  return decode(text.replace(PLUS_RE, " "));
141
145
  }
@@ -1468,15 +1472,6 @@ function isEventHandler(input) {
1468
1472
  return hasProp(input, "__is_handler__");
1469
1473
  }
1470
1474
  function toEventHandler(input, _, _route) {
1471
- if (!isEventHandler(input)) {
1472
- console.warn(
1473
- "[h3] Implicit event handler conversion is deprecated. Use `eventHandler()` or `fromNodeMiddleware()` to define event handlers.",
1474
- _route && _route !== "/" ? `
1475
- Route: ${_route}` : "",
1476
- `
1477
- Handler: ${input}`
1478
- );
1479
- }
1480
1475
  return input;
1481
1476
  }
1482
1477
  function defineLazyEventHandler(factory) {
@@ -1555,7 +1550,8 @@ function createAppEventHandler(stack, options) {
1555
1550
  const spacing = options.debug ? 2 : void 0;
1556
1551
  return eventHandler(async (event) => {
1557
1552
  event.node.req.originalUrl = event.node.req.originalUrl || event.node.req.url || "/";
1558
- const _reqPath = event._path || event.node.req.url || "/";
1553
+ const _reqPath = _decodePath(event._path || event.node.req.url || "/");
1554
+ event._path = _reqPath;
1559
1555
  let _layerPath;
1560
1556
  if (options.onRequest) {
1561
1557
  await options.onRequest(event);
@@ -1705,6 +1701,13 @@ function cachedFn(fn) {
1705
1701
  return cache;
1706
1702
  };
1707
1703
  }
1704
+ function _decodePath(url) {
1705
+ const qIndex = url.indexOf("?");
1706
+ const path = qIndex === -1 ? url : url.slice(0, qIndex);
1707
+ const query = qIndex === -1 ? "" : url.slice(qIndex);
1708
+ const decodedPath = path.includes("%25") ? decodePath(path.replace(/%25/g, "%2525")) : decodePath(path);
1709
+ return decodedPath + query;
1710
+ }
1708
1711
  function websocketOptions(evResolver, appOptions) {
1709
1712
  return {
1710
1713
  ...appOptions.websocket,
@@ -1744,7 +1747,7 @@ function createRouter(opts = {}) {
1744
1747
  addRoute(path, handler, m);
1745
1748
  }
1746
1749
  } else {
1747
- route.handlers[method] = toEventHandler(handler, void 0, path);
1750
+ route.handlers[method] = toEventHandler(handler);
1748
1751
  }
1749
1752
  return router;
1750
1753
  };
@@ -4710,7 +4713,7 @@ function toCamelOrPascal$f(text, pascal) {
4710
4713
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
4711
4714
  }
4712
4715
  function applyToFileParts$f(text, transformPart) {
4713
- const parts = text.split(".");
4716
+ const parts = text.split(/\.(?=[a-zA-Z])/);
4714
4717
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
4715
4718
  }
4716
4719
  function camelCase$f(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -4791,13 +4794,14 @@ function createLimit(concurrency) {
4791
4794
  };
4792
4795
  }
4793
4796
  function getChildren(node, recurse) {
4797
+ var _a;
4794
4798
  switch (node.kind) {
4795
4799
  case "Root":
4796
4800
  return [...node.schemas, ...node.operations];
4797
4801
  case "Operation":
4798
4802
  return [
4799
4803
  ...node.parameters,
4800
- ...node.requestBody ? [node.requestBody] : [],
4804
+ ...((_a = node.requestBody) == null ? void 0 : _a.schema) ? [node.requestBody.schema] : [],
4801
4805
  ...node.responses
4802
4806
  ];
4803
4807
  case "Schema": {
@@ -4806,6 +4810,7 @@ function getChildren(node, recurse) {
4806
4810
  if ("properties" in node && node.properties.length > 0) children.push(...node.properties);
4807
4811
  if ("items" in node && node.items) children.push(...node.items);
4808
4812
  if ("members" in node && node.members) children.push(...node.members);
4813
+ if ("additionalProperties" in node && node.additionalProperties && node.additionalProperties !== true) children.push(node.additionalProperties);
4809
4814
  return children;
4810
4815
  }
4811
4816
  case "Property":
@@ -4866,6 +4871,79 @@ async function _walk(node, visitor, recurse, limit) {
4866
4871
  const children = getChildren(node, recurse);
4867
4872
  await Promise.all(children.map((child) => _walk(child, visitor, recurse, limit)));
4868
4873
  }
4874
+ function transform(node, visitor, options = {}) {
4875
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
4876
+ const recurse = ((_a = options.depth) != null ? _a : visitorDepths.deep) === visitorDepths.deep;
4877
+ switch (node.kind) {
4878
+ case "Root": {
4879
+ let root = node;
4880
+ const replaced = (_b = visitor.root) == null ? void 0 : _b.call(visitor, root);
4881
+ if (replaced) root = replaced;
4882
+ return {
4883
+ ...root,
4884
+ schemas: root.schemas.map((s) => transform(s, visitor, options)),
4885
+ operations: root.operations.map((op) => transform(op, visitor, options))
4886
+ };
4887
+ }
4888
+ case "Operation": {
4889
+ let op = node;
4890
+ const replaced = (_c = visitor.operation) == null ? void 0 : _c.call(visitor, op);
4891
+ if (replaced) op = replaced;
4892
+ return {
4893
+ ...op,
4894
+ parameters: op.parameters.map((p) => transform(p, visitor, options)),
4895
+ requestBody: op.requestBody ? {
4896
+ ...op.requestBody,
4897
+ schema: op.requestBody.schema ? transform(op.requestBody.schema, visitor, options) : void 0
4898
+ } : void 0,
4899
+ responses: op.responses.map((r) => transform(r, visitor, options))
4900
+ };
4901
+ }
4902
+ case "Schema": {
4903
+ let schema = node;
4904
+ const replaced = (_d = visitor.schema) == null ? void 0 : _d.call(visitor, schema);
4905
+ if (replaced) schema = replaced;
4906
+ return {
4907
+ ...schema,
4908
+ ..."properties" in schema && recurse ? { properties: schema.properties.map((p) => transform(p, visitor, options)) } : {},
4909
+ ..."items" in schema && recurse ? { items: (_e = schema.items) == null ? void 0 : _e.map((i) => transform(i, visitor, options)) } : {},
4910
+ ..."members" in schema && recurse ? { members: (_f = schema.members) == null ? void 0 : _f.map((m) => transform(m, visitor, options)) } : {},
4911
+ ..."additionalProperties" in schema && recurse && schema.additionalProperties && schema.additionalProperties !== true ? { additionalProperties: transform(schema.additionalProperties, visitor, options) } : {}
4912
+ };
4913
+ }
4914
+ case "Property": {
4915
+ let prop = node;
4916
+ const replaced = (_g = visitor.property) == null ? void 0 : _g.call(visitor, prop);
4917
+ if (replaced) prop = replaced;
4918
+ return {
4919
+ ...prop,
4920
+ schema: transform(prop.schema, visitor, options)
4921
+ };
4922
+ }
4923
+ case "Parameter": {
4924
+ let param = node;
4925
+ const replaced = (_h = visitor.parameter) == null ? void 0 : _h.call(visitor, param);
4926
+ if (replaced) param = replaced;
4927
+ return {
4928
+ ...param,
4929
+ schema: transform(param.schema, visitor, options)
4930
+ };
4931
+ }
4932
+ case "Response": {
4933
+ let response = node;
4934
+ const replaced = (_i = visitor.response) == null ? void 0 : _i.call(visitor, response);
4935
+ if (replaced) response = replaced;
4936
+ return {
4937
+ ...response,
4938
+ schema: transform(response.schema, visitor, options)
4939
+ };
4940
+ }
4941
+ case "FunctionParameter":
4942
+ case "ObjectBindingParameter":
4943
+ case "FunctionParameters":
4944
+ return node;
4945
+ }
4946
+ }
4869
4947
  function collect(node, visitor, options = {}) {
4870
4948
  var _a, _b, _c, _d, _e, _f, _g;
4871
4949
  const recurse = ((_a = options.depth) != null ? _a : visitorDepths.deep) === visitorDepths.deep;
@@ -4980,7 +5058,7 @@ function toCamelOrPascal$e(text, pascal) {
4980
5058
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
4981
5059
  }
4982
5060
  function applyToFileParts$e(text, transformPart) {
4983
- const parts = text.split(".");
5061
+ const parts = text.split(/\.(?=[a-zA-Z])/);
4984
5062
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
4985
5063
  }
4986
5064
  function camelCase$e(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -5951,7 +6029,7 @@ const fsStorage = createStorage(() => ({
5951
6029
  await clean(resolve(base));
5952
6030
  }
5953
6031
  }));
5954
- var version$1 = "5.0.0-alpha.10";
6032
+ var version$1 = "5.0.0-alpha.12";
5955
6033
  function getDiagnosticInfo() {
5956
6034
  return {
5957
6035
  nodeVersion: version$2,
@@ -6228,12 +6306,16 @@ function buildBarrelExports({ barrelFiles, rootDir, existingExports, config, dri
6228
6306
  function inputToAdapterSource(config) {
6229
6307
  if (Array.isArray(config.input)) return {
6230
6308
  type: "paths",
6231
- paths: config.input.map((i) => resolve(config.root, i.path))
6309
+ paths: config.input.map((i) => new URLPath$a(i.path).isURL ? i.path : resolve(config.root, i.path))
6232
6310
  };
6233
6311
  if ("data" in config.input) return {
6234
6312
  type: "data",
6235
6313
  data: config.input.data
6236
6314
  };
6315
+ if (new URLPath$a(config.input.path).isURL) return {
6316
+ type: "path",
6317
+ path: config.input.path
6318
+ };
6237
6319
  return {
6238
6320
  type: "path",
6239
6321
  path: resolve(config.root, config.input.path)
@@ -6330,6 +6412,46 @@ function defineResolver(build2) {
6330
6412
  ...build2()
6331
6413
  };
6332
6414
  }
6415
+ async function renderOperation$1(node, options) {
6416
+ const { config, fabric, plugin, Component, adapter, driver, mode } = options;
6417
+ if (!Component) return;
6418
+ const fabricChild = createReactFabric();
6419
+ await fabricChild.render(/* @__PURE__ */ jsx(Fabric, {
6420
+ meta: {
6421
+ plugin,
6422
+ driver,
6423
+ mode
6424
+ },
6425
+ children: /* @__PURE__ */ jsx(Component, {
6426
+ config,
6427
+ adapter,
6428
+ node,
6429
+ options: options.options
6430
+ })
6431
+ }));
6432
+ fabric.context.fileManager.upsert(...fabricChild.files);
6433
+ fabricChild.unmount();
6434
+ }
6435
+ async function renderSchema$1(node, options) {
6436
+ const { config, fabric, plugin, Component, adapter, driver, mode } = options;
6437
+ if (!Component) return;
6438
+ const fabricChild = createReactFabric();
6439
+ await fabricChild.render(/* @__PURE__ */ jsx(Fabric, {
6440
+ meta: {
6441
+ plugin,
6442
+ driver,
6443
+ mode
6444
+ },
6445
+ children: /* @__PURE__ */ jsx(Component, {
6446
+ config,
6447
+ adapter,
6448
+ node,
6449
+ options: options.options
6450
+ })
6451
+ }));
6452
+ fabric.context.fileManager.upsert(...fabricChild.files);
6453
+ fabricChild.unmount();
6454
+ }
6333
6455
  const memoryStorage = createStorage(() => {
6334
6456
  const store = /* @__PURE__ */ new Map();
6335
6457
  return {
@@ -6694,7 +6816,7 @@ function satisfiesDependency(dependency, version2, cwd) {
6694
6816
  return satisfies(semVer, version2);
6695
6817
  }
6696
6818
 
6697
- var version = "5.0.0-alpha.10";
6819
+ var version = "5.0.0-alpha.12";
6698
6820
 
6699
6821
  function isCommandMessage(msg) {
6700
6822
  return msg.type === "command";
@@ -6899,7 +7021,7 @@ function toCamelOrPascal$d(text, pascal) {
6899
7021
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
6900
7022
  }
6901
7023
  function applyToFileParts$d(text, transformPart) {
6902
- const parts = text.split(".");
7024
+ const parts = text.split(/\.(?=[a-zA-Z])/);
6903
7025
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
6904
7026
  }
6905
7027
  function camelCase$d(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -7049,7 +7171,7 @@ function toCamelOrPascal$c(text, pascal) {
7049
7171
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
7050
7172
  }
7051
7173
  function applyToFileParts$c(text, transformPart) {
7052
- const parts = text.split(".");
7174
+ const parts = text.split(/\.(?=[a-zA-Z])/);
7053
7175
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
7054
7176
  }
7055
7177
  function camelCase$c(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -7219,8 +7341,8 @@ function getDefaultValue(schema) {
7219
7341
  }
7220
7342
  if (schema.type === "object" || schema.properties) return "{}";
7221
7343
  }
7222
- async function parse$3(pathOrApi, { oasClass = Oas, canBundle = true, enablePaths = true } = {}) {
7223
- if (typeof pathOrApi === "string" && canBundle) return parse$3((await bundle({
7344
+ async function parse$2(pathOrApi, { oasClass = Oas, canBundle = true, enablePaths = true } = {}) {
7345
+ if (typeof pathOrApi === "string" && canBundle) return parse$2((await bundle({
7224
7346
  ref: pathOrApi,
7225
7347
  config: await loadConfig$1(),
7226
7348
  base: pathOrApi
@@ -7240,13 +7362,13 @@ async function parse$3(pathOrApi, { oasClass = Oas, canBundle = true, enablePath
7240
7362
  return new oasClass(document);
7241
7363
  }
7242
7364
  async function merge(pathOrApi, { oasClass = Oas } = {}) {
7243
- const instances = await Promise.all(pathOrApi.map((p) => parse$3(p, {
7365
+ const instances = await Promise.all(pathOrApi.map((p) => parse$2(p, {
7244
7366
  oasClass,
7245
7367
  enablePaths: false,
7246
7368
  canBundle: false
7247
7369
  })));
7248
7370
  if (instances.length === 0) throw new Error("No OAS instances provided for merging.");
7249
- return parse$3(instances.reduce((acc, current) => {
7371
+ return parse$2(instances.reduce((acc, current) => {
7250
7372
  return mergeDeep(acc, current.document);
7251
7373
  }, {
7252
7374
  openapi: "3.0.0",
@@ -7260,16 +7382,16 @@ async function merge(pathOrApi, { oasClass = Oas } = {}) {
7260
7382
  }
7261
7383
  function parseFromConfig(config, oasClass = Oas) {
7262
7384
  if ("data" in config.input) {
7263
- if (typeof config.input.data === "object") return parse$3(structuredClone(config.input.data), { oasClass });
7385
+ if (typeof config.input.data === "object") return parse$2(structuredClone(config.input.data), { oasClass });
7264
7386
  try {
7265
- return parse$3(yaml.parse(config.input.data), { oasClass });
7387
+ return parse$2(yaml.parse(config.input.data), { oasClass });
7266
7388
  } catch (_e) {
7267
- return parse$3(config.input.data, { oasClass });
7389
+ return parse$2(config.input.data, { oasClass });
7268
7390
  }
7269
7391
  }
7270
7392
  if (Array.isArray(config.input)) return merge(config.input.map((input) => path$2.resolve(config.root, input.path)), { oasClass });
7271
- if (new URLPath$9(config.input.path).isURL) return parse$3(config.input.path, { oasClass });
7272
- return parse$3(path$2.resolve(config.root, config.input.path), { oasClass });
7393
+ if (new URLPath$9(config.input.path).isURL) return parse$2(config.input.path, { oasClass });
7394
+ return parse$2(path$2.resolve(config.root, config.input.path), { oasClass });
7273
7395
  }
7274
7396
  function flattenSchema(schema) {
7275
7397
  if (!(schema == null ? void 0 : schema.allOf) || schema.allOf.length === 0) return schema || null;
@@ -7895,131 +8017,69 @@ function getSchemaFactory(oas) {
7895
8017
  };
7896
8018
  };
7897
8019
  }
7898
- function isBuildOperationsV1Options(options) {
7899
- var _a2;
7900
- return ((_a2 = options.version) != null ? _a2 : "1") === "1";
7901
- }
7902
- async function buildOperations(operationsOrNodes, options) {
7903
- const { config, fabric, plugin } = options;
7904
- if (!options.Component) return;
8020
+ async function renderOperations(operations, options) {
8021
+ const { config, fabric, plugin, Component, generator } = options;
8022
+ if (!Component) return;
8023
+ const { driver, oas, mode } = generator.context;
7905
8024
  const fabricChild = createReactFabric();
7906
- if (isBuildOperationsV1Options(options)) {
7907
- const { generator, Component } = options;
7908
- const { driver, oas, mode } = generator.context;
7909
- await fabricChild.render(/* @__PURE__ */ jsx(Fabric, {
7910
- meta: {
7911
- driver,
7912
- plugin,
7913
- mode,
7914
- oas
7915
- },
7916
- children: /* @__PURE__ */ jsx(Component, {
7917
- config,
7918
- operations: operationsOrNodes,
7919
- generator,
7920
- plugin
7921
- })
7922
- }));
7923
- } else {
7924
- const { Component, adapter } = options;
7925
- await fabricChild.render(/* @__PURE__ */ jsx(Fabric, {
7926
- meta: { plugin },
7927
- children: /* @__PURE__ */ jsx(Component, {
7928
- config,
7929
- adapter,
7930
- nodes: operationsOrNodes,
7931
- options: options.options
7932
- })
7933
- }));
7934
- }
8025
+ await fabricChild.render(/* @__PURE__ */ jsx(Fabric, {
8026
+ meta: {
8027
+ driver,
8028
+ plugin,
8029
+ mode,
8030
+ oas
8031
+ },
8032
+ children: /* @__PURE__ */ jsx(Component, {
8033
+ config,
8034
+ operations,
8035
+ generator,
8036
+ plugin
8037
+ })
8038
+ }));
7935
8039
  fabric.context.fileManager.upsert(...fabricChild.files);
7936
8040
  fabricChild.unmount();
7937
8041
  }
7938
- function isBuildOperationV1Options(options) {
7939
- var _a2;
7940
- return ((_a2 = options.version) != null ? _a2 : "1") === "1";
7941
- }
7942
- async function buildOperation(operationOrNode, options) {
7943
- const { config, fabric, plugin } = options;
7944
- if (!options.Component) return;
8042
+ async function renderOperation(operation, options) {
8043
+ const { config, fabric, plugin, Component, generator } = options;
8044
+ if (!Component) return;
8045
+ const { driver, oas, mode } = generator.context;
7945
8046
  const fabricChild = createReactFabric();
7946
- if (isBuildOperationV1Options(options)) {
7947
- const { generator, Component } = options;
7948
- const { driver, oas, mode } = generator.context;
7949
- await fabricChild.render(/* @__PURE__ */ jsx(Fabric, {
7950
- meta: {
7951
- driver,
7952
- plugin,
7953
- mode,
7954
- oas
7955
- },
7956
- children: /* @__PURE__ */ jsx(Component, {
7957
- config,
7958
- operation: operationOrNode,
7959
- plugin,
7960
- generator
7961
- })
7962
- }));
7963
- } else {
7964
- const { Component, adapter, driver, mode } = options;
7965
- await fabricChild.render(/* @__PURE__ */ jsx(Fabric, {
7966
- meta: {
7967
- plugin,
7968
- driver,
7969
- mode
7970
- },
7971
- children: /* @__PURE__ */ jsx(Component, {
7972
- config,
7973
- adapter,
7974
- node: operationOrNode,
7975
- options: options.options
7976
- })
7977
- }));
7978
- }
8047
+ await fabricChild.render(/* @__PURE__ */ jsx(Fabric, {
8048
+ meta: {
8049
+ driver,
8050
+ plugin,
8051
+ mode,
8052
+ oas
8053
+ },
8054
+ children: /* @__PURE__ */ jsx(Component, {
8055
+ config,
8056
+ operation,
8057
+ plugin,
8058
+ generator
8059
+ })
8060
+ }));
7979
8061
  fabric.context.fileManager.upsert(...fabricChild.files);
7980
8062
  fabricChild.unmount();
7981
8063
  }
7982
- function isBuildSchemaV1Options(options) {
7983
- var _a2;
7984
- return ((_a2 = options.version) != null ? _a2 : "1") === "1";
7985
- }
7986
- async function buildSchema(schema, options) {
7987
- const { config, fabric, plugin } = options;
7988
- if (!options.Component) return;
8064
+ async function renderSchema(schema, options) {
8065
+ const { config, fabric, plugin, Component, generator } = options;
8066
+ if (!Component) return;
8067
+ const { driver, oas, mode } = generator.context;
7989
8068
  const fabricChild = createReactFabric();
7990
- if (isBuildSchemaV1Options(options)) {
7991
- const { generator, Component } = options;
7992
- const { driver, oas, mode } = generator.context;
7993
- await fabricChild.render(/* @__PURE__ */ jsx(Fabric, {
7994
- meta: {
7995
- driver,
7996
- plugin,
7997
- mode,
7998
- oas
7999
- },
8000
- children: /* @__PURE__ */ jsx(Component, {
8001
- config,
8002
- schema,
8003
- plugin,
8004
- generator
8005
- })
8006
- }));
8007
- } else {
8008
- const { Component, adapter, driver, mode } = options;
8009
- await fabricChild.render(/* @__PURE__ */ jsx(Fabric, {
8010
- meta: {
8011
- plugin,
8012
- driver,
8013
- mode
8014
- },
8015
- children: /* @__PURE__ */ jsx(Component, {
8016
- config,
8017
- adapter,
8018
- node: schema,
8019
- options: options.options
8020
- })
8021
- }));
8022
- }
8069
+ await fabricChild.render(/* @__PURE__ */ jsx(Fabric, {
8070
+ meta: {
8071
+ driver,
8072
+ plugin,
8073
+ mode,
8074
+ oas
8075
+ },
8076
+ children: /* @__PURE__ */ jsx(Component, {
8077
+ config,
8078
+ schema,
8079
+ plugin,
8080
+ generator
8081
+ })
8082
+ }));
8023
8083
  fabric.context.fileManager.upsert(...fabricChild.files);
8024
8084
  fabricChild.unmount();
8025
8085
  }
@@ -8958,7 +9018,7 @@ parseSchemaObject_fn = function({ schema: _schemaObject, name, parentName, rootN
8958
9018
  rootName: name
8959
9019
  });
8960
9020
  if (v1Generator.type === "react") {
8961
- await buildSchema({
9021
+ await renderSchema({
8962
9022
  name,
8963
9023
  value: schemaObject,
8964
9024
  tree
@@ -9248,7 +9308,7 @@ function toCamelOrPascal$b(text, pascal) {
9248
9308
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
9249
9309
  }
9250
9310
  function applyToFileParts$b(text, transformPart) {
9251
- const parts = text.split(".");
9311
+ const parts = text.split(/\.(?=[a-zA-Z])/);
9252
9312
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
9253
9313
  }
9254
9314
  function camelCase$b(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -10058,7 +10118,7 @@ var OperationGenerator = (_a$7 = class {
10058
10118
  var _a4, _b;
10059
10119
  const options = this.getOptions(operation, method);
10060
10120
  if (v1Generator.type === "react") {
10061
- await buildOperation(operation, {
10121
+ await renderOperation(operation, {
10062
10122
  config: this.context.driver.config,
10063
10123
  fabric: this.context.fabric,
10064
10124
  Component: v1Generator.Operation,
@@ -10088,7 +10148,7 @@ var OperationGenerator = (_a$7 = class {
10088
10148
  }));
10089
10149
  const opResultsFlat = (await Promise.all(operationTasks)).flat();
10090
10150
  if (v1Generator.type === "react") {
10091
- await buildOperations(operations.map((op) => op.operation), {
10151
+ await renderOperations(operations.map((op) => op.operation), {
10092
10152
  fabric: this.context.fabric,
10093
10153
  config: this.context.driver.config,
10094
10154
  Component: v1Generator.Operations,
@@ -10310,7 +10370,7 @@ function Operations({ name, operations }) {
10310
10370
  name: "OperationSchema",
10311
10371
  isExportable: true,
10312
10372
  isIndexable: true,
10313
- children: /* @__PURE__ */ jsx(Type$2, {
10373
+ children: /* @__PURE__ */ jsx(Type$1, {
10314
10374
  name: "OperationSchema",
10315
10375
  export: true,
10316
10376
  children: `{
@@ -10334,7 +10394,7 @@ function Operations({ name, operations }) {
10334
10394
  name: "OperationsMap",
10335
10395
  isExportable: true,
10336
10396
  isIndexable: true,
10337
- children: /* @__PURE__ */ jsx(Type$2, {
10397
+ children: /* @__PURE__ */ jsx(Type$1, {
10338
10398
  name: "OperationsMap",
10339
10399
  export: true,
10340
10400
  children: "Record<string, OperationSchema>"
@@ -10645,11 +10705,26 @@ const miniModifierKeywords = [
10645
10705
  function extractMiniModifiers(schemas) {
10646
10706
  const defaultSchema = schemas.find((item) => isKeyword(item, schemaKeywords.default));
10647
10707
  const isBigInt = schemas.some((item) => isKeyword(item, schemaKeywords.bigint));
10708
+ let defaultValue = defaultSchema == null ? void 0 : defaultSchema.args;
10709
+ if (defaultValue !== void 0) {
10710
+ const enumSchema = schemas.find((it) => isKeyword(it, schemaKeywords.enum));
10711
+ if (enumSchema) {
10712
+ let rawDefault = defaultValue;
10713
+ if (typeof rawDefault === "string") try {
10714
+ rawDefault = JSON.parse(rawDefault);
10715
+ } catch {
10716
+ }
10717
+ if (!enumSchema.args.items.map((item) => {
10718
+ var _a;
10719
+ return (_a = item.value) != null ? _a : item.name;
10720
+ }).includes(rawDefault)) defaultValue = void 0;
10721
+ }
10722
+ }
10648
10723
  return {
10649
10724
  hasOptional: schemas.some((item) => isKeyword(item, schemaKeywords.optional)),
10650
10725
  hasNullable: schemas.some((item) => isKeyword(item, schemaKeywords.nullable)),
10651
10726
  hasNullish: schemas.some((item) => isKeyword(item, schemaKeywords.nullish)),
10652
- defaultValue: defaultSchema == null ? void 0 : defaultSchema.args,
10727
+ defaultValue,
10653
10728
  isBigInt
10654
10729
  };
10655
10730
  }
@@ -10671,7 +10746,7 @@ const shouldCoerce = (coercion, type) => {
10671
10746
  if (typeof coercion === "boolean") return coercion;
10672
10747
  return !!coercion[type];
10673
10748
  };
10674
- const parse$2 = createParser({
10749
+ const parse$1 = createParser({
10675
10750
  mapper: zodKeywordMapper,
10676
10751
  handlers: {
10677
10752
  union(tree, options) {
@@ -10862,7 +10937,21 @@ const parse$2 = createParser({
10862
10937
  const { current, siblings } = tree;
10863
10938
  if (options.mini) return;
10864
10939
  const isBigInt = siblings.some((it) => isKeyword(it, schemaKeywords.bigint));
10865
- if (current.args !== void 0) return zodKeywordMapper.default(current.args, void 0, void 0, isBigInt);
10940
+ if (current.args !== void 0) {
10941
+ const enumSchema = siblings.find((it) => isKeyword(it, schemaKeywords.enum));
10942
+ if (enumSchema) {
10943
+ let rawDefault = current.args;
10944
+ if (typeof rawDefault === "string") try {
10945
+ rawDefault = JSON.parse(rawDefault);
10946
+ } catch {
10947
+ }
10948
+ if (!enumSchema.args.items.map((item) => {
10949
+ var _a;
10950
+ return (_a = item.value) != null ? _a : item.name;
10951
+ }).includes(rawDefault)) return;
10952
+ }
10953
+ return zodKeywordMapper.default(current.args, void 0, void 0, isBigInt);
10954
+ }
10866
10955
  return zodKeywordMapper.default();
10867
10956
  },
10868
10957
  describe(tree, options) {
@@ -10941,7 +11030,7 @@ function Zod({ name, typeName, tree, schema, inferTypeName, mapper, coercion, ke
10941
11030
  });
10942
11031
  const baseSchemas = mini ? filterMiniModifiers(schemas) : schemas;
10943
11032
  const output = baseSchemas.map((schemaKeyword, index) => {
10944
- return parse$2({
11033
+ return parse$1({
10945
11034
  schema,
10946
11035
  parent: void 0,
10947
11036
  current: schemaKeyword,
@@ -10966,7 +11055,7 @@ function Zod({ name, typeName, tree, schema, inferTypeName, mapper, coercion, ke
10966
11055
  if (firstSchema && isKeyword(firstSchema, schemaKeywords.ref)) if (version === "3") suffix = ".schema";
10967
11056
  else suffix = ".unwrap()";
10968
11057
  }
10969
- const emptyValue = parse$2({
11058
+ const emptyValue = parse$1({
10970
11059
  schema,
10971
11060
  parent: void 0,
10972
11061
  current: { keyword: schemaKeywords[emptySchemaType] },
@@ -11001,11 +11090,11 @@ function Zod({ name, typeName, tree, schema, inferTypeName, mapper, coercion, ke
11001
11090
  isExportable: true,
11002
11091
  isIndexable: true,
11003
11092
  isTypeOnly: true,
11004
- children: [typeName && /* @__PURE__ */ jsx(Type$2, {
11093
+ children: [typeName && /* @__PURE__ */ jsx(Type$1, {
11005
11094
  export: true,
11006
11095
  name: inferTypeName,
11007
11096
  children: typeName
11008
- }), !typeName && /* @__PURE__ */ jsx(Type$2, {
11097
+ }), !typeName && /* @__PURE__ */ jsx(Type$1, {
11009
11098
  export: true,
11010
11099
  name: inferTypeName,
11011
11100
  children: `z.infer<typeof ${name}>`
@@ -208905,7 +208994,7 @@ function toCamelOrPascal$a(text, pascal) {
208905
208994
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
208906
208995
  }
208907
208996
  function applyToFileParts$a(text, transformPart) {
208908
- const parts = text.split(".");
208997
+ const parts = text.split(/\.(?=[a-zA-Z])/);
208909
208998
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
208910
208999
  }
208911
209000
  function camelCase$a(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -208959,6 +209048,27 @@ function jsStringEscape$1(input) {
208959
209048
  }
208960
209049
  });
208961
209050
  }
209051
+ function stringify$1(value) {
209052
+ if (value === void 0 || value === null) return '""';
209053
+ return JSON.stringify(trimQuotes$1(value.toString()));
209054
+ }
209055
+ const OPTIONAL_ADDS_UNDEFINED = /* @__PURE__ */ new Set(["undefined", "questionTokenAndUndefined"]);
209056
+ const OPTIONAL_ADDS_QUESTION_TOKEN = /* @__PURE__ */ new Set(["questionToken", "questionTokenAndUndefined"]);
209057
+ const ENUM_TYPES_WITH_KEY_SUFFIX = /* @__PURE__ */ new Set(["asConst", "asPascalConst"]);
209058
+ const ENUM_TYPES_WITH_RUNTIME_VALUE = /* @__PURE__ */ new Set([
209059
+ "enum",
209060
+ "asConst",
209061
+ "asPascalConst",
209062
+ "constEnum",
209063
+ "literal",
209064
+ void 0
209065
+ ]);
209066
+ const ENUM_TYPES_WITH_TYPE_ONLY = /* @__PURE__ */ new Set([
209067
+ "asConst",
209068
+ "asPascalConst",
209069
+ "literal",
209070
+ void 0
209071
+ ]);
208962
209072
  const { SyntaxKind, factory } = ts;
208963
209073
  const modifiers = {
208964
209074
  async: factory.createModifier(ts.SyntaxKind.AsyncKeyword),
@@ -208971,11 +209081,6 @@ const syntaxKind = {
208971
209081
  literalType: SyntaxKind.LiteralType,
208972
209082
  stringLiteral: SyntaxKind.StringLiteral
208973
209083
  };
208974
- function getUnknownType(unknownType) {
208975
- if (unknownType === "any") return keywordTypeNodes.any;
208976
- if (unknownType === "void") return keywordTypeNodes.void;
208977
- return keywordTypeNodes.unknown;
208978
- }
208979
209084
  function isValidIdentifier(str) {
208980
209085
  if (!str.length || str.trim() !== str) return false;
208981
209086
  const node = ts.parseIsolatedEntityName(str, ts.ScriptTarget.Latest);
@@ -209162,376 +209267,290 @@ const createTupleTypeNode = factory.createTupleTypeNode;
209162
209267
  const createRestTypeNode = factory.createRestTypeNode;
209163
209268
  const createTrue = factory.createTrue;
209164
209269
  const createFalse = factory.createFalse;
209165
- const createIndexedAccessTypeNode = factory.createIndexedAccessTypeNode;
209166
- const createTypeOperatorNode = factory.createTypeOperatorNode;
209270
+ factory.createIndexedAccessTypeNode;
209271
+ factory.createTypeOperatorNode;
209167
209272
  const createPrefixUnaryExpression = factory.createPrefixUnaryExpression;
209168
- const typeKeywordMapper = {
209169
- any: () => keywordTypeNodes.any,
209170
- unknown: () => keywordTypeNodes.unknown,
209171
- void: () => keywordTypeNodes.void,
209172
- number: () => keywordTypeNodes.number,
209173
- integer: () => keywordTypeNodes.number,
209174
- bigint: () => keywordTypeNodes.bigint,
209175
- object: (nodes) => {
209176
- if (!nodes || !nodes.length) return keywordTypeNodes.object;
209177
- return createTypeLiteralNode(nodes);
209178
- },
209179
- string: () => keywordTypeNodes.string,
209180
- boolean: () => keywordTypeNodes.boolean,
209181
- undefined: () => keywordTypeNodes.undefined,
209182
- nullable: void 0,
209183
- null: () => keywordTypeNodes.null,
209184
- nullish: void 0,
209185
- array: (nodes, arrayType) => {
209186
- if (!nodes) return;
209187
- return createArrayDeclaration({
209188
- nodes,
209189
- arrayType
209190
- });
209191
- },
209192
- tuple: (nodes, rest, min, max) => {
209193
- if (!nodes) return;
209194
- if (max) {
209195
- nodes = nodes.slice(0, max);
209196
- if (nodes.length < max && rest) nodes = [...nodes, ...Array(max - nodes.length).fill(rest)];
209197
- }
209198
- if (min) nodes = nodes.map((node, index) => index >= min ? createOptionalTypeNode(node) : node);
209199
- if (typeof max === "undefined" && rest) nodes.push(createRestTypeNode(createArrayTypeNode(rest)));
209200
- return createTupleTypeNode(nodes);
209201
- },
209202
- enum: (name) => {
209203
- if (!name) return;
209204
- return createTypeReferenceNode(name, void 0);
209205
- },
209206
- union: (nodes) => {
209207
- if (!nodes) return;
209208
- return createUnionDeclaration({
209209
- withParentheses: true,
209210
- nodes
209211
- });
209212
- },
209213
- const: (name, format) => {
209214
- if (name === null || name === void 0 || name === "") return;
209215
- if (format === "boolean") {
209216
- if (name === true) return createLiteralTypeNode(createTrue());
209217
- return createLiteralTypeNode(createFalse());
209273
+ function constToTypeNode(value, format) {
209274
+ if (format === "boolean") return createLiteralTypeNode(value === true ? createTrue() : createFalse());
209275
+ if (format === "number" && typeof value === "number") {
209276
+ if (value < 0) return createLiteralTypeNode(createPrefixUnaryExpression(SyntaxKind.MinusToken, createNumericLiteral(Math.abs(value))));
209277
+ return createLiteralTypeNode(createNumericLiteral(value));
209278
+ }
209279
+ return createLiteralTypeNode(createStringLiteral(String(value)));
209280
+ }
209281
+ function dateOrStringNode(node) {
209282
+ return node.representation === "date" ? createTypeReferenceNode(createIdentifier("Date")) : keywordTypeNodes.string;
209283
+ }
209284
+ function buildMemberNodes(members, print) {
209285
+ return (members != null ? members : []).map(print).filter(Boolean);
209286
+ }
209287
+ function buildTupleNode(node, print) {
209288
+ var _a, _b;
209289
+ let items = ((_a = node.items) != null ? _a : []).map(print).filter(Boolean);
209290
+ const restNode = node.rest ? (_b = print(node.rest)) != null ? _b : void 0 : void 0;
209291
+ const { min, max } = node;
209292
+ if (max !== void 0) {
209293
+ items = items.slice(0, max);
209294
+ if (items.length < max && restNode) items = [...items, ...Array(max - items.length).fill(restNode)];
209295
+ }
209296
+ if (min !== void 0) items = items.map((item, i) => i >= min ? createOptionalTypeNode(item) : item);
209297
+ if (max === void 0 && restNode) items.push(createRestTypeNode(createArrayTypeNode(restNode)));
209298
+ return createTupleTypeNode(items);
209299
+ }
209300
+ function buildPropertyType(schema, baseType, optionalType) {
209301
+ const addsUndefined = OPTIONAL_ADDS_UNDEFINED.has(optionalType);
209302
+ let type = baseType;
209303
+ if (schema.nullable) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] });
209304
+ if ((schema.nullish || schema.optional) && addsUndefined) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
209305
+ return type;
209306
+ }
209307
+ function buildPropertyJSDocComments(schema) {
209308
+ return [
209309
+ "description" in schema && schema.description ? `@description ${jsStringEscape$1(schema.description)}` : void 0,
209310
+ "deprecated" in schema && schema.deprecated ? "@deprecated" : void 0,
209311
+ "min" in schema && schema.min !== void 0 ? `@minLength ${schema.min}` : void 0,
209312
+ "max" in schema && schema.max !== void 0 ? `@maxLength ${schema.max}` : void 0,
209313
+ "pattern" in schema && schema.pattern ? `@pattern ${schema.pattern}` : void 0,
209314
+ "default" in schema && schema.default !== void 0 ? `@default ${"primitive" in schema && schema.primitive === "string" ? stringify$1(schema.default) : schema.default}` : void 0,
209315
+ "example" in schema && schema.example !== void 0 ? `@example ${schema.example}` : void 0,
209316
+ "primitive" in schema && schema.primitive ? [`@type ${schema.primitive || "unknown"}`, "optional" in schema && schema.optional ? " | undefined" : void 0].filter(Boolean).join("") : void 0
209317
+ ];
209318
+ }
209319
+ function buildIndexSignatures(node, propertyCount, print) {
209320
+ var _a, _b;
209321
+ const elements = [];
209322
+ if (node.additionalProperties && node.additionalProperties !== true) {
209323
+ const additionalType = (_a = print(node.additionalProperties)) != null ? _a : keywordTypeNodes.unknown;
209324
+ elements.push(createIndexSignature(propertyCount > 0 ? keywordTypeNodes.unknown : additionalType));
209325
+ } else if (node.additionalProperties === true) elements.push(createIndexSignature(keywordTypeNodes.unknown));
209326
+ if (node.patternProperties) {
209327
+ const first = Object.values(node.patternProperties)[0];
209328
+ if (first) {
209329
+ let patternType = (_b = print(first)) != null ? _b : keywordTypeNodes.unknown;
209330
+ if (first.nullable) patternType = createUnionDeclaration({ nodes: [patternType, keywordTypeNodes.null] });
209331
+ elements.push(createIndexSignature(patternType));
209218
209332
  }
209219
- if (format === "number" && typeof name === "number") return createLiteralTypeNode(createNumericLiteral(name));
209220
- return createLiteralTypeNode(createStringLiteral(name.toString()));
209221
- },
209222
- datetime: () => keywordTypeNodes.string,
209223
- date: (type = "string") => type === "string" ? keywordTypeNodes.string : createTypeReferenceNode(createIdentifier("Date")),
209224
- time: (type = "string") => type === "string" ? keywordTypeNodes.string : createTypeReferenceNode(createIdentifier("Date")),
209225
- uuid: () => keywordTypeNodes.string,
209226
- url: () => keywordTypeNodes.string,
209227
- default: void 0,
209228
- and: (nodes) => {
209229
- if (!nodes) return;
209230
- return createIntersectionDeclaration({
209231
- withParentheses: true,
209232
- nodes
209233
- });
209234
- },
209235
- describe: void 0,
209236
- min: void 0,
209237
- max: void 0,
209238
- optional: void 0,
209239
- matches: () => keywordTypeNodes.string,
209240
- email: () => keywordTypeNodes.string,
209241
- firstName: void 0,
209242
- lastName: void 0,
209243
- password: void 0,
209244
- phone: void 0,
209245
- readOnly: void 0,
209246
- writeOnly: void 0,
209247
- ref: (propertyName2) => {
209248
- if (!propertyName2) return;
209249
- return createTypeReferenceNode(propertyName2, void 0);
209250
- },
209251
- blob: () => createTypeReferenceNode("Blob", []),
209252
- deprecated: void 0,
209253
- example: void 0,
209254
- schema: void 0,
209255
- catchall: void 0,
209256
- name: void 0,
209257
- interface: void 0,
209258
- exclusiveMaximum: void 0,
209259
- exclusiveMinimum: void 0
209260
- };
209261
- const parse$1 = createParser({
209262
- mapper: typeKeywordMapper,
209263
- handlers: {
209264
- union(tree, options) {
209265
- const { current, schema, name } = tree;
209266
- return typeKeywordMapper.union(current.args.map((it) => this.parse({
209267
- schema,
209268
- parent: current,
209269
- name,
209270
- current: it,
209271
- siblings: []
209272
- }, options)).filter(Boolean));
209273
- },
209274
- and(tree, options) {
209275
- const { current, schema, name } = tree;
209276
- return typeKeywordMapper.and(current.args.map((it) => this.parse({
209277
- schema,
209278
- parent: current,
209279
- name,
209280
- current: it,
209281
- siblings: []
209282
- }, options)).filter(Boolean));
209283
- },
209284
- array(tree, options) {
209285
- const { current, schema, name } = tree;
209286
- return typeKeywordMapper.array(current.args.items.map((it) => this.parse({
209287
- schema,
209288
- parent: current,
209289
- name,
209290
- current: it,
209291
- siblings: []
209292
- }, options)).filter(Boolean), options.arrayType);
209293
- },
209294
- enum(tree, options) {
209295
- const { current } = tree;
209296
- if (options.enumType === "inlineLiteral") {
209297
- const enumValues = current.args.items.map((item) => item.value).filter((value) => value !== void 0 && value !== null).map((value) => {
209298
- const format = typeof value === "number" ? "number" : typeof value === "boolean" ? "boolean" : "string";
209299
- return typeKeywordMapper.const(value, format);
209300
- }).filter(Boolean);
209301
- return typeKeywordMapper.union(enumValues);
209302
- }
209303
- return typeKeywordMapper.enum(["asConst", "asPascalConst"].includes(options.enumType) ? `${current.args.typeName}Key` : current.args.typeName);
209304
- },
209305
- ref(tree, _options) {
209306
- const { current } = tree;
209307
- return typeKeywordMapper.ref(current.args.name);
209308
- },
209309
- blob() {
209310
- return typeKeywordMapper.blob();
209311
- },
209312
- tuple(tree, options) {
209313
- var _a;
209314
- const { current, schema, name } = tree;
209315
- return typeKeywordMapper.tuple(current.args.items.map((it) => this.parse({
209316
- schema,
209317
- parent: current,
209318
- name,
209319
- current: it,
209320
- siblings: []
209321
- }, options)).filter(Boolean), current.args.rest && ((_a = this.parse({
209322
- schema,
209323
- parent: current,
209324
- name,
209325
- current: current.args.rest,
209326
- siblings: []
209327
- }, options)) != null ? _a : void 0), current.args.min, current.args.max);
209328
- },
209329
- const(tree, _options) {
209330
- const { current } = tree;
209331
- return typeKeywordMapper.const(current.args.name, current.args.format);
209332
- },
209333
- object(tree, options) {
209334
- var _a, _b, _c, _d, _e;
209335
- const { current, schema, name } = tree;
209336
- const properties = Object.entries(((_a = current.args) == null ? void 0 : _a.properties) || {}).filter((item) => {
209337
- const schemas = item[1];
209338
- return schemas && typeof schemas.map === "function";
209339
- }).map(([name2, schemas]) => {
209340
- var _a2, _b2, _c2, _d2, _e2;
209341
- const mappedName = ((_a2 = schemas.find((schema2) => schema2.keyword === schemaKeywords.name)) == null ? void 0 : _a2.args) || name2;
209342
- const isNullish = schemas.some((schema2) => schema2.keyword === schemaKeywords.nullish);
209343
- const isNullable = schemas.some((schema2) => schema2.keyword === schemaKeywords.nullable);
209344
- const isOptional = schemas.some((schema2) => schema2.keyword === schemaKeywords.optional);
209345
- const isReadonly = schemas.some((schema2) => schema2.keyword === schemaKeywords.readOnly);
209346
- const describeSchema = schemas.find((schema2) => schema2.keyword === schemaKeywords.describe);
209347
- const deprecatedSchema = schemas.find((schema2) => schema2.keyword === schemaKeywords.deprecated);
209348
- const defaultSchema = schemas.find((schema2) => schema2.keyword === schemaKeywords.default);
209349
- const exampleSchema = schemas.find((schema2) => schema2.keyword === schemaKeywords.example);
209350
- const schemaSchema = schemas.find((schema2) => schema2.keyword === schemaKeywords.schema);
209351
- const minSchema = schemas.find((schema2) => schema2.keyword === schemaKeywords.min);
209352
- const maxSchema = schemas.find((schema2) => schema2.keyword === schemaKeywords.max);
209353
- const matchesSchema = schemas.find((schema2) => schema2.keyword === schemaKeywords.matches);
209354
- let type = schemas.map((it) => this.parse({
209355
- schema,
209356
- parent: current,
209357
- name: name2,
209358
- current: it,
209359
- siblings: schemas
209360
- }, options)).filter(Boolean)[0];
209361
- if (isNullable) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] });
209362
- if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
209363
- if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
209364
- return appendJSDocToNode({
209365
- node: createPropertySignature({
209366
- questionToken: isOptional || isNullish ? ["questionToken", "questionTokenAndUndefined"].includes(options.optionalType) : false,
209367
- name: mappedName,
209368
- type,
209369
- readOnly: isReadonly
209370
- }),
209371
- comments: [
209372
- describeSchema ? `@description ${jsStringEscape$1(describeSchema.args)}` : void 0,
209373
- deprecatedSchema ? "@deprecated" : void 0,
209374
- minSchema ? `@minLength ${minSchema.args}` : void 0,
209375
- maxSchema ? `@maxLength ${maxSchema.args}` : void 0,
209376
- matchesSchema ? `@pattern ${matchesSchema.args}` : void 0,
209377
- defaultSchema ? `@default ${defaultSchema.args}` : void 0,
209378
- exampleSchema ? `@example ${exampleSchema.args}` : void 0,
209379
- ((_b2 = schemaSchema == null ? void 0 : schemaSchema.args) == null ? void 0 : _b2.type) || ((_c2 = schemaSchema == null ? void 0 : schemaSchema.args) == null ? void 0 : _c2.format) ? [`@type ${((_d2 = schemaSchema == null ? void 0 : schemaSchema.args) == null ? void 0 : _d2.type) || "unknown"}${!isOptional ? "" : " | undefined"}`, (_e2 = schemaSchema == null ? void 0 : schemaSchema.args) == null ? void 0 : _e2.format].filter(Boolean).join(", ") : void 0
209380
- ].filter(Boolean)
209333
+ }
209334
+ return elements;
209335
+ }
209336
+ const printerTs = definePrinter((options) => {
209337
+ const addsUndefined = OPTIONAL_ADDS_UNDEFINED.has(options.optionalType);
209338
+ return {
209339
+ name: "typescript",
209340
+ options,
209341
+ nodes: {
209342
+ any: () => keywordTypeNodes.any,
209343
+ unknown: () => keywordTypeNodes.unknown,
209344
+ void: () => keywordTypeNodes.void,
209345
+ never: () => keywordTypeNodes.never,
209346
+ boolean: () => keywordTypeNodes.boolean,
209347
+ null: () => keywordTypeNodes.null,
209348
+ blob: () => createTypeReferenceNode("Blob", []),
209349
+ string: () => keywordTypeNodes.string,
209350
+ uuid: () => keywordTypeNodes.string,
209351
+ email: () => keywordTypeNodes.string,
209352
+ url: (node) => {
209353
+ if (node.path) return createUrlTemplateType(node.path);
209354
+ return keywordTypeNodes.string;
209355
+ },
209356
+ datetime: () => keywordTypeNodes.string,
209357
+ number: () => keywordTypeNodes.number,
209358
+ integer: () => keywordTypeNodes.number,
209359
+ bigint: () => keywordTypeNodes.bigint,
209360
+ date: dateOrStringNode,
209361
+ time: dateOrStringNode,
209362
+ ref(node) {
209363
+ var _a;
209364
+ if (!node.name) return;
209365
+ const refName = node.ref ? (_a = node.ref.split("/").at(-1)) != null ? _a : node.name : node.name;
209366
+ return createTypeReferenceNode(node.ref ? this.options.resolver.default(refName, "type") : refName, void 0);
209367
+ },
209368
+ enum(node) {
209369
+ var _a, _b, _c, _d;
209370
+ const values = (_c = (_b = (_a = node.namedEnumValues) == null ? void 0 : _a.map((v) => v.value)) != null ? _b : node.enumValues) != null ? _c : [];
209371
+ if (this.options.enumType === "inlineLiteral" || !node.name) return (_d = createUnionDeclaration({
209372
+ withParentheses: true,
209373
+ nodes: values.filter((v) => v !== null).map((value) => constToTypeNode(value, typeof value)).filter(Boolean)
209374
+ })) != null ? _d : void 0;
209375
+ const resolvedName = this.options.resolver.default(node.name, "type");
209376
+ return createTypeReferenceNode(ENUM_TYPES_WITH_KEY_SUFFIX.has(this.options.enumType) ? `${resolvedName}Key` : resolvedName, void 0);
209377
+ },
209378
+ union(node) {
209379
+ var _a, _b, _c;
209380
+ const members = (_a = node.members) != null ? _a : [];
209381
+ const hasStringLiteral = members.some((m) => m.type === "enum" && (m.enumType === "string" || m.primitive === "string"));
209382
+ const hasPlainString = members.some((m) => isPlainStringType(m));
209383
+ if (hasStringLiteral && hasPlainString) return (_b = createUnionDeclaration({
209384
+ withParentheses: true,
209385
+ nodes: members.map((m) => {
209386
+ if (isPlainStringType(m)) return createIntersectionDeclaration({
209387
+ nodes: [keywordTypeNodes.string, createTypeLiteralNode([])],
209388
+ withParentheses: true
209389
+ });
209390
+ return this.print(m);
209391
+ }).filter(Boolean)
209392
+ })) != null ? _b : void 0;
209393
+ return (_c = createUnionDeclaration({
209394
+ withParentheses: true,
209395
+ nodes: buildMemberNodes(members, this.print)
209396
+ })) != null ? _c : void 0;
209397
+ },
209398
+ intersection(node) {
209399
+ var _a;
209400
+ return (_a = createIntersectionDeclaration({
209401
+ withParentheses: true,
209402
+ nodes: buildMemberNodes(node.members, this.print)
209403
+ })) != null ? _a : void 0;
209404
+ },
209405
+ array(node) {
209406
+ var _a, _b;
209407
+ return (_b = createArrayDeclaration({
209408
+ nodes: ((_a = node.items) != null ? _a : []).map((item) => this.print(item)).filter(Boolean),
209409
+ arrayType: this.options.arrayType
209410
+ })) != null ? _b : void 0;
209411
+ },
209412
+ tuple(node) {
209413
+ return buildTupleNode(node, this.print);
209414
+ },
209415
+ object(node) {
209416
+ const { print, options: options2 } = this;
209417
+ const addsQuestionToken = OPTIONAL_ADDS_QUESTION_TOKEN.has(options2.optionalType);
209418
+ const propertyNodes = node.properties.map((prop) => {
209419
+ var _a;
209420
+ const baseType = (_a = print(prop.schema)) != null ? _a : keywordTypeNodes.unknown;
209421
+ const type = buildPropertyType(prop.schema, baseType, options2.optionalType);
209422
+ return appendJSDocToNode({
209423
+ node: createPropertySignature({
209424
+ questionToken: prop.schema.optional || prop.schema.nullish ? addsQuestionToken : false,
209425
+ name: prop.name,
209426
+ type,
209427
+ readOnly: prop.schema.readOnly
209428
+ }),
209429
+ comments: buildPropertyJSDocComments(prop.schema)
209430
+ });
209381
209431
  });
209382
- });
209383
- let additionalProperties;
209384
- if ((_c = (_b = current.args) == null ? void 0 : _b.additionalProperties) == null ? void 0 : _c.length) {
209385
- let additionalPropertiesType = current.args.additionalProperties.map((it) => this.parse({
209386
- schema,
209387
- parent: current,
209388
- name,
209389
- current: it,
209390
- siblings: []
209391
- }, options)).filter(Boolean).at(0);
209392
- if ((_d = current.args) == null ? void 0 : _d.additionalProperties.some((schema2) => isKeyword(schema2, schemaKeywords.nullable))) additionalPropertiesType = createUnionDeclaration({ nodes: [additionalPropertiesType, keywordTypeNodes.null] });
209393
- additionalProperties = createIndexSignature(properties.length > 0 ? keywordTypeNodes.unknown : additionalPropertiesType);
209394
- }
209395
- let patternProperties;
209396
- if ((_e = current.args) == null ? void 0 : _e.patternProperties) {
209397
- const allPatternSchemas = Object.values(current.args.patternProperties).flat();
209398
- if (allPatternSchemas.length > 0) {
209399
- patternProperties = allPatternSchemas.map((it) => this.parse({
209400
- schema,
209401
- parent: current,
209402
- name,
209403
- current: it,
209404
- siblings: []
209405
- }, options)).filter(Boolean).at(0);
209406
- if (allPatternSchemas.some((schema2) => isKeyword(schema2, schemaKeywords.nullable))) patternProperties = createUnionDeclaration({ nodes: [patternProperties, keywordTypeNodes.null] });
209407
- patternProperties = createIndexSignature(patternProperties);
209408
- }
209432
+ const allElements = [...propertyNodes, ...buildIndexSignatures(node, propertyNodes.length, print)];
209433
+ if (!allElements.length) return keywordTypeNodes.object;
209434
+ return createTypeLiteralNode(allElements);
209409
209435
  }
209410
- return typeKeywordMapper.object([
209411
- ...properties,
209412
- additionalProperties,
209413
- patternProperties
209414
- ].filter(Boolean));
209415
209436
  },
209416
- datetime() {
209417
- return typeKeywordMapper.datetime();
209418
- },
209419
- date(tree) {
209420
- const { current } = tree;
209421
- return typeKeywordMapper.date(current.args.type);
209422
- },
209423
- time(tree) {
209424
- const { current } = tree;
209425
- return typeKeywordMapper.time(current.args.type);
209437
+ print(node) {
209438
+ let type = this.print(node);
209439
+ if (!type) return;
209440
+ if (node.nullable) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] });
209441
+ if ((node.nullish || node.optional) && addsUndefined) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
209442
+ const { typeName, syntaxType = "type", description, keysToOmit } = this.options;
209443
+ if (!typeName) return type;
209444
+ const useTypeGeneration = syntaxType === "type" || type.kind === syntaxKind.union || !!(keysToOmit == null ? void 0 : keysToOmit.length);
209445
+ return createTypeDeclaration({
209446
+ name: typeName,
209447
+ isExportable: true,
209448
+ type: (keysToOmit == null ? void 0 : keysToOmit.length) ? createOmitDeclaration({
209449
+ keys: keysToOmit,
209450
+ type,
209451
+ nonNullable: true
209452
+ }) : type,
209453
+ syntax: useTypeGeneration ? "type" : "interface",
209454
+ comments: [
209455
+ (node == null ? void 0 : node.title) ? jsStringEscape$1(node.title) : void 0,
209456
+ description ? `@description ${jsStringEscape$1(description)}` : void 0,
209457
+ (node == null ? void 0 : node.deprecated) ? "@deprecated" : void 0,
209458
+ node && "min" in node && node.min !== void 0 ? `@minLength ${node.min}` : void 0,
209459
+ node && "max" in node && node.max !== void 0 ? `@maxLength ${node.max}` : void 0,
209460
+ node && "pattern" in node && node.pattern ? `@pattern ${node.pattern}` : void 0,
209461
+ (node == null ? void 0 : node.default) ? `@default ${node.default}` : void 0,
209462
+ (node == null ? void 0 : node.example) ? `@example ${node.example}` : void 0
209463
+ ]
209464
+ });
209426
209465
  }
209427
- }
209466
+ };
209428
209467
  });
209429
- function Type$1({ name, typedName, tree, keysToOmit, schema, optionalType, arrayType, syntaxType, enumType, enumKeyCasing, description }) {
209430
- const typeNodes = [];
209431
- if (!tree.length) return "";
209432
- const schemaFromTree = tree.find((item) => item.keyword === schemaKeywords.schema);
209433
- const enumSchemas = SchemaGenerator.deepSearch(tree, schemaKeywords.enum);
209434
- let type = tree.map((current, _index, siblings) => parse$1({
209435
- name,
209436
- schema,
209437
- parent: void 0,
209438
- current,
209439
- siblings
209440
- }, {
209468
+ function getEnumNames({ node, enumType, resolver }) {
209469
+ const resolved = resolver.default(node.name, "type");
209470
+ return {
209471
+ enumName: enumType === "asPascalConst" ? resolved : camelCase$a(node.name),
209472
+ typeName: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) ? `${resolved}Key` : resolved,
209473
+ refName: resolved
209474
+ };
209475
+ }
209476
+ function Enum({ node, enumType, enumKeyCasing, resolver }) {
209477
+ var _a, _b, _c, _d;
209478
+ const { enumName, typeName, refName } = getEnumNames({
209479
+ node,
209480
+ enumType,
209481
+ resolver
209482
+ });
209483
+ const [nameNode, typeNode] = createEnumDeclaration({
209484
+ name: enumName,
209485
+ typeName,
209486
+ enums: (_d = (_c = (_a = node.namedEnumValues) == null ? void 0 : _a.map((v) => [trimQuotes$1(v.name.toString()), v.value])) != null ? _c : (_b = node.enumValues) == null ? void 0 : _b.filter((v) => v !== null && v !== void 0).map((v) => [trimQuotes$1(v.toString()), v])) != null ? _d : [],
209487
+ type: enumType,
209488
+ enumKeyCasing
209489
+ });
209490
+ const needsRefAlias = ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && refName !== typeName;
209491
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
209492
+ nameNode && /* @__PURE__ */ jsx(File.Source, {
209493
+ name: enumName,
209494
+ isExportable: true,
209495
+ isIndexable: true,
209496
+ isTypeOnly: false,
209497
+ children: safePrint(nameNode)
209498
+ }),
209499
+ /* @__PURE__ */ jsx(File.Source, {
209500
+ name: typeName,
209501
+ isIndexable: true,
209502
+ isExportable: ENUM_TYPES_WITH_RUNTIME_VALUE.has(enumType),
209503
+ isTypeOnly: ENUM_TYPES_WITH_TYPE_ONLY.has(enumType),
209504
+ children: safePrint(typeNode)
209505
+ }),
209506
+ needsRefAlias && /* @__PURE__ */ jsx(File.Source, {
209507
+ name: refName,
209508
+ isExportable: true,
209509
+ isIndexable: true,
209510
+ isTypeOnly: true,
209511
+ children: `export type ${refName} = ${typeName}`
209512
+ })
209513
+ ] });
209514
+ }
209515
+ function Type({ name, typedName, node, keysToOmit, optionalType, arrayType, syntaxType, enumType, enumKeyCasing, description, resolver }) {
209516
+ const resolvedDescription = description || (node == null ? void 0 : node.description);
209517
+ const enumSchemaNodes = collect(node, { schema(n) {
209518
+ if (n.type === "enum" && n.name) return n;
209519
+ } });
209520
+ const typeNode = printerTs({
209441
209521
  optionalType,
209442
209522
  arrayType,
209443
- enumType
209444
- })).filter(Boolean).at(0) || typeKeywordMapper.undefined();
209445
- if (["asConst", "asPascalConst"].includes(enumType) && enumSchemas.length > 0) {
209446
- const isDirectEnum = schema.type === "array" && schema.items !== void 0;
209447
- const isEnumOnly = "enum" in schema && schema.enum;
209448
- if (isDirectEnum || isEnumOnly) {
209449
- type = createTypeReferenceNode(`${enumSchemas[0].args.typeName}Key`);
209450
- if (schema.type === "array") if (arrayType === "generic") type = createTypeReferenceNode(createIdentifier("Array"), [type]);
209451
- else type = createArrayTypeNode(type);
209452
- }
209453
- }
209454
- if (schemaFromTree && isKeyword(schemaFromTree, schemaKeywords.schema)) {
209455
- const isNullish = tree.some((item) => item.keyword === schemaKeywords.nullish);
209456
- const isNullable = tree.some((item) => item.keyword === schemaKeywords.nullable);
209457
- const isOptional = tree.some((item) => item.keyword === schemaKeywords.optional);
209458
- if (isNullable) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] });
209459
- if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
209460
- if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
209461
- }
209462
- const useTypeGeneration = syntaxType === "type" || [syntaxKind.union].includes(type.kind) || !!(keysToOmit == null ? void 0 : keysToOmit.length);
209463
- typeNodes.push(createTypeDeclaration({
209464
- name,
209465
- isExportable: true,
209466
- type: (keysToOmit == null ? void 0 : keysToOmit.length) ? createOmitDeclaration({
209467
- keys: keysToOmit,
209468
- type,
209469
- nonNullable: true
209470
- }) : type,
209471
- syntax: useTypeGeneration ? "type" : "interface",
209472
- comments: [
209473
- schema.title ? `${jsStringEscape$1(schema.title)}` : void 0,
209474
- description ? `@description ${jsStringEscape$1(description)}` : void 0,
209475
- schema.deprecated ? "@deprecated" : void 0,
209476
- schema.minLength ? `@minLength ${schema.minLength}` : void 0,
209477
- schema.maxLength ? `@maxLength ${schema.maxLength}` : void 0,
209478
- schema.pattern ? `@pattern ${schema.pattern}` : void 0,
209479
- schema.default ? `@default ${schema.default}` : void 0,
209480
- schema.example ? `@example ${schema.example}` : void 0
209481
- ]
209482
- }));
209483
- const enums = [...new Set(enumSchemas)].map((enumSchema) => {
209484
- const name2 = enumType === "asPascalConst" ? pascalCase$6(enumSchema.args.name) : camelCase$a(enumSchema.args.name);
209485
- const typeName = ["asConst", "asPascalConst"].includes(enumType) ? `${enumSchema.args.typeName}Key` : enumSchema.args.typeName;
209486
- const [nameNode, typeNode] = createEnumDeclaration({
209487
- name: name2,
209488
- typeName,
209489
- enums: enumSchema.args.items.map((item) => {
209490
- var _a;
209491
- return item.value === void 0 ? void 0 : [trimQuotes$1((_a = item.name) == null ? void 0 : _a.toString()), item.value];
209492
- }).filter(Boolean),
209493
- type: enumType,
209494
- enumKeyCasing
209495
- });
209523
+ enumType,
209524
+ typeName: name,
209525
+ syntaxType,
209526
+ description: resolvedDescription,
209527
+ keysToOmit,
209528
+ resolver
209529
+ }).print(node);
209530
+ if (!typeNode) return;
209531
+ const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node2) => {
209496
209532
  return {
209497
- nameNode,
209498
- typeNode,
209499
- name: name2,
209500
- typeName
209533
+ node: node2,
209534
+ ...getEnumNames({
209535
+ node: node2,
209536
+ enumType,
209537
+ resolver
209538
+ })
209501
209539
  };
209502
209540
  });
209503
209541
  const shouldExportEnums = enumType !== "inlineLiteral";
209504
209542
  const shouldExportType = enumType === "inlineLiteral" || enums.every((item) => item.typeName !== name);
209505
- return /* @__PURE__ */ jsxs(Fragment, { children: [shouldExportEnums && enums.map(({ name: name2, nameNode, typeName, typeNode }) => /* @__PURE__ */ jsxs(Fragment, { children: [nameNode && /* @__PURE__ */ jsx(File.Source, {
209506
- name: name2,
209507
- isExportable: true,
209508
- isIndexable: true,
209509
- isTypeOnly: false,
209510
- children: safePrint(nameNode)
209511
- }), /* @__PURE__ */ jsx(File.Source, {
209512
- name: typeName,
209513
- isIndexable: true,
209514
- isExportable: [
209515
- "enum",
209516
- "asConst",
209517
- "asPascalConst",
209518
- "constEnum",
209519
- "literal",
209520
- void 0
209521
- ].includes(enumType),
209522
- isTypeOnly: [
209523
- "asConst",
209524
- "asPascalConst",
209525
- "literal",
209526
- void 0
209527
- ].includes(enumType),
209528
- children: safePrint(typeNode)
209529
- })] })), shouldExportType && /* @__PURE__ */ jsx(File.Source, {
209543
+ return /* @__PURE__ */ jsxs(Fragment, { children: [shouldExportEnums && enums.map(({ node: node2 }) => /* @__PURE__ */ jsx(Enum, {
209544
+ node: node2,
209545
+ enumType,
209546
+ enumKeyCasing,
209547
+ resolver
209548
+ })), shouldExportType && /* @__PURE__ */ jsx(File.Source, {
209530
209549
  name: typedName,
209531
209550
  isTypeOnly: true,
209532
209551
  isExportable: true,
209533
209552
  isIndexable: true,
209534
- children: safePrint(...typeNodes)
209553
+ children: safePrint(typeNode)
209535
209554
  })] });
209536
209555
  }
209537
209556
 
@@ -209613,867 +209632,21 @@ function usePluginDriver() {
209613
209632
  return meta.driver;
209614
209633
  }
209615
209634
 
209616
- function useOas() {
209617
- const { meta } = useFabric();
209618
- return meta.oas;
209619
- }
209620
- function useOperationManager(generator) {
209621
- const plugin = usePlugin();
209622
- const driver = usePluginDriver();
209623
- const getName = (operation, { prefix = "", suffix = "", pluginName = plugin.name, type }) => {
209624
- return driver.resolveName({
209625
- name: `${prefix} ${operation.getOperationId()} ${suffix}`,
209626
- pluginName,
209627
- type
209628
- });
209629
- };
209630
- const getGroup = (operation) => {
209631
- var _a;
209632
- return {
209633
- tag: (_a = operation.getTags().at(0)) == null ? void 0 : _a.name,
209634
- path: operation.path
209635
- };
209636
- };
209637
- const getSchemas = (operation, params) => {
209638
- if (!generator) throw new Error(`useOperationManager: 'generator' parameter is required but was not provided`);
209639
- return generator.getSchemas(operation, { resolveName: (name) => driver.resolveName({
209640
- name,
209641
- pluginName: params == null ? void 0 : params.pluginName,
209642
- type: params == null ? void 0 : params.type
209643
- }) });
209644
- };
209645
- const getFile = (operation, { prefix, suffix, pluginName = plugin.name, extname = ".ts" } = {}) => {
209646
- const name = getName(operation, {
209647
- type: "file",
209648
- pluginName,
209649
- prefix,
209650
- suffix
209651
- });
209652
- const group = getGroup(operation);
209653
- const file = driver.getFile({
209654
- name,
209655
- extname,
209656
- pluginName,
209657
- options: {
209658
- type: "file",
209659
- pluginName,
209660
- group
209661
- }
209662
- });
209663
- return {
209664
- ...file,
209665
- meta: {
209666
- ...file.meta,
209667
- name,
209668
- pluginName,
209669
- group
209670
- }
209671
- };
209672
- };
209673
- const groupSchemasByName = (operation, { pluginName = plugin.name, type }) => {
209674
- var _a, _b, _c, _d;
209675
- if (!generator) throw new Error(`useOperationManager: 'generator' parameter is required but was not provided`);
209676
- const schemas = generator.getSchemas(operation);
209677
- const errors = (schemas.errors || []).reduce((prev, acc) => {
209678
- if (!acc.statusCode) return prev;
209679
- prev[acc.statusCode] = driver.resolveName({
209680
- name: acc.name,
209681
- pluginName,
209682
- type
209683
- });
209684
- return prev;
209685
- }, {});
209686
- const responses = (schemas.responses || []).reduce((prev, acc) => {
209687
- if (!acc.statusCode) return prev;
209688
- prev[acc.statusCode] = driver.resolveName({
209689
- name: acc.name,
209690
- pluginName,
209691
- type
209692
- });
209693
- return prev;
209694
- }, {});
209695
- return {
209696
- request: ((_a = schemas.request) == null ? void 0 : _a.name) ? driver.resolveName({
209697
- name: schemas.request.name,
209698
- pluginName,
209699
- type
209700
- }) : void 0,
209701
- parameters: {
209702
- path: ((_b = schemas.pathParams) == null ? void 0 : _b.name) ? driver.resolveName({
209703
- name: schemas.pathParams.name,
209704
- pluginName,
209705
- type
209706
- }) : void 0,
209707
- query: ((_c = schemas.queryParams) == null ? void 0 : _c.name) ? driver.resolveName({
209708
- name: schemas.queryParams.name,
209709
- pluginName,
209710
- type
209711
- }) : void 0,
209712
- header: ((_d = schemas.headerParams) == null ? void 0 : _d.name) ? driver.resolveName({
209713
- name: schemas.headerParams.name,
209714
- pluginName,
209715
- type
209716
- }) : void 0
209717
- },
209718
- responses: {
209719
- ...responses,
209720
- ["default"]: driver.resolveName({
209721
- name: schemas.response.name,
209722
- pluginName,
209723
- type
209724
- }),
209725
- ...errors
209726
- },
209727
- errors
209728
- };
209729
- };
209730
- return {
209731
- getName,
209732
- getFile,
209733
- getSchemas,
209734
- groupSchemasByName,
209735
- getGroup
209736
- };
209737
- }
209738
- function useSchemaManager() {
209739
- const plugin = usePlugin();
209740
- const driver = usePluginDriver();
209741
- const getName = (name, { pluginName = plugin.name, type }) => {
209742
- return driver.resolveName({
209743
- name,
209744
- pluginName,
209745
- type
209746
- });
209747
- };
209748
- const getFile = (name, { mode = "split", pluginName = plugin.name, extname = ".ts", group } = {}) => {
209749
- const resolvedName = mode === "single" ? "" : getName(name, {
209750
- type: "file",
209751
- pluginName
209752
- });
209753
- const file = driver.getFile({
209754
- name: resolvedName,
209755
- extname,
209756
- pluginName,
209757
- options: {
209758
- type: "file",
209759
- pluginName,
209760
- group
209761
- }
209762
- });
209763
- return {
209764
- ...file,
209765
- meta: {
209766
- ...file.meta,
209767
- name: resolvedName,
209768
- pluginName
209769
- }
209770
- };
209771
- };
209772
- return {
209773
- getName,
209774
- getFile
209775
- };
209776
- }
209777
-
209778
- function stringify$1(value) {
209779
- if (value === void 0 || value === null) return '""';
209780
- return JSON.stringify(trimQuotes$1(value.toString()));
209781
- }
209782
- function printCombinedSchema({ name, schemas, driver }) {
209783
- const properties = {};
209784
- if (schemas.response) properties["response"] = createUnionDeclaration({ nodes: schemas.responses.map((res) => {
209785
- return createTypeReferenceNode(createIdentifier(driver.resolveName({
209786
- name: res.name,
209787
- pluginName: pluginTsName,
209788
- type: "function"
209789
- })), void 0);
209790
- }) });
209791
- if (schemas.request) properties["request"] = createTypeReferenceNode(createIdentifier(driver.resolveName({
209792
- name: schemas.request.name,
209793
- pluginName: pluginTsName,
209794
- type: "function"
209795
- })), void 0);
209796
- if (schemas.pathParams) properties["pathParams"] = createTypeReferenceNode(createIdentifier(driver.resolveName({
209797
- name: schemas.pathParams.name,
209798
- pluginName: pluginTsName,
209799
- type: "function"
209800
- })), void 0);
209801
- if (schemas.queryParams) properties["queryParams"] = createTypeReferenceNode(createIdentifier(driver.resolveName({
209802
- name: schemas.queryParams.name,
209803
- pluginName: pluginTsName,
209804
- type: "function"
209805
- })), void 0);
209806
- if (schemas.headerParams) properties["headerParams"] = createTypeReferenceNode(createIdentifier(driver.resolveName({
209807
- name: schemas.headerParams.name,
209808
- pluginName: pluginTsName,
209809
- type: "function"
209810
- })), void 0);
209811
- if (schemas.errors) properties["errors"] = createUnionDeclaration({ nodes: schemas.errors.map((error) => {
209812
- return createTypeReferenceNode(createIdentifier(driver.resolveName({
209813
- name: error.name,
209814
- pluginName: pluginTsName,
209815
- type: "function"
209816
- })), void 0);
209817
- }) });
209818
- return safePrint(createTypeAliasDeclaration({
209819
- name,
209820
- type: createTypeLiteralNode(Object.keys(properties).map((key) => {
209821
- const type = properties[key];
209822
- if (!type) return;
209823
- return createPropertySignature({
209824
- name: pascalCase$6(key),
209825
- type
209826
- });
209827
- }).filter(Boolean)),
209828
- modifiers: [modifiers.export]
209829
- }));
209830
- }
209831
- function printRequestSchema({ baseName, operation, schemas, driver }) {
209832
- const name = driver.resolveName({
209833
- name: `${baseName} Request`,
209834
- pluginName: pluginTsName,
209835
- type: "type"
209836
- });
209837
- const results = [];
209838
- const dataRequestProperties = [];
209839
- if (schemas.request) {
209840
- const identifier = driver.resolveName({
209841
- name: schemas.request.name,
209842
- pluginName: pluginTsName,
209843
- type: "type"
209844
- });
209845
- dataRequestProperties.push(createPropertySignature({
209846
- name: "data",
209847
- questionToken: true,
209848
- type: createTypeReferenceNode(createIdentifier(identifier), void 0)
209849
- }));
209850
- } else dataRequestProperties.push(createPropertySignature({
209851
- name: "data",
209852
- questionToken: true,
209853
- type: keywordTypeNodes.never
209854
- }));
209855
- if (schemas.pathParams) {
209856
- const identifier = driver.resolveName({
209857
- name: schemas.pathParams.name,
209858
- pluginName: pluginTsName,
209859
- type: "type"
209860
- });
209861
- dataRequestProperties.push(createPropertySignature({
209862
- name: "pathParams",
209863
- type: createTypeReferenceNode(createIdentifier(identifier), void 0)
209864
- }));
209865
- } else dataRequestProperties.push(createPropertySignature({
209866
- name: "pathParams",
209867
- questionToken: true,
209868
- type: keywordTypeNodes.never
209869
- }));
209870
- if (schemas.queryParams) {
209871
- const identifier = driver.resolveName({
209872
- name: schemas.queryParams.name,
209873
- pluginName: pluginTsName,
209874
- type: "type"
209875
- });
209876
- dataRequestProperties.push(createPropertySignature({
209877
- name: "queryParams",
209878
- questionToken: true,
209879
- type: createTypeReferenceNode(createIdentifier(identifier), void 0)
209880
- }));
209881
- } else dataRequestProperties.push(createPropertySignature({
209882
- name: "queryParams",
209883
- questionToken: true,
209884
- type: keywordTypeNodes.never
209885
- }));
209886
- if (schemas.headerParams) {
209887
- const identifier = driver.resolveName({
209888
- name: schemas.headerParams.name,
209889
- pluginName: pluginTsName,
209890
- type: "type"
209891
- });
209892
- dataRequestProperties.push(createPropertySignature({
209893
- name: "headerParams",
209894
- questionToken: true,
209895
- type: createTypeReferenceNode(createIdentifier(identifier), void 0)
209896
- }));
209897
- } else dataRequestProperties.push(createPropertySignature({
209898
- name: "headerParams",
209899
- questionToken: true,
209900
- type: keywordTypeNodes.never
209901
- }));
209902
- dataRequestProperties.push(createPropertySignature({
209903
- name: "url",
209904
- type: createUrlTemplateType(operation.path)
209905
- }));
209906
- const dataRequestNode = createTypeAliasDeclaration({
209907
- name,
209908
- type: createTypeLiteralNode(dataRequestProperties),
209909
- modifiers: [modifiers.export]
209910
- });
209911
- results.push(safePrint(dataRequestNode));
209912
- return results.join("\n\n");
209913
- }
209914
- function printResponseSchema({ baseName, schemas, driver, unknownType }) {
209915
- const results = [];
209916
- const name = driver.resolveName({
209917
- name: `${baseName} ResponseData`,
209918
- pluginName: pluginTsName,
209919
- type: "type"
209920
- });
209921
- if (schemas.responses && schemas.responses.length > 0) {
209922
- const responsesProperties = schemas.responses.map((res) => {
209923
- var _a, _b;
209924
- const identifier = driver.resolveName({
209925
- name: res.name,
209926
- pluginName: pluginTsName,
209927
- type: "type"
209928
- });
209929
- return createPropertySignature({
209930
- name: (_b = (_a = res.statusCode) == null ? void 0 : _a.toString()) != null ? _b : "default",
209931
- type: createTypeReferenceNode(createIdentifier(identifier), void 0)
209932
- });
209933
- });
209934
- const responsesNode = createTypeAliasDeclaration({
209935
- name: `${baseName}Responses`,
209936
- type: createTypeLiteralNode(responsesProperties),
209937
- modifiers: [modifiers.export]
209938
- });
209939
- results.push(safePrint(responsesNode));
209940
- const responseNode = createTypeAliasDeclaration({
209941
- name,
209942
- type: createIndexedAccessTypeNode(createTypeReferenceNode(createIdentifier(`${baseName}Responses`), void 0), createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, createTypeReferenceNode(createIdentifier(`${baseName}Responses`), void 0))),
209943
- modifiers: [modifiers.export]
209944
- });
209945
- results.push(safePrint(responseNode));
209946
- } else {
209947
- const responseNode = createTypeAliasDeclaration({
209948
- name,
209949
- modifiers: [modifiers.export],
209950
- type: getUnknownType(unknownType)
209951
- });
209952
- results.push(safePrint(responseNode));
209953
- }
209954
- return results.join("\n\n");
209955
- }
209956
- const typeGenerator$1 = createReactGenerator({
209957
- name: "typescript",
209958
- Operation({ operation, generator, plugin }) {
209959
- const { options, options: { enumType, enumKeyCasing, syntaxType, optionalType, arrayType, unknownType, paramsCasing } } = plugin;
209960
- const mode = useMode();
209961
- const driver = usePluginDriver();
209962
- const oas = useOas();
209963
- const { getSchemas, getFile, getName, getGroup } = useOperationManager(generator);
209964
- const schemaManager = useSchemaManager();
209965
- const name = getName(operation, {
209966
- type: "type",
209967
- pluginName: pluginTsName
209968
- });
209969
- const file = getFile(operation);
209970
- const schemas = getSchemas(operation);
209971
- const schemaGenerator = new SchemaGenerator(options, {
209972
- fabric: generator.context.fabric,
209973
- oas,
209974
- events: generator.context.events,
209975
- plugin,
209976
- driver,
209977
- mode,
209978
- override: options.override
209979
- });
209980
- const operationSchemas = [
209981
- schemas.pathParams,
209982
- schemas.queryParams,
209983
- schemas.headerParams,
209984
- schemas.statusCodes,
209985
- schemas.request,
209986
- schemas.response
209987
- ].flat().filter(Boolean);
209988
- const mapOperationSchema = ({ name: name2, schema, description, keysToOmit, ...options2 }) => {
209989
- const transformedSchema = paramsCasing && isParameterSchema(name2) ? applyParamsCasing(schema, paramsCasing) : schema;
209990
- const tree = schemaGenerator.parse({
209991
- schema: transformedSchema,
209992
- name: name2,
209993
- parentName: null
209994
- });
209995
- const imports = getImports(tree);
209996
- const group = options2.operation ? getGroup(options2.operation) : void 0;
209997
- const type = {
209998
- name: schemaManager.getName(name2, { type: "type" }),
209999
- typedName: schemaManager.getName(name2, { type: "type" }),
210000
- file: schemaManager.getFile(options2.operationName || name2, { group })
210001
- };
210002
- return /* @__PURE__ */ jsxs(Fragment, { children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
210003
- root: file.path,
210004
- path: imp.path,
210005
- name: imp.name,
210006
- isTypeOnly: true
210007
- }, [
210008
- name2,
210009
- imp.name,
210010
- imp.path,
210011
- imp.isTypeOnly
210012
- ].join("-"))), /* @__PURE__ */ jsx(Type$1, {
210013
- name: type.name,
210014
- typedName: type.typedName,
210015
- description,
210016
- tree,
210017
- schema: transformedSchema,
210018
- enumType,
210019
- enumKeyCasing,
210020
- optionalType,
210021
- arrayType,
210022
- keysToOmit,
210023
- syntaxType
210024
- })] });
210025
- };
210026
- const responseName = schemaManager.getName(schemas.response.name, { type: "type" });
210027
- const combinedSchemaName = operation.method === "get" ? `${name}Query` : `${name}Mutation`;
210028
- return /* @__PURE__ */ jsxs(File, {
210029
- baseName: file.baseName,
210030
- path: file.path,
210031
- meta: file.meta,
210032
- banner: getBanner({
210033
- oas,
210034
- output: plugin.options.output,
210035
- config: driver.config
210036
- }),
210037
- footer: getFooter({
210038
- oas,
210039
- output: plugin.options.output
210040
- }),
210041
- children: [operationSchemas.map(mapOperationSchema), generator.context.UNSTABLE_NAMING ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
210042
- name: `${name}Request`,
210043
- isExportable: true,
210044
- isIndexable: true,
210045
- isTypeOnly: true,
210046
- children: printRequestSchema({
210047
- baseName: name,
210048
- operation,
210049
- schemas,
210050
- driver
210051
- })
210052
- }), /* @__PURE__ */ jsx(File.Source, {
210053
- name: responseName,
210054
- isExportable: true,
210055
- isIndexable: true,
210056
- isTypeOnly: true,
210057
- children: printResponseSchema({
210058
- baseName: name,
210059
- schemas,
210060
- driver,
210061
- unknownType
210062
- })
210063
- })] }) : /* @__PURE__ */ jsx(File.Source, {
210064
- name: combinedSchemaName,
210065
- isExportable: true,
210066
- isIndexable: true,
210067
- isTypeOnly: true,
210068
- children: printCombinedSchema({
210069
- name: combinedSchemaName,
210070
- schemas,
210071
- driver
210072
- })
210073
- })]
210074
- });
210075
- },
210076
- Schema({ schema, plugin }) {
210077
- const { options: { enumType, enumKeyCasing, syntaxType, optionalType, arrayType, output } } = plugin;
210078
- const mode = useMode();
210079
- const oas = useOas();
210080
- const driver = usePluginDriver();
210081
- const { getName, getFile } = useSchemaManager();
210082
- const imports = getImports(schema.tree);
210083
- const schemaFromTree = schema.tree.find((item) => item.keyword === schemaKeywords.schema);
210084
- let typedName = getName(schema.name, { type: "type" });
210085
- if (["asConst", "asPascalConst"].includes(enumType) && schemaFromTree && isKeyword(schemaFromTree, schemaKeywords.enum)) typedName = typedName += "Key";
210086
- const type = {
210087
- name: getName(schema.name, { type: "function" }),
210088
- typedName,
210089
- file: getFile(schema.name)
210090
- };
210091
- return /* @__PURE__ */ jsxs(File, {
210092
- baseName: type.file.baseName,
210093
- path: type.file.path,
210094
- meta: type.file.meta,
210095
- banner: getBanner({
210096
- oas,
210097
- output,
210098
- config: driver.config
210099
- }),
210100
- footer: getFooter({
210101
- oas,
210102
- output
210103
- }),
210104
- children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
210105
- root: type.file.path,
210106
- path: imp.path,
210107
- name: imp.name,
210108
- isTypeOnly: true
210109
- }, [
210110
- schema.name,
210111
- imp.path,
210112
- imp.isTypeOnly
210113
- ].join("-"))), /* @__PURE__ */ jsx(Type$1, {
210114
- name: type.name,
210115
- typedName: type.typedName,
210116
- description: schema.value.description,
210117
- tree: schema.tree,
210118
- schema: schema.value,
210119
- enumType,
210120
- enumKeyCasing,
210121
- optionalType,
210122
- arrayType,
210123
- syntaxType
210124
- })]
210125
- });
210126
- }
210127
- });
210128
- const OPTIONAL_ADDS_UNDEFINED = /* @__PURE__ */ new Set(["undefined", "questionTokenAndUndefined"]);
210129
- const OPTIONAL_ADDS_QUESTION_TOKEN = /* @__PURE__ */ new Set(["questionToken", "questionTokenAndUndefined"]);
210130
- const ENUM_TYPES_WITH_KEY_SUFFIX = /* @__PURE__ */ new Set(["asConst", "asPascalConst"]);
210131
- const ENUM_TYPES_WITH_RUNTIME_VALUE = /* @__PURE__ */ new Set([
210132
- "enum",
210133
- "asConst",
210134
- "asPascalConst",
210135
- "constEnum",
210136
- "literal",
210137
- void 0
210138
- ]);
210139
- const ENUM_TYPES_WITH_TYPE_ONLY = /* @__PURE__ */ new Set([
210140
- "asConst",
210141
- "asPascalConst",
210142
- "literal",
210143
- void 0
210144
- ]);
210145
- function constToTypeNode(value, format) {
210146
- if (format === "boolean") return createLiteralTypeNode(value === true ? createTrue() : createFalse());
210147
- if (format === "number" && typeof value === "number") {
210148
- if (value < 0) return createLiteralTypeNode(createPrefixUnaryExpression(SyntaxKind.MinusToken, createNumericLiteral(Math.abs(value))));
210149
- return createLiteralTypeNode(createNumericLiteral(value));
210150
- }
210151
- return createLiteralTypeNode(createStringLiteral(String(value)));
210152
- }
210153
- function dateOrStringNode(node) {
210154
- return node.representation === "date" ? createTypeReferenceNode(createIdentifier("Date")) : keywordTypeNodes.string;
210155
- }
210156
- function buildMemberNodes(members, print) {
210157
- return (members != null ? members : []).map(print).filter(Boolean);
210158
- }
210159
- function buildTupleNode(node, print) {
210160
- var _a, _b;
210161
- let items = ((_a = node.items) != null ? _a : []).map(print).filter(Boolean);
210162
- const restNode = node.rest ? (_b = print(node.rest)) != null ? _b : void 0 : void 0;
210163
- const { min, max } = node;
210164
- if (max !== void 0) {
210165
- items = items.slice(0, max);
210166
- if (items.length < max && restNode) items = [...items, ...Array(max - items.length).fill(restNode)];
210167
- }
210168
- if (min !== void 0) items = items.map((item, i) => i >= min ? createOptionalTypeNode(item) : item);
210169
- if (max === void 0 && restNode) items.push(createRestTypeNode(createArrayTypeNode(restNode)));
210170
- return createTupleTypeNode(items);
210171
- }
210172
- function buildPropertyType(schema, baseType, optionalType) {
210173
- const addsUndefined = OPTIONAL_ADDS_UNDEFINED.has(optionalType);
210174
- let type = baseType;
210175
- if (schema.nullable) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] });
210176
- if ((schema.nullish || schema.optional) && addsUndefined) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
210177
- return type;
210178
- }
210179
- function buildPropertyJSDocComments(schema) {
210180
- return [
210181
- "description" in schema && schema.description ? `@description ${jsStringEscape$1(schema.description)}` : void 0,
210182
- "deprecated" in schema && schema.deprecated ? "@deprecated" : void 0,
210183
- "min" in schema && schema.min !== void 0 ? `@minLength ${schema.min}` : void 0,
210184
- "max" in schema && schema.max !== void 0 ? `@maxLength ${schema.max}` : void 0,
210185
- "pattern" in schema && schema.pattern ? `@pattern ${schema.pattern}` : void 0,
210186
- "default" in schema && schema.default !== void 0 ? `@default ${"primitive" in schema && schema.primitive === "string" ? stringify$1(schema.default) : schema.default}` : void 0,
210187
- "example" in schema && schema.example !== void 0 ? `@example ${schema.example}` : void 0,
210188
- "primitive" in schema && schema.primitive ? [`@type ${schema.primitive || "unknown"}`, "optional" in schema && schema.optional ? " | undefined" : void 0].filter(Boolean).join("") : void 0
210189
- ];
210190
- }
210191
- function buildIndexSignatures(node, propertyCount, print) {
210192
- var _a, _b;
210193
- const elements = [];
210194
- if (node.additionalProperties && node.additionalProperties !== true) {
210195
- const additionalType = (_a = print(node.additionalProperties)) != null ? _a : keywordTypeNodes.unknown;
210196
- elements.push(createIndexSignature(propertyCount > 0 ? keywordTypeNodes.unknown : additionalType));
210197
- } else if (node.additionalProperties === true) elements.push(createIndexSignature(keywordTypeNodes.unknown));
210198
- if (node.patternProperties) {
210199
- const first = Object.values(node.patternProperties)[0];
210200
- if (first) {
210201
- let patternType = (_b = print(first)) != null ? _b : keywordTypeNodes.unknown;
210202
- if (first.nullable) patternType = createUnionDeclaration({ nodes: [patternType, keywordTypeNodes.null] });
210203
- elements.push(createIndexSignature(patternType));
210204
- }
210205
- }
210206
- return elements;
210207
- }
210208
- const printerTs = definePrinter((options) => {
210209
- const addsUndefined = OPTIONAL_ADDS_UNDEFINED.has(options.optionalType);
210210
- return {
210211
- name: "typescript",
210212
- options,
210213
- nodes: {
210214
- any: () => keywordTypeNodes.any,
210215
- unknown: () => keywordTypeNodes.unknown,
210216
- void: () => keywordTypeNodes.void,
210217
- never: () => keywordTypeNodes.never,
210218
- boolean: () => keywordTypeNodes.boolean,
210219
- null: () => keywordTypeNodes.null,
210220
- blob: () => createTypeReferenceNode("Blob", []),
210221
- string: () => keywordTypeNodes.string,
210222
- uuid: () => keywordTypeNodes.string,
210223
- email: () => keywordTypeNodes.string,
210224
- url: (node) => {
210225
- if (node.path) return createUrlTemplateType(node.path);
210226
- return keywordTypeNodes.string;
210227
- },
210228
- datetime: () => keywordTypeNodes.string,
210229
- number: () => keywordTypeNodes.number,
210230
- integer: () => keywordTypeNodes.number,
210231
- bigint: () => keywordTypeNodes.bigint,
210232
- date: dateOrStringNode,
210233
- time: dateOrStringNode,
210234
- ref(node) {
210235
- if (!node.name) return;
210236
- return createTypeReferenceNode(node.name, void 0);
210237
- },
210238
- enum(node) {
210239
- var _a, _b, _c, _d;
210240
- const values = (_c = (_b = (_a = node.namedEnumValues) == null ? void 0 : _a.map((v) => v.value)) != null ? _b : node.enumValues) != null ? _c : [];
210241
- if (this.options.enumType === "inlineLiteral" || !node.name) return (_d = createUnionDeclaration({
210242
- withParentheses: true,
210243
- nodes: values.filter((v) => v !== null).map((value) => constToTypeNode(value, typeof value)).filter(Boolean)
210244
- })) != null ? _d : void 0;
210245
- const resolvedName = pascalCase$6(node.name);
210246
- return createTypeReferenceNode(ENUM_TYPES_WITH_KEY_SUFFIX.has(this.options.enumType) ? `${resolvedName}Key` : resolvedName, void 0);
210247
- },
210248
- union(node) {
210249
- var _a, _b, _c;
210250
- const members = (_a = node.members) != null ? _a : [];
210251
- const hasStringLiteral = members.some((m) => m.type === "enum" && (m.enumType === "string" || m.primitive === "string"));
210252
- const hasPlainString = members.some((m) => isPlainStringType(m));
210253
- if (hasStringLiteral && hasPlainString) return (_b = createUnionDeclaration({
210254
- withParentheses: true,
210255
- nodes: members.map((m) => {
210256
- if (isPlainStringType(m)) return createIntersectionDeclaration({
210257
- nodes: [keywordTypeNodes.string, createTypeLiteralNode([])],
210258
- withParentheses: true
210259
- });
210260
- return this.print(m);
210261
- }).filter(Boolean)
210262
- })) != null ? _b : void 0;
210263
- return (_c = createUnionDeclaration({
210264
- withParentheses: true,
210265
- nodes: buildMemberNodes(members, this.print)
210266
- })) != null ? _c : void 0;
210267
- },
210268
- intersection(node) {
210269
- var _a;
210270
- return (_a = createIntersectionDeclaration({
210271
- withParentheses: true,
210272
- nodes: buildMemberNodes(node.members, this.print)
210273
- })) != null ? _a : void 0;
210274
- },
210275
- array(node) {
210276
- var _a, _b;
210277
- return (_b = createArrayDeclaration({
210278
- nodes: ((_a = node.items) != null ? _a : []).map((item) => this.print(item)).filter(Boolean),
210279
- arrayType: this.options.arrayType
210280
- })) != null ? _b : void 0;
210281
- },
210282
- tuple(node) {
210283
- return buildTupleNode(node, this.print);
210284
- },
210285
- object(node) {
210286
- const { print, options: options2 } = this;
210287
- const addsQuestionToken = OPTIONAL_ADDS_QUESTION_TOKEN.has(options2.optionalType);
210288
- const propertyNodes = node.properties.map((prop) => {
210289
- var _a;
210290
- const baseType = (_a = print(prop.schema)) != null ? _a : keywordTypeNodes.unknown;
210291
- const type = buildPropertyType(prop.schema, baseType, options2.optionalType);
210292
- return appendJSDocToNode({
210293
- node: createPropertySignature({
210294
- questionToken: prop.schema.optional || prop.schema.nullish ? addsQuestionToken : false,
210295
- name: prop.name,
210296
- type,
210297
- readOnly: prop.schema.readOnly
210298
- }),
210299
- comments: buildPropertyJSDocComments(prop.schema)
210300
- });
210301
- });
210302
- const allElements = [...propertyNodes, ...buildIndexSignatures(node, propertyNodes.length, print)];
210303
- if (!allElements.length) return keywordTypeNodes.object;
210304
- return createTypeLiteralNode(allElements);
210305
- }
210306
- },
210307
- print(node) {
210308
- let type = this.print(node);
210309
- if (!type) return;
210310
- if (node.nullable) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] });
210311
- if ((node.nullish || node.optional) && addsUndefined) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
210312
- const { typeName, syntaxType = "type", description, keysToOmit } = this.options;
210313
- if (!typeName) return type;
210314
- const useTypeGeneration = syntaxType === "type" || type.kind === syntaxKind.union || !!(keysToOmit == null ? void 0 : keysToOmit.length);
210315
- return createTypeDeclaration({
210316
- name: typeName,
210317
- isExportable: true,
210318
- type: (keysToOmit == null ? void 0 : keysToOmit.length) ? createOmitDeclaration({
210319
- keys: keysToOmit,
210320
- type,
210321
- nonNullable: true
210322
- }) : type,
210323
- syntax: useTypeGeneration ? "type" : "interface",
210324
- comments: [
210325
- (node == null ? void 0 : node.title) ? jsStringEscape$1(node.title) : void 0,
210326
- description ? `@description ${jsStringEscape$1(description)}` : void 0,
210327
- (node == null ? void 0 : node.deprecated) ? "@deprecated" : void 0,
210328
- node && "min" in node && node.min !== void 0 ? `@minLength ${node.min}` : void 0,
210329
- node && "max" in node && node.max !== void 0 ? `@maxLength ${node.max}` : void 0,
210330
- node && "pattern" in node && node.pattern ? `@pattern ${node.pattern}` : void 0,
210331
- (node == null ? void 0 : node.default) ? `@default ${node.default}` : void 0,
210332
- (node == null ? void 0 : node.example) ? `@example ${node.example}` : void 0
210333
- ]
210334
- });
210335
- }
210336
- };
210337
- });
210338
- function getEnumNames(node, enumType) {
210339
- const resolved = pascalCase$6(node.name);
210340
- return {
210341
- enumName: enumType === "asPascalConst" ? resolved : camelCase$a(node.name),
210342
- typeName: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) ? `${resolved}Key` : resolved
210343
- };
210344
- }
210345
- function Enum({ node, enumType, enumKeyCasing }) {
210346
- var _a, _b, _c, _d;
210347
- const { enumName, typeName } = getEnumNames(node, enumType);
210348
- const [nameNode, typeNode] = createEnumDeclaration({
210349
- name: enumName,
210350
- typeName,
210351
- enums: (_d = (_c = (_a = node.namedEnumValues) == null ? void 0 : _a.map((v) => [trimQuotes$1(v.name.toString()), v.value])) != null ? _c : (_b = node.enumValues) == null ? void 0 : _b.filter((v) => v !== null && v !== void 0).map((v) => [trimQuotes$1(v.toString()), v])) != null ? _d : [],
210352
- type: enumType,
210353
- enumKeyCasing
210354
- });
210355
- return /* @__PURE__ */ jsxs(Fragment, { children: [nameNode && /* @__PURE__ */ jsx(File.Source, {
210356
- name: enumName,
210357
- isExportable: true,
210358
- isIndexable: true,
210359
- isTypeOnly: false,
210360
- children: safePrint(nameNode)
210361
- }), /* @__PURE__ */ jsx(File.Source, {
210362
- name: typeName,
210363
- isIndexable: true,
210364
- isExportable: ENUM_TYPES_WITH_RUNTIME_VALUE.has(enumType),
210365
- isTypeOnly: ENUM_TYPES_WITH_TYPE_ONLY.has(enumType),
210366
- children: safePrint(typeNode)
210367
- })] });
210368
- }
210369
- function Type({ name, typedName, node, keysToOmit, optionalType, arrayType, syntaxType, enumType, enumKeyCasing, description }) {
210370
- const resolvedDescription = description || (node == null ? void 0 : node.description);
210371
- const enumSchemaNodes = collect(node, { schema(n) {
210372
- if (n.type === "enum" && n.name) return n;
210373
- } });
210374
- const typeNode = printerTs({
210375
- optionalType,
210376
- arrayType,
210377
- enumType,
210378
- typeName: name,
210379
- syntaxType,
210380
- description: resolvedDescription,
210381
- keysToOmit
210382
- }).print(node);
210383
- if (!typeNode) return;
210384
- const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node2) => {
210385
- return {
210386
- node: node2,
210387
- ...getEnumNames(node2, enumType)
210388
- };
210389
- });
210390
- const shouldExportEnums = enumType !== "inlineLiteral";
210391
- const shouldExportType = enumType === "inlineLiteral" || enums.every((item) => item.typeName !== name);
210392
- return /* @__PURE__ */ jsxs(Fragment, { children: [shouldExportEnums && enums.map(({ node: node2 }) => /* @__PURE__ */ jsx(Enum, {
210393
- node: node2,
210394
- enumType,
210395
- enumKeyCasing
210396
- })), shouldExportType && /* @__PURE__ */ jsx(File.Source, {
210397
- name: typedName,
210398
- isTypeOnly: true,
210399
- isExportable: true,
210400
- isIndexable: true,
210401
- children: safePrint(typeNode)
210402
- })] });
210403
- }
210404
- const resolverTs = defineResolver(() => {
210405
- return {
210406
- default(name, type) {
210407
- return pascalCase$6(name, { isFile: type === "file" });
210408
- },
210409
- resolveName(name) {
210410
- return this.default(name, "function");
210411
- },
210412
- resolveTypedName(name) {
210413
- return this.default(name, "type");
210414
- },
210415
- resolvePathName(name, type) {
210416
- return this.default(name, type);
210417
- },
210418
- resolveParamName(node, param) {
210419
- return this.resolveName(`${node.operationId} ${this.default(param.in)} ${param.name}`);
210420
- },
210421
- resolveParamTypedName(node, param) {
210422
- return this.resolveTypedName(`${node.operationId} ${this.default(param.in)} ${param.name}`);
210423
- },
210424
- resolveResponseStatusName(node, statusCode) {
210425
- return this.resolveName(`${node.operationId} Status ${statusCode}`);
210426
- },
210427
- resolveResponseStatusTypedName(node, statusCode) {
210428
- return this.resolveTypedName(`${node.operationId} Status ${statusCode}`);
210429
- },
210430
- resolveDataName(node) {
210431
- return this.resolveName(`${node.operationId} Data`);
210432
- },
210433
- resolveDataTypedName(node) {
210434
- return this.resolveTypedName(`${node.operationId} Data`);
210435
- },
210436
- resolveRequestConfigName(node) {
210437
- return this.resolveName(`${node.operationId} RequestConfig`);
210438
- },
210439
- resolveRequestConfigTypedName(node) {
210440
- return this.resolveTypedName(`${node.operationId} RequestConfig`);
210441
- },
210442
- resolveResponsesName(node) {
210443
- return this.resolveName(`${node.operationId} Responses`);
210444
- },
210445
- resolveResponsesTypedName(node) {
210446
- return this.resolveTypedName(`${node.operationId} Responses`);
210447
- },
210448
- resolveResponseName(node) {
210449
- return this.resolveName(`${node.operationId} Response`);
210450
- },
210451
- resolveResponseTypedName(node) {
210452
- return this.resolveTypedName(`${node.operationId} Response`);
210453
- },
210454
- resolveEnumKeyTypedName(node) {
210455
- var _a;
210456
- return `${this.resolveTypedName((_a = node.name) != null ? _a : "")}Key`;
210457
- }
210458
- };
210459
- });
210460
- function buildParamsSchema({ params, operationId, resolveName }) {
209635
+ function buildParamsSchema({ params, node, resolver }) {
210461
209636
  return createSchema({
210462
209637
  type: "object",
210463
209638
  properties: params.map((param) => createProperty({
210464
209639
  name: param.name,
210465
209640
  schema: createSchema({
210466
209641
  type: "ref",
210467
- name: resolveName({
210468
- name: `${operationId} ${pascalCase$6(param.in)} ${param.name}`,
210469
- type: "function"
210470
- }),
209642
+ name: resolver.resolveParamName(node, param),
210471
209643
  optional: !param.required
210472
209644
  })
210473
209645
  }))
210474
209646
  });
210475
209647
  }
210476
- function buildDataSchemaNode({ node, resolveName }) {
209648
+ function buildDataSchemaNode({ node, resolver }) {
209649
+ var _a;
210477
209650
  const pathParams = node.parameters.filter((p) => p.in === "path");
210478
209651
  const queryParams = node.parameters.filter((p) => p.in === "query");
210479
209652
  const headerParams = node.parameters.filter((p) => p.in === "header");
@@ -210483,12 +209656,9 @@ function buildDataSchemaNode({ node, resolveName }) {
210483
209656
  properties: [
210484
209657
  createProperty({
210485
209658
  name: "data",
210486
- schema: node.requestBody ? createSchema({
209659
+ schema: ((_a = node.requestBody) == null ? void 0 : _a.schema) ? createSchema({
210487
209660
  type: "ref",
210488
- name: resolveName({
210489
- name: `${node.operationId} Data`,
210490
- type: "function"
210491
- }),
209661
+ name: resolver.resolveDataTypedName(node),
210492
209662
  optional: true
210493
209663
  }) : createSchema({
210494
209664
  type: "never",
@@ -210499,8 +209669,8 @@ function buildDataSchemaNode({ node, resolveName }) {
210499
209669
  name: "pathParams",
210500
209670
  schema: pathParams.length > 0 ? buildParamsSchema({
210501
209671
  params: pathParams,
210502
- operationId: node.operationId,
210503
- resolveName
209672
+ node,
209673
+ resolver
210504
209674
  }) : createSchema({
210505
209675
  type: "never",
210506
209676
  optional: true
@@ -210511,8 +209681,8 @@ function buildDataSchemaNode({ node, resolveName }) {
210511
209681
  schema: queryParams.length > 0 ? createSchema({
210512
209682
  ...buildParamsSchema({
210513
209683
  params: queryParams,
210514
- operationId: node.operationId,
210515
- resolveName
209684
+ node,
209685
+ resolver
210516
209686
  }),
210517
209687
  optional: true
210518
209688
  }) : createSchema({
@@ -210525,8 +209695,8 @@ function buildDataSchemaNode({ node, resolveName }) {
210525
209695
  schema: headerParams.length > 0 ? createSchema({
210526
209696
  ...buildParamsSchema({
210527
209697
  params: headerParams,
210528
- operationId: node.operationId,
210529
- resolveName
209698
+ node,
209699
+ resolver
210530
209700
  }),
210531
209701
  optional: true
210532
209702
  }) : createSchema({
@@ -210544,7 +209714,7 @@ function buildDataSchemaNode({ node, resolveName }) {
210544
209714
  ]
210545
209715
  });
210546
209716
  }
210547
- function buildResponsesSchemaNode({ node, resolveName }) {
209717
+ function buildResponsesSchemaNode({ node, resolver }) {
210548
209718
  if (node.responses.length === 0) return null;
210549
209719
  return createSchema({
210550
209720
  type: "object",
@@ -210552,48 +209722,174 @@ function buildResponsesSchemaNode({ node, resolveName }) {
210552
209722
  name: String(res.statusCode),
210553
209723
  schema: createSchema({
210554
209724
  type: "ref",
210555
- name: resolveName({
210556
- name: `${node.operationId} Status ${res.statusCode}`,
210557
- type: "function"
210558
- })
209725
+ name: resolver.resolveResponseStatusTypedName(node, res.statusCode)
210559
209726
  })
210560
209727
  }))
210561
209728
  });
210562
209729
  }
210563
- function buildResponseUnionSchemaNode({ node, resolveName }) {
209730
+ function buildResponseUnionSchemaNode({ node, resolver }) {
210564
209731
  const responsesWithSchema = node.responses.filter((res) => res.schema);
210565
209732
  if (responsesWithSchema.length === 0) return null;
210566
209733
  return createSchema({
210567
209734
  type: "union",
210568
209735
  members: responsesWithSchema.map((res) => createSchema({
210569
209736
  type: "ref",
210570
- name: resolveName({
210571
- name: `${node.operationId} Status ${res.statusCode}`,
210572
- type: "function"
210573
- })
209737
+ name: resolver.resolveResponseStatusTypedName(node, res.statusCode)
210574
209738
  }))
210575
209739
  });
210576
209740
  }
209741
+ function buildGroupedParamsSchema({ params, parentName }) {
209742
+ return createSchema({
209743
+ type: "object",
209744
+ properties: params.map((param) => {
209745
+ let schema = {
209746
+ ...param.schema,
209747
+ optional: !param.required
209748
+ };
209749
+ if (narrowSchema(schema, "enum") && !schema.name && parentName) schema = {
209750
+ ...schema,
209751
+ name: pascalCase$6([
209752
+ parentName,
209753
+ param.name,
209754
+ "enum"
209755
+ ].join(" "))
209756
+ };
209757
+ return createProperty({
209758
+ name: param.name,
209759
+ schema
209760
+ });
209761
+ })
209762
+ });
209763
+ }
209764
+ function buildLegacyResponsesSchemaNode({ node, resolver }) {
209765
+ var _a;
209766
+ const isGet = node.method.toLowerCase() === "get";
209767
+ const successResponses = node.responses.filter((res) => {
209768
+ const code = Number(res.statusCode);
209769
+ return !Number.isNaN(code) && code >= 200 && code < 300;
209770
+ });
209771
+ const errorResponses = node.responses.filter((res) => res.statusCode === "default" || Number(res.statusCode) >= 400);
209772
+ const responseSchema = successResponses.length > 0 ? successResponses.length === 1 ? createSchema({
209773
+ type: "ref",
209774
+ name: resolver.resolveResponseStatusTypedName(node, successResponses[0].statusCode)
209775
+ }) : createSchema({
209776
+ type: "union",
209777
+ members: successResponses.map((res) => createSchema({
209778
+ type: "ref",
209779
+ name: resolver.resolveResponseStatusTypedName(node, res.statusCode)
209780
+ }))
209781
+ }) : createSchema({ type: "any" });
209782
+ const errorsSchema = errorResponses.length > 0 ? errorResponses.length === 1 ? createSchema({
209783
+ type: "ref",
209784
+ name: resolver.resolveResponseStatusTypedName(node, errorResponses[0].statusCode)
209785
+ }) : createSchema({
209786
+ type: "union",
209787
+ members: errorResponses.map((res) => createSchema({
209788
+ type: "ref",
209789
+ name: resolver.resolveResponseStatusTypedName(node, res.statusCode)
209790
+ }))
209791
+ }) : createSchema({ type: "any" });
209792
+ const properties = [createProperty({
209793
+ name: "Response",
209794
+ schema: responseSchema
209795
+ })];
209796
+ if (!isGet && ((_a = node.requestBody) == null ? void 0 : _a.schema)) properties.push(createProperty({
209797
+ name: "Request",
209798
+ schema: createSchema({
209799
+ type: "ref",
209800
+ name: resolver.resolveDataTypedName(node)
209801
+ })
209802
+ }));
209803
+ else if (isGet && node.parameters.some((p) => p.in === "query")) properties.push(createProperty({
209804
+ name: "QueryParams",
209805
+ schema: createSchema({
209806
+ type: "ref",
209807
+ name: resolver.resolveQueryParamsTypedName(node)
209808
+ })
209809
+ }));
209810
+ if (node.parameters.some((p) => p.in === "path") && resolver.resolvePathParamsTypedName) properties.push(createProperty({
209811
+ name: "PathParams",
209812
+ schema: createSchema({
209813
+ type: "ref",
209814
+ name: resolver.resolvePathParamsTypedName(node)
209815
+ })
209816
+ }));
209817
+ if (node.parameters.some((p) => p.in === "header") && resolver.resolveHeaderParamsTypedName) properties.push(createProperty({
209818
+ name: "HeaderParams",
209819
+ schema: createSchema({
209820
+ type: "ref",
209821
+ name: resolver.resolveHeaderParamsTypedName(node)
209822
+ })
209823
+ }));
209824
+ properties.push(createProperty({
209825
+ name: "Errors",
209826
+ schema: errorsSchema
209827
+ }));
209828
+ return createSchema({
209829
+ type: "object",
209830
+ properties
209831
+ });
209832
+ }
209833
+ function buildLegacyResponseUnionSchemaNode({ node, resolver }) {
209834
+ const successResponses = node.responses.filter((res) => {
209835
+ const code = Number(res.statusCode);
209836
+ return !Number.isNaN(code) && code >= 200 && code < 300;
209837
+ });
209838
+ if (successResponses.length === 0) return createSchema({ type: "any" });
209839
+ if (successResponses.length === 1) return createSchema({
209840
+ type: "ref",
209841
+ name: resolver.resolveResponseStatusTypedName(node, successResponses[0].statusCode)
209842
+ });
209843
+ return createSchema({
209844
+ type: "union",
209845
+ members: successResponses.map((res) => createSchema({
209846
+ type: "ref",
209847
+ name: resolver.resolveResponseStatusTypedName(node, res.statusCode)
209848
+ }))
209849
+ });
209850
+ }
209851
+ function nameUnnamedEnums(node, parentName) {
209852
+ return transform(node, {
209853
+ schema(n) {
209854
+ if (n.type === "enum" && !n.name) return {
209855
+ ...n,
209856
+ name: pascalCase$6([parentName, "enum"].join(" "))
209857
+ };
209858
+ },
209859
+ property(p) {
209860
+ const enumNode = narrowSchema(p.schema, "enum");
209861
+ if (enumNode && !enumNode.name) return {
209862
+ ...p,
209863
+ schema: {
209864
+ ...enumNode,
209865
+ name: pascalCase$6([
209866
+ parentName,
209867
+ p.name,
209868
+ "enum"
209869
+ ].join(" "))
209870
+ }
209871
+ };
209872
+ }
209873
+ });
209874
+ }
210577
209875
  const typeGenerator = defineGenerator({
210578
209876
  name: "typescript",
210579
209877
  type: "react",
210580
209878
  Operation({ node, adapter, options }) {
210581
- const { enumType, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group } = options;
210582
- const { mode, getFile, resolveName, resolveBanner, resolveFooter } = useKubb();
209879
+ var _a, _b;
209880
+ const { enumType, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group, resolver, legacy } = options;
209881
+ const { mode, getFile, resolveBanner, resolveFooter } = useKubb();
210583
209882
  const file = getFile({
210584
209883
  name: node.operationId,
210585
209884
  extname: ".ts",
210586
209885
  mode,
210587
- options: { group: group ? group.type === "tag" ? { tag: node.tags[0] } : { path: node.path } : void 0 }
209886
+ options: { group: group ? group.type === "tag" ? { tag: (_a = node.tags[0]) != null ? _a : "default" } : { path: node.path } : void 0 }
210588
209887
  });
210589
209888
  const params = applyParamsCasing$1(node.parameters, paramsCasing);
210590
- function renderSchemaType({ node: schemaNode, name, typedName, description }) {
209889
+ function renderSchemaType({ node: schemaNode, name, typedName, description, keysToOmit }) {
210591
209890
  if (!schemaNode) return null;
210592
209891
  const imports = adapter.getImports(schemaNode, (schemaName) => ({
210593
- name: resolveName({
210594
- name: schemaName,
210595
- type: "type"
210596
- }),
209892
+ name: resolver.default(schemaName, "type"),
210597
209893
  path: getFile({
210598
209894
  name: schemaName,
210599
209895
  extname: ".ts",
@@ -210618,52 +209914,126 @@ const typeGenerator = defineGenerator({
210618
209914
  enumKeyCasing,
210619
209915
  optionalType,
210620
209916
  arrayType,
210621
- syntaxType
209917
+ syntaxType,
209918
+ resolver,
209919
+ keysToOmit
210622
209920
  })] });
210623
209921
  }
210624
- const paramTypes = params.map((param) => renderSchemaType({
210625
- node: param.schema,
210626
- name: resolverTs.resolveParamName(node, param),
210627
- typedName: resolverTs.resolveParamTypedName(node, param)
210628
- }));
210629
- const responseTypes = node.responses.map((res) => renderSchemaType({
209922
+ const responseTypes = legacy ? node.responses.map((res) => {
209923
+ const responseName = resolver.resolveResponseStatusName(node, res.statusCode);
209924
+ return renderSchemaType({
209925
+ node: res.schema ? nameUnnamedEnums(res.schema, responseName) : res.schema,
209926
+ name: responseName,
209927
+ typedName: resolver.resolveResponseStatusTypedName(node, res.statusCode),
209928
+ description: res.description,
209929
+ keysToOmit: res.keysToOmit
209930
+ });
209931
+ }) : node.responses.map((res) => renderSchemaType({
210630
209932
  node: res.schema,
210631
- name: resolverTs.resolveResponseStatusName(node, res.statusCode),
210632
- typedName: resolverTs.resolveResponseStatusTypedName(node, res.statusCode),
210633
- description: res.description
209933
+ name: resolver.resolveResponseStatusName(node, res.statusCode),
209934
+ typedName: resolver.resolveResponseStatusTypedName(node, res.statusCode),
209935
+ description: res.description,
209936
+ keysToOmit: res.keysToOmit
210634
209937
  }));
210635
- const requestType = node.requestBody ? renderSchemaType({
210636
- node: node.requestBody,
210637
- name: resolverTs.resolveDataName(node),
210638
- typedName: resolverTs.resolveDataTypedName(node),
210639
- description: node.requestBody.description
209938
+ const requestType = ((_b = node.requestBody) == null ? void 0 : _b.schema) ? renderSchemaType({
209939
+ node: legacy ? nameUnnamedEnums(node.requestBody.schema, resolver.resolveDataName(node)) : node.requestBody.schema,
209940
+ name: resolver.resolveDataName(node),
209941
+ typedName: resolver.resolveDataTypedName(node),
209942
+ description: node.requestBody.schema.description,
209943
+ keysToOmit: node.requestBody.keysToOmit
210640
209944
  }) : null;
209945
+ if (legacy) {
209946
+ const pathParams = params.filter((p) => p.in === "path");
209947
+ const queryParams = params.filter((p) => p.in === "query");
209948
+ const headerParams = params.filter((p) => p.in === "header");
209949
+ const legacyParamTypes = [
209950
+ pathParams.length > 0 ? renderSchemaType({
209951
+ node: buildGroupedParamsSchema({
209952
+ params: pathParams,
209953
+ parentName: resolver.resolvePathParamsName(node)
209954
+ }),
209955
+ name: resolver.resolvePathParamsName(node),
209956
+ typedName: resolver.resolvePathParamsTypedName(node)
209957
+ }) : null,
209958
+ queryParams.length > 0 ? renderSchemaType({
209959
+ node: buildGroupedParamsSchema({
209960
+ params: queryParams,
209961
+ parentName: resolver.resolveQueryParamsName(node)
209962
+ }),
209963
+ name: resolver.resolveQueryParamsName(node),
209964
+ typedName: resolver.resolveQueryParamsTypedName(node)
209965
+ }) : null,
209966
+ headerParams.length > 0 ? renderSchemaType({
209967
+ node: buildGroupedParamsSchema({
209968
+ params: headerParams,
209969
+ parentName: resolver.resolveHeaderParamsName(node)
209970
+ }),
209971
+ name: resolver.resolveHeaderParamsName(node),
209972
+ typedName: resolver.resolveHeaderParamsTypedName(node)
209973
+ }) : null
209974
+ ];
209975
+ const legacyResponsesType = renderSchemaType({
209976
+ node: buildLegacyResponsesSchemaNode({
209977
+ node,
209978
+ resolver
209979
+ }),
209980
+ name: resolver.resolveResponsesName(node),
209981
+ typedName: resolver.resolveResponsesTypedName(node)
209982
+ });
209983
+ const legacyResponseType = renderSchemaType({
209984
+ node: buildLegacyResponseUnionSchemaNode({
209985
+ node,
209986
+ resolver
209987
+ }),
209988
+ name: resolver.resolveResponseName(node),
209989
+ typedName: resolver.resolveResponseTypedName(node)
209990
+ });
209991
+ return /* @__PURE__ */ jsxs(File, {
209992
+ baseName: file.baseName,
209993
+ path: file.path,
209994
+ meta: file.meta,
209995
+ banner: resolveBanner(),
209996
+ footer: resolveFooter(),
209997
+ children: [
209998
+ legacyParamTypes,
209999
+ responseTypes,
210000
+ requestType,
210001
+ legacyResponsesType,
210002
+ legacyResponseType
210003
+ ]
210004
+ });
210005
+ }
210006
+ const paramTypes = params.map((param) => renderSchemaType({
210007
+ node: param.schema,
210008
+ name: resolver.resolveParamName(node, param),
210009
+ typedName: resolver.resolveParamTypedName(node, param)
210010
+ }));
210641
210011
  const dataType = renderSchemaType({
210642
210012
  node: buildDataSchemaNode({
210643
210013
  node: {
210644
210014
  ...node,
210645
210015
  parameters: params
210646
210016
  },
210647
- resolveName
210017
+ resolver
210648
210018
  }),
210649
- name: resolverTs.resolveRequestConfigName(node),
210650
- typedName: resolverTs.resolveRequestConfigTypedName(node)
210019
+ name: resolver.resolveRequestConfigName(node),
210020
+ typedName: resolver.resolveRequestConfigTypedName(node)
210651
210021
  });
210652
210022
  const responsesType = renderSchemaType({
210653
210023
  node: buildResponsesSchemaNode({
210654
210024
  node,
210655
- resolveName
210025
+ resolver
210656
210026
  }),
210657
- name: resolverTs.resolveResponsesName(node),
210658
- typedName: resolverTs.resolveResponsesTypedName(node)
210027
+ name: resolver.resolveResponsesName(node),
210028
+ typedName: resolver.resolveResponsesTypedName(node)
210659
210029
  });
210660
210030
  const responseType = renderSchemaType({
210661
210031
  node: buildResponseUnionSchemaNode({
210662
210032
  node,
210663
- resolveName
210033
+ resolver
210664
210034
  }),
210665
- name: resolverTs.resolveResponseName(node),
210666
- typedName: resolverTs.resolveResponseTypedName(node),
210035
+ name: resolver.resolveResponseName(node),
210036
+ typedName: resolver.resolveResponseTypedName(node),
210667
210037
  description: "Union of all possible responses"
210668
210038
  });
210669
210039
  return /* @__PURE__ */ jsxs(File, {
@@ -210683,14 +210053,11 @@ const typeGenerator = defineGenerator({
210683
210053
  });
210684
210054
  },
210685
210055
  Schema({ node, adapter, options }) {
210686
- const { enumType, enumKeyCasing, syntaxType, optionalType, arrayType } = options;
210687
- const { mode, resolveName, getFile, resolveBanner, resolveFooter } = useKubb();
210056
+ const { enumType, enumKeyCasing, syntaxType, optionalType, arrayType, resolver } = options;
210057
+ const { mode, getFile, resolveBanner, resolveFooter } = useKubb();
210688
210058
  if (!node.name) return;
210689
210059
  const imports = adapter.getImports(node, (schemaName) => ({
210690
- name: resolveName({
210691
- name: schemaName,
210692
- type: "type"
210693
- }),
210060
+ name: resolver.default(schemaName, "type"),
210694
210061
  path: getFile({
210695
210062
  name: schemaName,
210696
210063
  extname: ".ts",
@@ -210698,9 +210065,9 @@ const typeGenerator = defineGenerator({
210698
210065
  }).path
210699
210066
  }));
210700
210067
  const isEnumSchema = node.type === "enum";
210701
- const typedName = ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && isEnumSchema ? resolverTs.resolveEnumKeyTypedName(node) : resolverTs.resolveTypedName(node.name);
210068
+ const typedName = ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && isEnumSchema ? resolver.resolveEnumKeyTypedName(node) : resolver.resolveTypedName(node.name);
210702
210069
  const type = {
210703
- name: resolverTs.resolveName(node.name),
210070
+ name: resolver.resolveName(node.name),
210704
210071
  typedName,
210705
210072
  file: getFile({
210706
210073
  name: node.name,
@@ -210731,38 +210098,176 @@ const typeGenerator = defineGenerator({
210731
210098
  enumKeyCasing,
210732
210099
  optionalType,
210733
210100
  arrayType,
210734
- syntaxType
210101
+ syntaxType,
210102
+ resolver
210735
210103
  })]
210736
210104
  });
210737
210105
  }
210738
210106
  });
210107
+
210108
+ function resolveName(name, type) {
210109
+ return pascalCase$6(name, { isFile: type === "file" });
210110
+ }
210111
+ const resolverTs = defineResolver(() => {
210112
+ return {
210113
+ default(name, type) {
210114
+ return resolveName(name, type);
210115
+ },
210116
+ resolveName(name) {
210117
+ return this.default(name, "function");
210118
+ },
210119
+ resolveTypedName(name) {
210120
+ return this.default(name, "type");
210121
+ },
210122
+ resolvePathName(name, type) {
210123
+ return this.default(name, type);
210124
+ },
210125
+ resolveParamName(node, param) {
210126
+ return this.resolveName(`${node.operationId} ${this.default(param.in)} ${param.name}`);
210127
+ },
210128
+ resolveParamTypedName(node, param) {
210129
+ return this.resolveTypedName(`${node.operationId} ${this.default(param.in)} ${param.name}`);
210130
+ },
210131
+ resolveResponseStatusName(node, statusCode) {
210132
+ return this.resolveName(`${node.operationId} Status ${statusCode}`);
210133
+ },
210134
+ resolveResponseStatusTypedName(node, statusCode) {
210135
+ return this.resolveTypedName(`${node.operationId} Status ${statusCode}`);
210136
+ },
210137
+ resolveDataName(node) {
210138
+ return this.resolveName(`${node.operationId} Data`);
210139
+ },
210140
+ resolveDataTypedName(node) {
210141
+ return this.resolveTypedName(`${node.operationId} Data`);
210142
+ },
210143
+ resolveRequestConfigName(node) {
210144
+ return this.resolveName(`${node.operationId} RequestConfig`);
210145
+ },
210146
+ resolveRequestConfigTypedName(node) {
210147
+ return this.resolveTypedName(`${node.operationId} RequestConfig`);
210148
+ },
210149
+ resolveResponsesName(node) {
210150
+ return this.resolveName(`${node.operationId} Responses`);
210151
+ },
210152
+ resolveResponsesTypedName(node) {
210153
+ return this.resolveTypedName(`${node.operationId} Responses`);
210154
+ },
210155
+ resolveResponseName(node) {
210156
+ return this.resolveName(`${node.operationId} Response`);
210157
+ },
210158
+ resolveResponseTypedName(node) {
210159
+ return this.resolveTypedName(`${node.operationId} Response`);
210160
+ },
210161
+ resolveEnumKeyTypedName(node) {
210162
+ var _a;
210163
+ return `${this.resolveTypedName((_a = node.name) != null ? _a : "")}Key`;
210164
+ },
210165
+ resolvePathParamsName(_node) {
210166
+ throw new Error("resolvePathParamsName is only available in legacy mode (legacy: true). Use resolveParamName per individual parameter instead.");
210167
+ },
210168
+ resolvePathParamsTypedName(_node) {
210169
+ throw new Error("resolvePathParamsTypedName is only available in legacy mode (legacy: true). Use resolveParamTypedName per individual parameter instead.");
210170
+ },
210171
+ resolveQueryParamsName(_node) {
210172
+ throw new Error("resolveQueryParamsName is only available in legacy mode (legacy: true). Use resolveParamName per individual parameter instead.");
210173
+ },
210174
+ resolveQueryParamsTypedName(_node) {
210175
+ throw new Error("resolveQueryParamsTypedName is only available in legacy mode (legacy: true). Use resolveParamTypedName per individual parameter instead.");
210176
+ },
210177
+ resolveHeaderParamsName(_node) {
210178
+ throw new Error("resolveHeaderParamsName is only available in legacy mode (legacy: true). Use resolveParamName per individual parameter instead.");
210179
+ },
210180
+ resolveHeaderParamsTypedName(_node) {
210181
+ throw new Error("resolveHeaderParamsTypedName is only available in legacy mode (legacy: true). Use resolveParamTypedName per individual parameter instead.");
210182
+ }
210183
+ };
210184
+ });
210185
+ const resolverTsLegacy = defineResolver(() => {
210186
+ return {
210187
+ ...resolverTs,
210188
+ resolveResponseStatusName(node, statusCode) {
210189
+ if (statusCode === "default") return this.resolveName(`${node.operationId} Error`);
210190
+ return this.resolveName(`${node.operationId} ${statusCode}`);
210191
+ },
210192
+ resolveResponseStatusTypedName(node, statusCode) {
210193
+ if (statusCode === "default") return this.resolveTypedName(`${node.operationId} Error`);
210194
+ return this.resolveTypedName(`${node.operationId} ${statusCode}`);
210195
+ },
210196
+ resolveDataName(node) {
210197
+ const suffix = node.method === "GET" ? "QueryRequest" : "MutationRequest";
210198
+ return this.resolveName(`${node.operationId} ${suffix}`);
210199
+ },
210200
+ resolveDataTypedName(node) {
210201
+ const suffix = node.method === "GET" ? "QueryRequest" : "MutationRequest";
210202
+ return this.resolveTypedName(`${node.operationId} ${suffix}`);
210203
+ },
210204
+ resolveResponsesName(node) {
210205
+ const suffix = node.method === "GET" ? "Query" : "Mutation";
210206
+ return this.resolveName(`${node.operationId} ${suffix}`);
210207
+ },
210208
+ resolveResponsesTypedName(node) {
210209
+ const suffix = node.method === "GET" ? "Query" : "Mutation";
210210
+ return this.resolveTypedName(`${node.operationId} ${suffix}`);
210211
+ },
210212
+ resolveResponseName(node) {
210213
+ const suffix = node.method === "GET" ? "QueryResponse" : "MutationResponse";
210214
+ return this.resolveName(`${node.operationId} ${suffix}`);
210215
+ },
210216
+ resolveResponseTypedName(node) {
210217
+ const suffix = node.method === "GET" ? "QueryResponse" : "MutationResponse";
210218
+ return this.resolveTypedName(`${node.operationId} ${suffix}`);
210219
+ },
210220
+ resolvePathParamsName(node) {
210221
+ return this.resolveName(`${node.operationId} PathParams`);
210222
+ },
210223
+ resolvePathParamsTypedName(node) {
210224
+ return this.resolveTypedName(`${node.operationId} PathParams`);
210225
+ },
210226
+ resolveQueryParamsName(node) {
210227
+ return this.resolveName(`${node.operationId} QueryParams`);
210228
+ },
210229
+ resolveQueryParamsTypedName(node) {
210230
+ return this.resolveTypedName(`${node.operationId} QueryParams`);
210231
+ },
210232
+ resolveHeaderParamsName(node) {
210233
+ return this.resolveName(`${node.operationId} HeaderParams`);
210234
+ },
210235
+ resolveHeaderParamsTypedName(node) {
210236
+ return this.resolveTypedName(`${node.operationId} HeaderParams`);
210237
+ }
210238
+ };
210239
+ });
210739
210240
  const pluginTsName = "plugin-ts";
210740
210241
  const pluginTs = createPlugin((options) => {
210741
210242
  const { output = {
210742
210243
  path: "types",
210743
210244
  barrelType: "named"
210744
- }, group, exclude = [], include, override = [], enumType = "asConst", enumKeyCasing = "none", enumSuffix = "enum", dateType = "string", integerType = "number", unknownType = "any", optionalType = "questionToken", arrayType = "array", emptySchemaType = unknownType, syntaxType = "type", transformers = {}, paramsCasing, generators = [typeGenerator$1, typeGenerator].filter(Boolean), contentType, UNSTABLE_NAMING } = options;
210245
+ }, group, exclude = [], include, override = [], enumType = "asConst", enumKeyCasing = "none", optionalType = "questionToken", arrayType = "array", syntaxType = "type", transformers = {}, paramsCasing, generators = [typeGenerator].filter(Boolean), legacy = false } = options;
210246
+ const baseResolver = legacy ? resolverTsLegacy : resolverTs;
210247
+ const resolver = (transformers == null ? void 0 : transformers.name) ? {
210248
+ ...baseResolver,
210249
+ default(name, type) {
210250
+ const resolved = baseResolver.default(name, type);
210251
+ return transformers.name(resolved, type) || resolved;
210252
+ }
210253
+ } : baseResolver;
210254
+ let resolveNameWarning = false;
210745
210255
  return {
210746
210256
  name: pluginTsName,
210747
210257
  options: {
210748
210258
  output,
210749
210259
  transformers,
210750
- dateType,
210751
- integerType,
210752
210260
  optionalType,
210753
210261
  arrayType,
210754
210262
  enumType,
210755
210263
  enumKeyCasing,
210756
- enumSuffix,
210757
- unknownType,
210758
- emptySchemaType,
210759
210264
  syntaxType,
210760
210265
  group,
210761
210266
  override,
210762
210267
  paramsCasing,
210763
- usedEnumNames: {}
210268
+ legacy,
210269
+ resolver
210764
210270
  },
210765
- pre: [pluginOasName],
210766
210271
  resolvePath(baseName, pathMode, options2) {
210767
210272
  var _a, _b;
210768
210273
  const root = path$2.resolve(this.config.root, this.config.output.path);
@@ -210778,109 +210283,71 @@ const pluginTs = createPlugin((options) => {
210778
210283
  return path$2.resolve(root, output.path, baseName);
210779
210284
  },
210780
210285
  resolveName(name, type) {
210781
- var _a;
210782
- const resolvedName = resolverTs.default(name, type);
210783
- if (type) return ((_a = transformers == null ? void 0 : transformers.name) == null ? void 0 : _a.call(transformers, resolvedName, type)) || resolvedName;
210784
- return resolvedName;
210286
+ if (!resolveNameWarning) {
210287
+ this.driver.events.emit("warn", "Do not use resolveName for pluginTs, use resolverTs instead");
210288
+ resolveNameWarning = true;
210289
+ }
210290
+ return resolver.default(name, type);
210785
210291
  },
210786
210292
  async install() {
210787
- var _a, _b;
210293
+ var _a;
210788
210294
  const { config, fabric, plugin, adapter, rootNode, driver, openInStudio } = this;
210789
210295
  const root = path$2.resolve(config.root, config.output.path);
210790
210296
  const mode = getMode(path$2.resolve(root, output.path));
210791
- if (adapter) {
210792
- await openInStudio({ ast: true });
210793
- await walk(rootNode, {
210794
- async schema(schemaNode) {
210795
- const writeTasks = generators.map(async (generator) => {
210796
- if (generator.type === "react" && generator.version === "2") {
210797
- const options2 = resolverTs.resolveOptions(schemaNode, {
210798
- options: plugin.options,
210799
- exclude,
210800
- include,
210801
- override
210802
- });
210803
- if (options2 === null) return;
210804
- await buildSchema(schemaNode, {
210805
- options: options2,
210806
- adapter,
210807
- config,
210808
- fabric,
210809
- Component: generator.Schema,
210810
- plugin,
210811
- driver,
210812
- mode,
210813
- version: generator.version
210814
- });
210815
- }
210816
- });
210817
- await Promise.all(writeTasks);
210818
- },
210819
- async operation(operationNode) {
210820
- const writeTasks = generators.map(async (generator) => {
210821
- if (generator.type === "react" && generator.version === "2") {
210822
- const options2 = resolverTs.resolveOptions(operationNode, {
210823
- options: plugin.options,
210824
- exclude,
210825
- include,
210826
- override
210827
- });
210828
- if (options2 === null) return;
210829
- await buildOperation(operationNode, {
210830
- options: options2,
210831
- adapter,
210832
- config,
210833
- fabric,
210834
- Component: generator.Operation,
210835
- plugin,
210836
- driver,
210837
- mode,
210838
- version: generator.version
210839
- });
210840
- }
210841
- });
210842
- await Promise.all(writeTasks);
210843
- }
210844
- }, { depth: "shallow" });
210845
- const barrelFiles2 = await getBarrelFiles(this.fabric.files, {
210846
- type: (_a = output.barrelType) != null ? _a : "named",
210847
- root,
210848
- output,
210849
- meta: { pluginName: this.plugin.name }
210850
- });
210851
- await this.upsertFile(...barrelFiles2);
210852
- return;
210853
- }
210854
- const oas = await this.getOas();
210855
- const schemaFiles = await new SchemaGenerator(this.plugin.options, {
210856
- fabric: this.fabric,
210857
- oas,
210858
- driver: this.driver,
210859
- events: this.events,
210860
- plugin: this.plugin,
210861
- contentType,
210862
- include: void 0,
210863
- override,
210864
- mode,
210865
- output: output.path
210866
- }).build(...generators);
210867
- await this.upsertFile(...schemaFiles);
210868
- const operationFiles = await new OperationGenerator(this.plugin.options, {
210869
- fabric: this.fabric,
210870
- oas,
210871
- driver: this.driver,
210872
- events: this.events,
210873
- plugin: this.plugin,
210874
- contentType,
210875
- exclude,
210876
- include,
210877
- override,
210878
- mode,
210879
- UNSTABLE_NAMING
210880
- }).build(...generators);
210881
- await this.upsertFile(...operationFiles);
210297
+ if (!adapter) throw new Error("Plugin cannot work without adapter being set");
210298
+ await openInStudio({ ast: true });
210299
+ await walk(rootNode, {
210300
+ async schema(schemaNode) {
210301
+ const writeTasks = generators.map(async (generator) => {
210302
+ if (generator.type === "react" && generator.version === "2") {
210303
+ const options2 = resolver.resolveOptions(schemaNode, {
210304
+ options: plugin.options,
210305
+ exclude,
210306
+ include,
210307
+ override
210308
+ });
210309
+ if (options2 === null) return;
210310
+ await renderSchema$1(schemaNode, {
210311
+ options: options2,
210312
+ adapter,
210313
+ config,
210314
+ fabric,
210315
+ Component: generator.Schema,
210316
+ plugin,
210317
+ driver,
210318
+ mode
210319
+ });
210320
+ }
210321
+ });
210322
+ await Promise.all(writeTasks);
210323
+ },
210324
+ async operation(operationNode) {
210325
+ const writeTasks = generators.map(async (generator) => {
210326
+ if (generator.type === "react" && generator.version === "2") {
210327
+ const options2 = resolver.resolveOptions(operationNode, {
210328
+ options: plugin.options,
210329
+ exclude,
210330
+ include,
210331
+ override
210332
+ });
210333
+ if (options2 === null) return;
210334
+ await renderOperation$1(operationNode, {
210335
+ options: options2,
210336
+ adapter,
210337
+ config,
210338
+ fabric,
210339
+ Component: generator.Operation,
210340
+ plugin,
210341
+ driver,
210342
+ mode
210343
+ });
210344
+ }
210345
+ });
210346
+ await Promise.all(writeTasks);
210347
+ }
210348
+ }, { depth: "shallow" });
210882
210349
  const barrelFiles = await getBarrelFiles(this.fabric.files, {
210883
- type: (_b = output.barrelType) != null ? _b : "named",
210350
+ type: (_a = output.barrelType) != null ? _a : "named",
210884
210351
  root,
210885
210352
  output,
210886
210353
  meta: { pluginName: this.plugin.name }
@@ -210890,6 +210357,172 @@ const pluginTs = createPlugin((options) => {
210890
210357
  };
210891
210358
  });
210892
210359
 
210360
+ function useOas() {
210361
+ const { meta } = useFabric();
210362
+ return meta.oas;
210363
+ }
210364
+ function useOperationManager(generator) {
210365
+ const plugin = usePlugin();
210366
+ const driver = usePluginDriver();
210367
+ const defaultPluginName = plugin.name;
210368
+ const getName = (operation, { prefix = "", suffix = "", pluginName = defaultPluginName, type }) => {
210369
+ return driver.resolveName({
210370
+ name: `${prefix} ${operation.getOperationId()} ${suffix}`,
210371
+ pluginName,
210372
+ type
210373
+ });
210374
+ };
210375
+ const getGroup = (operation) => {
210376
+ var _a, _b;
210377
+ return {
210378
+ tag: (_b = (_a = operation.getTags().at(0)) == null ? void 0 : _a.name) != null ? _b : "default",
210379
+ path: operation.path
210380
+ };
210381
+ };
210382
+ const getSchemas = (operation, params) => {
210383
+ if (!generator) throw new Error(`useOperationManager: 'generator' parameter is required but was not provided`);
210384
+ return generator.getSchemas(operation, { resolveName: (name) => {
210385
+ var _a;
210386
+ return driver.resolveName({
210387
+ name,
210388
+ pluginName: (_a = params == null ? void 0 : params.pluginName) != null ? _a : defaultPluginName,
210389
+ type: params == null ? void 0 : params.type
210390
+ });
210391
+ } });
210392
+ };
210393
+ const getFile = (operation, { prefix, suffix, pluginName = defaultPluginName, extname = ".ts" } = {}) => {
210394
+ const name = getName(operation, {
210395
+ type: "file",
210396
+ pluginName,
210397
+ prefix,
210398
+ suffix
210399
+ });
210400
+ const group = getGroup(operation);
210401
+ const file = driver.getFile({
210402
+ name,
210403
+ extname,
210404
+ pluginName,
210405
+ options: {
210406
+ type: "file",
210407
+ pluginName,
210408
+ group
210409
+ }
210410
+ });
210411
+ return {
210412
+ ...file,
210413
+ meta: {
210414
+ ...file.meta,
210415
+ name,
210416
+ pluginName,
210417
+ group
210418
+ }
210419
+ };
210420
+ };
210421
+ const groupSchemasByName = (operation, { pluginName = defaultPluginName, type }) => {
210422
+ var _a, _b, _c, _d;
210423
+ if (!generator) throw new Error(`useOperationManager: 'generator' parameter is required but was not provided`);
210424
+ const schemas = getSchemas(operation);
210425
+ const errors = (schemas.errors || []).reduce((prev, acc) => {
210426
+ if (!acc.statusCode) return prev;
210427
+ prev[acc.statusCode] = driver.resolveName({
210428
+ name: acc.name,
210429
+ pluginName,
210430
+ type
210431
+ });
210432
+ return prev;
210433
+ }, {});
210434
+ const responses = (schemas.responses || []).reduce((prev, acc) => {
210435
+ if (!acc.statusCode) return prev;
210436
+ prev[acc.statusCode] = driver.resolveName({
210437
+ name: acc.name,
210438
+ pluginName,
210439
+ type
210440
+ });
210441
+ return prev;
210442
+ }, {});
210443
+ return {
210444
+ request: ((_a = schemas.request) == null ? void 0 : _a.name) ? driver.resolveName({
210445
+ name: schemas.request.name,
210446
+ pluginName,
210447
+ type
210448
+ }) : void 0,
210449
+ parameters: {
210450
+ path: ((_b = schemas.pathParams) == null ? void 0 : _b.name) ? driver.resolveName({
210451
+ name: schemas.pathParams.name,
210452
+ pluginName,
210453
+ type
210454
+ }) : void 0,
210455
+ query: ((_c = schemas.queryParams) == null ? void 0 : _c.name) ? driver.resolveName({
210456
+ name: schemas.queryParams.name,
210457
+ pluginName,
210458
+ type
210459
+ }) : void 0,
210460
+ header: ((_d = schemas.headerParams) == null ? void 0 : _d.name) ? driver.resolveName({
210461
+ name: schemas.headerParams.name,
210462
+ pluginName,
210463
+ type
210464
+ }) : void 0
210465
+ },
210466
+ responses: {
210467
+ ...responses,
210468
+ ["default"]: driver.resolveName({
210469
+ name: schemas.response.name,
210470
+ pluginName,
210471
+ type
210472
+ }),
210473
+ ...errors
210474
+ },
210475
+ errors
210476
+ };
210477
+ };
210478
+ return {
210479
+ getName,
210480
+ getFile,
210481
+ getSchemas,
210482
+ groupSchemasByName,
210483
+ getGroup
210484
+ };
210485
+ }
210486
+ function useSchemaManager() {
210487
+ const plugin = usePlugin();
210488
+ const driver = usePluginDriver();
210489
+ const getName = (name, { pluginName = plugin.name, type }) => {
210490
+ return driver.resolveName({
210491
+ name,
210492
+ pluginName,
210493
+ type
210494
+ });
210495
+ };
210496
+ const getFile = (name, { mode = "split", pluginName = plugin.name, extname = ".ts", group } = {}) => {
210497
+ const resolvedName = mode === "single" ? "" : getName(name, {
210498
+ type: "file",
210499
+ pluginName
210500
+ });
210501
+ const file = driver.getFile({
210502
+ name: resolvedName,
210503
+ extname,
210504
+ pluginName,
210505
+ options: {
210506
+ type: "file",
210507
+ pluginName,
210508
+ group
210509
+ }
210510
+ });
210511
+ return {
210512
+ ...file,
210513
+ meta: {
210514
+ ...file.meta,
210515
+ name: resolvedName,
210516
+ pluginName
210517
+ }
210518
+ };
210519
+ };
210520
+ return {
210521
+ getName,
210522
+ getFile
210523
+ };
210524
+ }
210525
+
210893
210526
  const operationsGenerator$1 = createReactGenerator({
210894
210527
  name: "operations",
210895
210528
  Operations({ operations, generator, plugin }) {
@@ -211174,7 +210807,7 @@ function toCamelOrPascal$9(text, pascal) {
211174
210807
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
211175
210808
  }
211176
210809
  function applyToFileParts$9(text, transformPart) {
211177
- const parts = text.split(".");
210810
+ const parts = text.split(/\.(?=[a-zA-Z])/);
211178
210811
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
211179
210812
  }
211180
210813
  function camelCase$9(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -211321,7 +210954,7 @@ const classClientGenerator = createReactGenerator({
211321
210954
  const driver = usePluginDriver();
211322
210955
  const oas = useOas();
211323
210956
  const { getName, getFile, getGroup, getSchemas } = useOperationManager(generator);
211324
- function buildOperationData(operation) {
210957
+ function renderOperationData(operation) {
211325
210958
  const type = {
211326
210959
  file: getFile(operation, { pluginName: pluginTsName }),
211327
210960
  schemas: getSchemas(operation, {
@@ -211356,7 +210989,7 @@ const classClientGenerator = createReactGenerator({
211356
210989
  extname: ".ts",
211357
210990
  pluginName
211358
210991
  });
211359
- const operationData = buildOperationData(operation);
210992
+ const operationData = renderOperationData(operation);
211360
210993
  const previousFile = acc.find((item) => item.file.path === file.path);
211361
210994
  if (previousFile) previousFile.operations.push(operationData);
211362
210995
  else acc.push({
@@ -211372,7 +211005,7 @@ const classClientGenerator = createReactGenerator({
211372
211005
  pluginName,
211373
211006
  options: { group }
211374
211007
  });
211375
- const operationData = buildOperationData(operation);
211008
+ const operationData = renderOperationData(operation);
211376
211009
  const previousFile = acc.find((item) => item.file.path === file.path);
211377
211010
  if (previousFile) previousFile.operations.push(operationData);
211378
211011
  else acc.push({
@@ -211798,7 +211431,7 @@ const staticClassClientGenerator = createReactGenerator({
211798
211431
  const driver = usePluginDriver();
211799
211432
  const oas = useOas();
211800
211433
  const { getName, getFile, getGroup, getSchemas } = useOperationManager(generator);
211801
- function buildOperationData(operation) {
211434
+ function renderOperationData(operation) {
211802
211435
  const type = {
211803
211436
  file: getFile(operation, { pluginName: pluginTsName }),
211804
211437
  schemas: getSchemas(operation, {
@@ -211833,7 +211466,7 @@ const staticClassClientGenerator = createReactGenerator({
211833
211466
  extname: ".ts",
211834
211467
  pluginName
211835
211468
  });
211836
- const operationData = buildOperationData(operation);
211469
+ const operationData = renderOperationData(operation);
211837
211470
  const previousFile = acc.find((item) => item.file.path === file.path);
211838
211471
  if (previousFile) previousFile.operations.push(operationData);
211839
211472
  else acc.push({
@@ -211849,7 +211482,7 @@ const staticClassClientGenerator = createReactGenerator({
211849
211482
  pluginName,
211850
211483
  options: { group }
211851
211484
  });
211852
- const operationData = buildOperationData(operation);
211485
+ const operationData = renderOperationData(operation);
211853
211486
  const previousFile = acc.find((item) => item.file.path === file.path);
211854
211487
  if (previousFile) previousFile.operations.push(operationData);
211855
211488
  else acc.push({
@@ -212141,7 +211774,7 @@ function toCamelOrPascal$8(text, pascal) {
212141
211774
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
212142
211775
  }
212143
211776
  function applyToFileParts$8(text, transformPart) {
212144
- const parts = text.split(".");
211777
+ const parts = text.split(/\.(?=[a-zA-Z])/);
212145
211778
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
212146
211779
  }
212147
211780
  function camelCase$8(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -213050,7 +212683,7 @@ function toCamelOrPascal$7(text, pascal) {
213050
212683
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
213051
212684
  }
213052
212685
  function applyToFileParts$7(text, transformPart) {
213053
- const parts = text.split(".");
212686
+ const parts = text.split(/\.(?=[a-zA-Z])/);
213054
212687
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
213055
212688
  }
213056
212689
  function camelCase$7(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -213158,7 +212791,7 @@ function toCamelOrPascal$6(text, pascal) {
213158
212791
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
213159
212792
  }
213160
212793
  function applyToFileParts$6(text, transformPart) {
213161
- const parts = text.split(".");
212794
+ const parts = text.split(/\.(?=[a-zA-Z])/);
213162
212795
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
213163
212796
  }
213164
212797
  function camelCase$6(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -213676,7 +213309,7 @@ function toCamelOrPascal$5(text, pascal) {
213676
213309
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
213677
213310
  }
213678
213311
  function applyToFileParts$5(text, transformPart) {
213679
- const parts = text.split(".");
213312
+ const parts = text.split(/\.(?=[a-zA-Z])/);
213680
213313
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
213681
213314
  }
213682
213315
  function camelCase$5(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -214140,7 +213773,7 @@ function toCamelOrPascal$4(text, pascal) {
214140
213773
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
214141
213774
  }
214142
213775
  function applyToFileParts$4(text, transformPart) {
214143
- const parts = text.split(".");
213776
+ const parts = text.split(/\.(?=[a-zA-Z])/);
214144
213777
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
214145
213778
  }
214146
213779
  function camelCase$4(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -214293,7 +213926,7 @@ function MutationKey$4({ name, typeSchemas, pathParamsType, paramsCasing, operat
214293
213926
  isExportable: true,
214294
213927
  isIndexable: true,
214295
213928
  isTypeOnly: true,
214296
- children: /* @__PURE__ */ jsx(Type$2, {
213929
+ children: /* @__PURE__ */ jsx(Type$1, {
214297
213930
  name: typeName,
214298
213931
  export: true,
214299
213932
  children: `ReturnType<typeof ${name}>`
@@ -214361,7 +213994,7 @@ function QueryKey$4({ name, typeSchemas, paramsCasing, pathParamsType, operation
214361
213994
  isExportable: true,
214362
213995
  isIndexable: true,
214363
213996
  isTypeOnly: true,
214364
- children: /* @__PURE__ */ jsx(Type$2, {
213997
+ children: /* @__PURE__ */ jsx(Type$1, {
214365
213998
  name: typeName,
214366
213999
  export: true,
214367
214000
  children: `ReturnType<typeof ${name}>`
@@ -215854,7 +215487,7 @@ const hookOptionsGenerator = createReactGenerator({
215854
215487
  isExportable: true,
215855
215488
  isIndexable: true,
215856
215489
  isTypeOnly: true,
215857
- children: /* @__PURE__ */ jsx(Type$2, {
215490
+ children: /* @__PURE__ */ jsx(Type$1, {
215858
215491
  export: true,
215859
215492
  name,
215860
215493
  children: `{ ${Object.keys(hookOptions).map((key) => `${JSON.stringify(key)}: ${hookOptions[key]}`)} }`
@@ -217215,7 +216848,7 @@ function toCamelOrPascal$3(text, pascal) {
217215
216848
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
217216
216849
  }
217217
216850
  function applyToFileParts$3(text, transformPart) {
217218
- const parts = text.split(".");
216851
+ const parts = text.split(/\.(?=[a-zA-Z])/);
217219
216852
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
217220
216853
  }
217221
216854
  function camelCase$3(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -217363,7 +216996,7 @@ function MutationKey$3({ name, typeSchemas, pathParamsType, paramsCasing, operat
217363
216996
  isExportable: true,
217364
216997
  isIndexable: true,
217365
216998
  isTypeOnly: true,
217366
- children: /* @__PURE__ */ jsx(Type$2, {
216999
+ children: /* @__PURE__ */ jsx(Type$1, {
217367
217000
  name: typeName,
217368
217001
  export: true,
217369
217002
  children: `ReturnType<typeof ${name}>`
@@ -217431,7 +217064,7 @@ function QueryKey$3({ name, typeSchemas, paramsCasing, pathParamsType, operation
217431
217064
  isExportable: true,
217432
217065
  isIndexable: true,
217433
217066
  isTypeOnly: true,
217434
- children: /* @__PURE__ */ jsx(Type$2, {
217067
+ children: /* @__PURE__ */ jsx(Type$1, {
217435
217068
  name: typeName,
217436
217069
  export: true,
217437
217070
  children: `ReturnType<typeof ${name}>`
@@ -218365,7 +217998,7 @@ function toCamelOrPascal$2(text, pascal) {
218365
217998
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
218366
217999
  }
218367
218000
  function applyToFileParts$2(text, transformPart) {
218368
- const parts = text.split(".");
218001
+ const parts = text.split(/\.(?=[a-zA-Z])/);
218369
218002
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
218370
218003
  }
218371
218004
  function camelCase$2(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -218513,7 +218146,7 @@ function MutationKey$2({ name, typeSchemas, pathParamsType, paramsCasing, operat
218513
218146
  isExportable: true,
218514
218147
  isIndexable: true,
218515
218148
  isTypeOnly: true,
218516
- children: /* @__PURE__ */ jsx(Type$2, {
218149
+ children: /* @__PURE__ */ jsx(Type$1, {
218517
218150
  name: typeName,
218518
218151
  export: true,
218519
218152
  children: `ReturnType<typeof ${name}>`
@@ -218581,7 +218214,7 @@ function QueryKey$2({ name, typeSchemas, paramsCasing, pathParamsType, operation
218581
218214
  isExportable: true,
218582
218215
  isIndexable: true,
218583
218216
  isTypeOnly: true,
218584
- children: /* @__PURE__ */ jsx(Type$2, {
218217
+ children: /* @__PURE__ */ jsx(Type$1, {
218585
218218
  name: typeName,
218586
218219
  export: true,
218587
218220
  children: `ReturnType<typeof ${name}>`
@@ -219515,7 +219148,7 @@ function toCamelOrPascal$1(text, pascal) {
219515
219148
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
219516
219149
  }
219517
219150
  function applyToFileParts$1(text, transformPart) {
219518
- const parts = text.split(".");
219151
+ const parts = text.split(/\.(?=[a-zA-Z])/);
219519
219152
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
219520
219153
  }
219521
219154
  function camelCase$1(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -219663,7 +219296,7 @@ function MutationKey$1({ name, typeSchemas, pathParamsType, paramsCasing, operat
219663
219296
  isExportable: true,
219664
219297
  isIndexable: true,
219665
219298
  isTypeOnly: true,
219666
- children: /* @__PURE__ */ jsx(Type$2, {
219299
+ children: /* @__PURE__ */ jsx(Type$1, {
219667
219300
  name: typeName,
219668
219301
  export: true,
219669
219302
  children: `ReturnType<typeof ${name}>`
@@ -219731,7 +219364,7 @@ function QueryKey$1({ name, typeSchemas, paramsCasing, pathParamsType, operation
219731
219364
  isExportable: true,
219732
219365
  isIndexable: true,
219733
219366
  isTypeOnly: true,
219734
- children: /* @__PURE__ */ jsx(Type$2, {
219367
+ children: /* @__PURE__ */ jsx(Type$1, {
219735
219368
  name: typeName,
219736
219369
  export: true,
219737
219370
  children: `ReturnType<typeof ${name}>`
@@ -219860,7 +219493,7 @@ function Mutation$1({ name, clientName, mutationKeyName, mutationKeyTypeName, pa
219860
219493
  isExportable: true,
219861
219494
  isIndexable: true,
219862
219495
  isTypeOnly: true,
219863
- children: /* @__PURE__ */ jsx(Type$2, {
219496
+ children: /* @__PURE__ */ jsx(Type$1, {
219864
219497
  name: mutationArgTypeName,
219865
219498
  export: true,
219866
219499
  children: hasMutationParams ? `{${mutationArg}}` : "never"
@@ -220687,7 +220320,7 @@ function toCamelOrPascal(text, pascal) {
220687
220320
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
220688
220321
  }
220689
220322
  function applyToFileParts(text, transformPart) {
220690
- const parts = text.split(".");
220323
+ const parts = text.split(/\.(?=[a-zA-Z])/);
220691
220324
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
220692
220325
  }
220693
220326
  function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -220874,7 +220507,7 @@ function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation,
220874
220507
  isExportable: true,
220875
220508
  isIndexable: true,
220876
220509
  isTypeOnly: true,
220877
- children: /* @__PURE__ */ jsx(Type$2, {
220510
+ children: /* @__PURE__ */ jsx(Type$1, {
220878
220511
  name: typeName,
220879
220512
  export: true,
220880
220513
  children: `ReturnType<typeof ${name}>`
@@ -221352,7 +220985,7 @@ function MutationKey({ name, typeSchemas, pathParamsType, paramsCasing, operatio
221352
220985
  isExportable: true,
221353
220986
  isIndexable: true,
221354
220987
  isTypeOnly: true,
221355
- children: /* @__PURE__ */ jsx(Type$2, {
220988
+ children: /* @__PURE__ */ jsx(Type$1, {
221356
220989
  name: typeName,
221357
220990
  export: true,
221358
220991
  children: `ReturnType<typeof ${name}>`