@codewithagents/openapi-server 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.cjs CHANGED
@@ -277,24 +277,24 @@ var require_normalize = __commonJS({
277
277
  };
278
278
  }
279
279
  exports2.normalizeOptions = normalizeOptions;
280
- function normalizeArgs(args2, options) {
280
+ function normalizeArgs(args, options) {
281
281
  let originalError;
282
282
  let props;
283
283
  let formatArgs;
284
284
  let message = "";
285
- if (typeof args2[0] === "string") {
286
- formatArgs = args2;
287
- } else if (typeof args2[1] === "string") {
288
- if (args2[0] instanceof Error) {
289
- originalError = args2[0];
285
+ if (typeof args[0] === "string") {
286
+ formatArgs = args;
287
+ } else if (typeof args[1] === "string") {
288
+ if (args[0] instanceof Error) {
289
+ originalError = args[0];
290
290
  } else {
291
- props = args2[0];
291
+ props = args[0];
292
292
  }
293
- formatArgs = args2.slice(1);
293
+ formatArgs = args.slice(1);
294
294
  } else {
295
- originalError = args2[0];
296
- props = args2[1];
297
- formatArgs = args2.slice(2);
295
+ originalError = args[0];
296
+ props = args[1];
297
+ formatArgs = args.slice(2);
298
298
  }
299
299
  if (formatArgs.length > 0) {
300
300
  if (options.format) {
@@ -325,8 +325,8 @@ var require_constructor = __commonJS({
325
325
  exports2.Ono = constructor;
326
326
  function Ono(ErrorConstructor, options) {
327
327
  options = normalize_1.normalizeOptions(options);
328
- function ono(...args2) {
329
- let { originalError, props, message } = normalize_1.normalizeArgs(args2, options);
328
+ function ono(...args) {
329
+ let { originalError, props, message } = normalize_1.normalizeArgs(args, options);
330
330
  let newError = new ErrorConstructor(message);
331
331
  return extend_error_1.extendError(newError, originalError, props);
332
332
  }
@@ -365,19 +365,19 @@ var require_singleton = __commonJS({
365
365
  ono.type = new constructor_1.Ono(TypeError);
366
366
  ono.uri = new constructor_1.Ono(URIError);
367
367
  var onoMap = ono;
368
- function ono(...args2) {
369
- let originalError = args2[0];
368
+ function ono(...args) {
369
+ let originalError = args[0];
370
370
  if (typeof originalError === "object" && typeof originalError.name === "string") {
371
371
  for (let typedOno of Object.values(onoMap)) {
372
372
  if (typeof typedOno === "function" && typedOno.name === "ono") {
373
373
  let species = typedOno[Symbol.species];
374
374
  if (species && species !== Error && (originalError instanceof species || originalError.name === species.name)) {
375
- return typedOno.apply(void 0, args2);
375
+ return typedOno.apply(void 0, args);
376
376
  }
377
377
  }
378
378
  }
379
379
  }
380
- return ono.error.apply(void 0, args2);
380
+ return ono.error.apply(void 0, args);
381
381
  }
382
382
  }
383
383
  });
@@ -482,23 +482,23 @@ var require_code = __commonJS({
482
482
  };
483
483
  exports2._Code = _Code;
484
484
  exports2.nil = new _Code("");
485
- function _(strs, ...args2) {
485
+ function _(strs, ...args) {
486
486
  const code = [strs[0]];
487
487
  let i = 0;
488
- while (i < args2.length) {
489
- addCodeArg(code, args2[i]);
488
+ while (i < args.length) {
489
+ addCodeArg(code, args[i]);
490
490
  code.push(strs[++i]);
491
491
  }
492
492
  return new _Code(code);
493
493
  }
494
494
  exports2._ = _;
495
495
  var plus = new _Code("+");
496
- function str(strs, ...args2) {
496
+ function str(strs, ...args) {
497
497
  const expr = [safeStringify(strs[0])];
498
498
  let i = 0;
499
- while (i < args2.length) {
499
+ while (i < args.length) {
500
500
  expr.push(plus);
501
- addCodeArg(expr, args2[i]);
501
+ addCodeArg(expr, args[i]);
502
502
  expr.push(plus, safeStringify(strs[++i]));
503
503
  }
504
504
  optimize(expr);
@@ -1053,10 +1053,10 @@ var require_codegen = __commonJS({
1053
1053
  }
1054
1054
  };
1055
1055
  var Func = class extends BlockNode {
1056
- constructor(name, args2, async) {
1056
+ constructor(name, args, async) {
1057
1057
  super();
1058
1058
  this.name = name;
1059
- this.args = args2;
1059
+ this.args = args;
1060
1060
  this.async = async;
1061
1061
  }
1062
1062
  render(opts) {
@@ -1331,8 +1331,8 @@ var require_codegen = __commonJS({
1331
1331
  return this;
1332
1332
  }
1333
1333
  // `function` heading (or definition if funcBody is passed)
1334
- func(name, args2 = code_1.nil, async, funcBody) {
1335
- this._blockNode(new Func(name, args2, async));
1334
+ func(name, args = code_1.nil, async, funcBody) {
1335
+ this._blockNode(new Func(name, args, async));
1336
1336
  if (funcBody)
1337
1337
  this.code(funcBody).endFunc();
1338
1338
  return this;
@@ -1426,13 +1426,13 @@ var require_codegen = __commonJS({
1426
1426
  }
1427
1427
  exports2.not = not;
1428
1428
  var andCode = mappend(exports2.operators.AND);
1429
- function and(...args2) {
1430
- return args2.reduce(andCode);
1429
+ function and(...args) {
1430
+ return args.reduce(andCode);
1431
1431
  }
1432
1432
  exports2.and = and;
1433
1433
  var orCode = mappend(exports2.operators.OR);
1434
- function or(...args2) {
1435
- return args2.reduce(orCode);
1434
+ function or(...args) {
1435
+ return args.reduce(orCode);
1436
1436
  }
1437
1437
  exports2.or = or;
1438
1438
  function mappend(op) {
@@ -2165,8 +2165,8 @@ var require_code2 = __commonJS({
2165
2165
  ];
2166
2166
  if (it.opts.dynamicRef)
2167
2167
  valCxt.push([names_1.default.dynamicAnchors, names_1.default.dynamicAnchors]);
2168
- const args2 = (0, codegen_1._)`${dataAndSchema}, ${gen.object(...valCxt)}`;
2169
- return context !== codegen_1.nil ? (0, codegen_1._)`${func}.call(${context}, ${args2})` : (0, codegen_1._)`${func}(${args2})`;
2168
+ const args = (0, codegen_1._)`${dataAndSchema}, ${gen.object(...valCxt)}`;
2169
+ return context !== codegen_1.nil ? (0, codegen_1._)`${func}.call(${context}, ${args})` : (0, codegen_1._)`${func}(${args})`;
2170
2170
  }
2171
2171
  exports2.callValidateCode = callValidateCode;
2172
2172
  var newRegExp = (0, codegen_1._)`new RegExp`;
@@ -4161,18 +4161,18 @@ var require_fast_uri = __commonJS({
4161
4161
  return uriTokens.join("");
4162
4162
  }
4163
4163
  var URI_PARSE = /^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u;
4164
- function getParseError(parsed, matches) {
4165
- if (matches[2] !== void 0 && parsed.path && parsed.path[0] !== "/") {
4164
+ function getParseError(parsed2, matches) {
4165
+ if (matches[2] !== void 0 && parsed2.path && parsed2.path[0] !== "/") {
4166
4166
  return 'URI path must start with "/" when authority is present.';
4167
4167
  }
4168
- if (typeof parsed.port === "number" && (parsed.port < 0 || parsed.port > 65535)) {
4168
+ if (typeof parsed2.port === "number" && (parsed2.port < 0 || parsed2.port > 65535)) {
4169
4169
  return "URI port is malformed.";
4170
4170
  }
4171
4171
  return void 0;
4172
4172
  }
4173
4173
  function parseWithStatus(uri, opts) {
4174
4174
  const options = Object.assign({}, opts);
4175
- const parsed = {
4175
+ const parsed2 = {
4176
4176
  scheme: void 0,
4177
4177
  userinfo: void 0,
4178
4178
  host: "",
@@ -4192,80 +4192,80 @@ var require_fast_uri = __commonJS({
4192
4192
  }
4193
4193
  const matches = uri.match(URI_PARSE);
4194
4194
  if (matches) {
4195
- parsed.scheme = matches[1];
4196
- parsed.userinfo = matches[3];
4197
- parsed.host = matches[4];
4198
- parsed.port = parseInt(matches[5], 10);
4199
- parsed.path = matches[6] || "";
4200
- parsed.query = matches[7];
4201
- parsed.fragment = matches[8];
4202
- if (isNaN(parsed.port)) {
4203
- parsed.port = matches[5];
4204
- }
4205
- const parseError = getParseError(parsed, matches);
4195
+ parsed2.scheme = matches[1];
4196
+ parsed2.userinfo = matches[3];
4197
+ parsed2.host = matches[4];
4198
+ parsed2.port = parseInt(matches[5], 10);
4199
+ parsed2.path = matches[6] || "";
4200
+ parsed2.query = matches[7];
4201
+ parsed2.fragment = matches[8];
4202
+ if (isNaN(parsed2.port)) {
4203
+ parsed2.port = matches[5];
4204
+ }
4205
+ const parseError = getParseError(parsed2, matches);
4206
4206
  if (parseError !== void 0) {
4207
- parsed.error = parsed.error || parseError;
4207
+ parsed2.error = parsed2.error || parseError;
4208
4208
  malformedAuthorityOrPort = true;
4209
4209
  }
4210
- if (parsed.host) {
4211
- const ipv4result = isIPv4(parsed.host);
4210
+ if (parsed2.host) {
4211
+ const ipv4result = isIPv4(parsed2.host);
4212
4212
  if (ipv4result === false) {
4213
- const ipv6result = normalizeIPv6(parsed.host);
4214
- parsed.host = ipv6result.host.toLowerCase();
4213
+ const ipv6result = normalizeIPv6(parsed2.host);
4214
+ parsed2.host = ipv6result.host.toLowerCase();
4215
4215
  isIP = ipv6result.isIPV6;
4216
4216
  } else {
4217
4217
  isIP = true;
4218
4218
  }
4219
4219
  }
4220
- if (parsed.scheme === void 0 && parsed.userinfo === void 0 && parsed.host === void 0 && parsed.port === void 0 && parsed.query === void 0 && !parsed.path) {
4221
- parsed.reference = "same-document";
4222
- } else if (parsed.scheme === void 0) {
4223
- parsed.reference = "relative";
4224
- } else if (parsed.fragment === void 0) {
4225
- parsed.reference = "absolute";
4220
+ if (parsed2.scheme === void 0 && parsed2.userinfo === void 0 && parsed2.host === void 0 && parsed2.port === void 0 && parsed2.query === void 0 && !parsed2.path) {
4221
+ parsed2.reference = "same-document";
4222
+ } else if (parsed2.scheme === void 0) {
4223
+ parsed2.reference = "relative";
4224
+ } else if (parsed2.fragment === void 0) {
4225
+ parsed2.reference = "absolute";
4226
4226
  } else {
4227
- parsed.reference = "uri";
4227
+ parsed2.reference = "uri";
4228
4228
  }
4229
- if (options.reference && options.reference !== "suffix" && options.reference !== parsed.reference) {
4230
- parsed.error = parsed.error || "URI is not a " + options.reference + " reference.";
4229
+ if (options.reference && options.reference !== "suffix" && options.reference !== parsed2.reference) {
4230
+ parsed2.error = parsed2.error || "URI is not a " + options.reference + " reference.";
4231
4231
  }
4232
- const schemeHandler = getSchemeHandler(options.scheme || parsed.scheme);
4232
+ const schemeHandler = getSchemeHandler(options.scheme || parsed2.scheme);
4233
4233
  if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
4234
- if (parsed.host && (options.domainHost || schemeHandler && schemeHandler.domainHost) && isIP === false && nonSimpleDomain(parsed.host)) {
4234
+ if (parsed2.host && (options.domainHost || schemeHandler && schemeHandler.domainHost) && isIP === false && nonSimpleDomain(parsed2.host)) {
4235
4235
  try {
4236
- parsed.host = URL.domainToASCII(parsed.host.toLowerCase());
4236
+ parsed2.host = URL.domainToASCII(parsed2.host.toLowerCase());
4237
4237
  } catch (e) {
4238
- parsed.error = parsed.error || "Host's domain name can not be converted to ASCII: " + e;
4238
+ parsed2.error = parsed2.error || "Host's domain name can not be converted to ASCII: " + e;
4239
4239
  }
4240
4240
  }
4241
4241
  }
4242
4242
  if (!schemeHandler || schemeHandler && !schemeHandler.skipNormalize) {
4243
4243
  if (uri.indexOf("%") !== -1) {
4244
- if (parsed.scheme !== void 0) {
4245
- parsed.scheme = unescape(parsed.scheme);
4244
+ if (parsed2.scheme !== void 0) {
4245
+ parsed2.scheme = unescape(parsed2.scheme);
4246
4246
  }
4247
- if (parsed.host !== void 0) {
4248
- parsed.host = reescapeHostDelimiters(unescape(parsed.host), isIP);
4247
+ if (parsed2.host !== void 0) {
4248
+ parsed2.host = reescapeHostDelimiters(unescape(parsed2.host), isIP);
4249
4249
  }
4250
4250
  }
4251
- if (parsed.path) {
4252
- parsed.path = normalizePathEncoding(parsed.path);
4251
+ if (parsed2.path) {
4252
+ parsed2.path = normalizePathEncoding(parsed2.path);
4253
4253
  }
4254
- if (parsed.fragment) {
4254
+ if (parsed2.fragment) {
4255
4255
  try {
4256
- parsed.fragment = encodeURI(decodeURIComponent(parsed.fragment));
4256
+ parsed2.fragment = encodeURI(decodeURIComponent(parsed2.fragment));
4257
4257
  } catch {
4258
- parsed.error = parsed.error || "URI malformed";
4258
+ parsed2.error = parsed2.error || "URI malformed";
4259
4259
  }
4260
4260
  }
4261
4261
  }
4262
4262
  if (schemeHandler && schemeHandler.parse) {
4263
- schemeHandler.parse(parsed, options);
4263
+ schemeHandler.parse(parsed2, options);
4264
4264
  }
4265
4265
  } else {
4266
- parsed.error = parsed.error || "URI can not be parsed.";
4266
+ parsed2.error = parsed2.error || "URI can not be parsed.";
4267
4267
  }
4268
- return { parsed, malformedAuthorityOrPort };
4268
+ return { parsed: parsed2, malformedAuthorityOrPort };
4269
4269
  }
4270
4270
  function parse(uri, opts) {
4271
4271
  return parseWithStatus(uri, opts).parsed;
@@ -4274,9 +4274,9 @@ var require_fast_uri = __commonJS({
4274
4274
  return normalizeStringWithStatus(uri, opts).normalized;
4275
4275
  }
4276
4276
  function normalizeStringWithStatus(uri, opts) {
4277
- const { parsed, malformedAuthorityOrPort } = parseWithStatus(uri, opts);
4277
+ const { parsed: parsed2, malformedAuthorityOrPort } = parseWithStatus(uri, opts);
4278
4278
  return {
4279
- normalized: malformedAuthorityOrPort ? uri : serialize(parsed, opts),
4279
+ normalized: malformedAuthorityOrPort ? uri : serialize(parsed2, opts),
4280
4280
  malformedAuthorityOrPort
4281
4281
  };
4282
4282
  }
@@ -12957,7 +12957,7 @@ var require_url = __commonJS({
12957
12957
  Object.defineProperty(exports2, "__esModule", { value: true });
12958
12958
  exports2.parse = void 0;
12959
12959
  exports2.resolve = resolve4;
12960
- exports2.cwd = cwd2;
12960
+ exports2.cwd = cwd;
12961
12961
  exports2.getProtocol = getProtocol;
12962
12962
  exports2.getExtension = getExtension;
12963
12963
  exports2.stripQuery = stripQuery;
@@ -12994,7 +12994,7 @@ var require_url = __commonJS({
12994
12994
  }
12995
12995
  return resolvedUrl.toString() + endSpaces;
12996
12996
  }
12997
- function cwd2() {
12997
+ function cwd() {
12998
12998
  if (typeof window !== "undefined") {
12999
12999
  return location.href;
13000
13000
  }
@@ -13066,7 +13066,7 @@ var require_url = __commonJS({
13066
13066
  }
13067
13067
  function fromFileSystemPath(path) {
13068
13068
  if ((0, is_windows_1.isWindows)()) {
13069
- const projectDir = cwd2();
13069
+ const projectDir = cwd();
13070
13070
  const upperPath = path.toUpperCase();
13071
13071
  const projectDirPosixPath = (0, convert_path_to_posix_1.default)(projectDir);
13072
13072
  const posixUpper = projectDirPosixPath.toUpperCase();
@@ -15259,15 +15259,15 @@ var require_loader = __commonJS({
15259
15259
  }
15260
15260
  }
15261
15261
  var directiveHandlers = {
15262
- YAML: function handleYamlDirective(state, name, args2) {
15262
+ YAML: function handleYamlDirective(state, name, args) {
15263
15263
  var match, major, minor;
15264
15264
  if (state.version !== null) {
15265
15265
  throwError(state, "duplication of %YAML directive");
15266
15266
  }
15267
- if (args2.length !== 1) {
15267
+ if (args.length !== 1) {
15268
15268
  throwError(state, "YAML directive accepts exactly one argument");
15269
15269
  }
15270
- match = /^([0-9]+)\.([0-9]+)$/.exec(args2[0]);
15270
+ match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
15271
15271
  if (match === null) {
15272
15272
  throwError(state, "ill-formed argument of the YAML directive");
15273
15273
  }
@@ -15276,19 +15276,19 @@ var require_loader = __commonJS({
15276
15276
  if (major !== 1) {
15277
15277
  throwError(state, "unacceptable YAML version of the document");
15278
15278
  }
15279
- state.version = args2[0];
15279
+ state.version = args[0];
15280
15280
  state.checkLineBreaks = minor < 2;
15281
15281
  if (minor !== 1 && minor !== 2) {
15282
15282
  throwWarning(state, "unsupported YAML version of the document");
15283
15283
  }
15284
15284
  },
15285
- TAG: function handleTagDirective(state, name, args2) {
15285
+ TAG: function handleTagDirective(state, name, args) {
15286
15286
  var handle, prefix;
15287
- if (args2.length !== 2) {
15287
+ if (args.length !== 2) {
15288
15288
  throwError(state, "TAG directive accepts exactly two arguments");
15289
15289
  }
15290
- handle = args2[0];
15291
- prefix = args2[1];
15290
+ handle = args[0];
15291
+ prefix = args[1];
15292
15292
  if (!PATTERN_TAG_HANDLE.test(handle)) {
15293
15293
  throwError(state, "ill-formed tag handle (first argument) of the TAG directive");
15294
15294
  }
@@ -17427,23 +17427,23 @@ var require_normalize_args = __commonJS({
17427
17427
  let schema;
17428
17428
  let options;
17429
17429
  let callback;
17430
- const args2 = Array.prototype.slice.call(_args);
17431
- if (typeof args2[args2.length - 1] === "function") {
17432
- callback = args2.pop();
17433
- }
17434
- if (typeof args2[0] === "string") {
17435
- path = args2[0];
17436
- if (typeof args2[2] === "object") {
17437
- schema = args2[1];
17438
- options = args2[2];
17430
+ const args = Array.prototype.slice.call(_args);
17431
+ if (typeof args[args.length - 1] === "function") {
17432
+ callback = args.pop();
17433
+ }
17434
+ if (typeof args[0] === "string") {
17435
+ path = args[0];
17436
+ if (typeof args[2] === "object") {
17437
+ schema = args[1];
17438
+ options = args[2];
17439
17439
  } else {
17440
17440
  schema = void 0;
17441
- options = args2[1];
17441
+ options = args[1];
17442
17442
  }
17443
17443
  } else {
17444
17444
  path = "";
17445
- schema = args2[0];
17446
- options = args2[1];
17445
+ schema = args[0];
17446
+ options = args[1];
17447
17447
  }
17448
17448
  try {
17449
17449
  options = (0, options_js_1.getNewOptions)(options);
@@ -17637,8 +17637,8 @@ var require_bundle = __commonJS({
17637
17637
  if (pointer === null) {
17638
17638
  return;
17639
17639
  }
17640
- const parsed = pointer_js_1.default.parse(pathFromRoot);
17641
- const depth = parsed.length;
17640
+ const parsed2 = pointer_js_1.default.parse(pathFromRoot);
17641
+ const depth = parsed2.length;
17642
17642
  const file = url.stripHash(pointer.path);
17643
17643
  const hash = url.getHash(pointer.path);
17644
17644
  const external = file !== $refs._root$Ref.path;
@@ -18042,51 +18042,51 @@ var require_lib3 = __commonJS({
18042
18042
  this.$refs = new refs_js_1.default();
18043
18043
  }
18044
18044
  async parse() {
18045
- const args2 = (0, normalize_args_js_1.default)(arguments);
18045
+ const args = (0, normalize_args_js_1.default)(arguments);
18046
18046
  let promise;
18047
- if (!args2.path && !args2.schema) {
18048
- const err = (0, ono_1.ono)(`Expected a file path, URL, or object. Got ${args2.path || args2.schema}`);
18049
- return (0, maybe_js_1.default)(args2.callback, Promise.reject(err));
18047
+ if (!args.path && !args.schema) {
18048
+ const err = (0, ono_1.ono)(`Expected a file path, URL, or object. Got ${args.path || args.schema}`);
18049
+ return (0, maybe_js_1.default)(args.callback, Promise.reject(err));
18050
18050
  }
18051
18051
  this.schema = null;
18052
18052
  this.$refs = new refs_js_1.default();
18053
18053
  let pathType = "http";
18054
- if (url.isFileSystemPath(args2.path)) {
18055
- args2.path = url.fromFileSystemPath(args2.path);
18054
+ if (url.isFileSystemPath(args.path)) {
18055
+ args.path = url.fromFileSystemPath(args.path);
18056
18056
  pathType = "file";
18057
- } else if (!args2.path && args2.schema && "$id" in args2.schema && args2.schema.$id) {
18058
- const params = url.parse(args2.schema.$id);
18057
+ } else if (!args.path && args.schema && "$id" in args.schema && args.schema.$id) {
18058
+ const params = url.parse(args.schema.$id);
18059
18059
  const port = params.protocol === "https:" ? 443 : 80;
18060
- args2.path = `${params.protocol}//${params.hostname}:${port}`;
18060
+ args.path = `${params.protocol}//${params.hostname}:${port}`;
18061
18061
  }
18062
- args2.path = url.resolve(url.cwd(), args2.path);
18063
- if (args2.schema && typeof args2.schema === "object") {
18064
- const $ref = this.$refs._add(args2.path);
18065
- $ref.value = args2.schema;
18062
+ args.path = url.resolve(url.cwd(), args.path);
18063
+ if (args.schema && typeof args.schema === "object") {
18064
+ const $ref = this.$refs._add(args.path);
18065
+ $ref.value = args.schema;
18066
18066
  $ref.pathType = pathType;
18067
- promise = Promise.resolve(args2.schema);
18067
+ promise = Promise.resolve(args.schema);
18068
18068
  } else {
18069
- promise = (0, parse_js_1.default)(args2.path, this.$refs, args2.options);
18069
+ promise = (0, parse_js_1.default)(args.path, this.$refs, args.options);
18070
18070
  }
18071
18071
  try {
18072
18072
  const result = await promise;
18073
18073
  if (result !== null && typeof result === "object" && !Buffer.isBuffer(result)) {
18074
18074
  this.schema = result;
18075
- return (0, maybe_js_1.default)(args2.callback, Promise.resolve(this.schema));
18076
- } else if (args2.options.continueOnError) {
18075
+ return (0, maybe_js_1.default)(args.callback, Promise.resolve(this.schema));
18076
+ } else if (args.options.continueOnError) {
18077
18077
  this.schema = null;
18078
- return (0, maybe_js_1.default)(args2.callback, Promise.resolve(this.schema));
18078
+ return (0, maybe_js_1.default)(args.callback, Promise.resolve(this.schema));
18079
18079
  } else {
18080
18080
  throw ono_1.ono.syntax(`"${this.$refs._root$Ref.path || result}" is not a valid JSON Schema`);
18081
18081
  }
18082
18082
  } catch (err) {
18083
- if (!args2.options.continueOnError || !(0, errors_js_1.isHandledError)(err)) {
18084
- return (0, maybe_js_1.default)(args2.callback, Promise.reject(err));
18083
+ if (!args.options.continueOnError || !(0, errors_js_1.isHandledError)(err)) {
18084
+ return (0, maybe_js_1.default)(args.callback, Promise.reject(err));
18085
18085
  }
18086
- if (this.$refs._$refs[url.stripHash(args2.path)]) {
18087
- this.$refs._$refs[url.stripHash(args2.path)].addError(err);
18086
+ if (this.$refs._$refs[url.stripHash(args.path)]) {
18087
+ this.$refs._$refs[url.stripHash(args.path)].addError(err);
18088
18088
  }
18089
- return (0, maybe_js_1.default)(args2.callback, Promise.resolve(null));
18089
+ return (0, maybe_js_1.default)(args.callback, Promise.resolve(null));
18090
18090
  }
18091
18091
  }
18092
18092
  static parse() {
@@ -18094,14 +18094,14 @@ var require_lib3 = __commonJS({
18094
18094
  return parser.parse.apply(parser, arguments);
18095
18095
  }
18096
18096
  async resolve() {
18097
- const args2 = (0, normalize_args_js_1.default)(arguments);
18097
+ const args = (0, normalize_args_js_1.default)(arguments);
18098
18098
  try {
18099
- await this.parse(args2.path, args2.schema, args2.options);
18100
- await (0, resolve_external_js_1.default)(this, args2.options);
18099
+ await this.parse(args.path, args.schema, args.options);
18100
+ await (0, resolve_external_js_1.default)(this, args.options);
18101
18101
  finalize(this);
18102
- return (0, maybe_js_1.default)(args2.callback, Promise.resolve(this.$refs));
18102
+ return (0, maybe_js_1.default)(args.callback, Promise.resolve(this.$refs));
18103
18103
  } catch (err) {
18104
- return (0, maybe_js_1.default)(args2.callback, Promise.reject(err));
18104
+ return (0, maybe_js_1.default)(args.callback, Promise.reject(err));
18105
18105
  }
18106
18106
  }
18107
18107
  static resolve() {
@@ -18113,14 +18113,14 @@ var require_lib3 = __commonJS({
18113
18113
  return instance.bundle.apply(instance, arguments);
18114
18114
  }
18115
18115
  async bundle() {
18116
- const args2 = (0, normalize_args_js_1.default)(arguments);
18116
+ const args = (0, normalize_args_js_1.default)(arguments);
18117
18117
  try {
18118
- await this.resolve(args2.path, args2.schema, args2.options);
18119
- (0, bundle_js_1.default)(this, args2.options);
18118
+ await this.resolve(args.path, args.schema, args.options);
18119
+ (0, bundle_js_1.default)(this, args.options);
18120
18120
  finalize(this);
18121
- return (0, maybe_js_1.default)(args2.callback, Promise.resolve(this.schema));
18121
+ return (0, maybe_js_1.default)(args.callback, Promise.resolve(this.schema));
18122
18122
  } catch (err) {
18123
- return (0, maybe_js_1.default)(args2.callback, Promise.reject(err));
18123
+ return (0, maybe_js_1.default)(args.callback, Promise.reject(err));
18124
18124
  }
18125
18125
  }
18126
18126
  static dereference() {
@@ -18128,14 +18128,14 @@ var require_lib3 = __commonJS({
18128
18128
  return instance.dereference.apply(instance, arguments);
18129
18129
  }
18130
18130
  async dereference() {
18131
- const args2 = (0, normalize_args_js_1.default)(arguments);
18131
+ const args = (0, normalize_args_js_1.default)(arguments);
18132
18132
  try {
18133
- await this.resolve(args2.path, args2.schema, args2.options);
18134
- (0, dereference_js_1.default)(this, args2.options);
18133
+ await this.resolve(args.path, args.schema, args.options);
18134
+ (0, dereference_js_1.default)(this, args.options);
18135
18135
  finalize(this);
18136
- return (0, maybe_js_1.default)(args2.callback, Promise.resolve(this.schema));
18136
+ return (0, maybe_js_1.default)(args.callback, Promise.resolve(this.schema));
18137
18137
  } catch (err) {
18138
- return (0, maybe_js_1.default)(args2.callback, Promise.reject(err));
18138
+ return (0, maybe_js_1.default)(args.callback, Promise.reject(err));
18139
18139
  }
18140
18140
  }
18141
18141
  };
@@ -18273,13 +18273,13 @@ var require_lib4 = __commonJS({
18273
18273
  * @returns {Promise} - The returned promise resolves with the parsed API object.
18274
18274
  */
18275
18275
  async parse(path, api, options, callback) {
18276
- let args2 = normalizeArgs(arguments);
18277
- args2.options = new Options(args2.options);
18276
+ let args = normalizeArgs(arguments);
18277
+ args.options = new Options(args.options);
18278
18278
  try {
18279
- let schema = await super.parse(args2.path, args2.schema, args2.options);
18279
+ let schema = await super.parse(args.path, args.schema, args.options);
18280
18280
  if (schema.swagger) {
18281
18281
  if (schema.swagger === void 0 || schema.info === void 0 || schema.paths === void 0) {
18282
- throw ono.syntax(`${args2.path || args2.schema} is not a valid Swagger API definition`);
18282
+ throw ono.syntax(`${args.path || args.schema} is not a valid Swagger API definition`);
18283
18283
  } else if (typeof schema.swagger === "number") {
18284
18284
  throw ono.syntax('Swagger version number must be a string (e.g. "2.0") not a number.');
18285
18285
  } else if (typeof schema.info.version === "number") {
@@ -18289,14 +18289,14 @@ var require_lib4 = __commonJS({
18289
18289
  }
18290
18290
  } else {
18291
18291
  if (schema.openapi === void 0 || schema.info === void 0) {
18292
- throw ono.syntax(`${args2.path || args2.schema} is not a valid Openapi API definition`);
18292
+ throw ono.syntax(`${args.path || args.schema} is not a valid Openapi API definition`);
18293
18293
  } else if (schema.paths === void 0) {
18294
18294
  if (supported31Versions.indexOf(schema.openapi) !== -1) {
18295
18295
  if (schema.webhooks === void 0) {
18296
- throw ono.syntax(`${args2.path || args2.schema} is not a valid Openapi API definition`);
18296
+ throw ono.syntax(`${args.path || args.schema} is not a valid Openapi API definition`);
18297
18297
  }
18298
18298
  } else {
18299
- throw ono.syntax(`${args2.path || args2.schema} is not a valid Openapi API definition`);
18299
+ throw ono.syntax(`${args.path || args.schema} is not a valid Openapi API definition`);
18300
18300
  }
18301
18301
  } else if (typeof schema.openapi === "number") {
18302
18302
  throw ono.syntax('Openapi version number must be a string (e.g. "3.0.0") not a number.');
@@ -18307,11 +18307,11 @@ var require_lib4 = __commonJS({
18307
18307
  `Unsupported OpenAPI version: ${schema.openapi}. Swagger Parser only supports versions ${supportedVersions.join(", ")}`
18308
18308
  );
18309
18309
  }
18310
- util.fixOasRelativeServers(schema, args2.path);
18310
+ util.fixOasRelativeServers(schema, args.path);
18311
18311
  }
18312
- return maybe(args2.callback, Promise.resolve(schema));
18312
+ return maybe(args.callback, Promise.resolve(schema));
18313
18313
  } catch (err) {
18314
- return maybe(args2.callback, Promise.reject(err));
18314
+ return maybe(args.callback, Promise.reject(err));
18315
18315
  }
18316
18316
  }
18317
18317
  /**
@@ -18326,29 +18326,29 @@ var require_lib4 = __commonJS({
18326
18326
  */
18327
18327
  async validate(path, api, options, callback) {
18328
18328
  let me = this;
18329
- let args2 = normalizeArgs(arguments);
18330
- args2.options = new Options(args2.options);
18331
- let circular$RefOption = args2.options.dereference.circular;
18332
- args2.options.validate.schema && (args2.options.dereference.circular = "ignore");
18329
+ let args = normalizeArgs(arguments);
18330
+ args.options = new Options(args.options);
18331
+ let circular$RefOption = args.options.dereference.circular;
18332
+ args.options.validate.schema && (args.options.dereference.circular = "ignore");
18333
18333
  try {
18334
- await this.dereference(args2.path, args2.schema, args2.options);
18335
- args2.options.dereference.circular = circular$RefOption;
18336
- if (args2.options.validate.schema) {
18334
+ await this.dereference(args.path, args.schema, args.options);
18335
+ args.options.dereference.circular = circular$RefOption;
18336
+ if (args.options.validate.schema) {
18337
18337
  validateSchema(me.api);
18338
18338
  if (me.$refs.circular) {
18339
18339
  if (circular$RefOption === true) {
18340
- dereference(me, args2.options);
18340
+ dereference(me, args.options);
18341
18341
  } else if (circular$RefOption === false) {
18342
18342
  throw ono.reference("The API contains circular references");
18343
18343
  }
18344
18344
  }
18345
18345
  }
18346
- if (args2.options.validate.spec) {
18346
+ if (args.options.validate.spec) {
18347
18347
  validateSpec(me.api);
18348
18348
  }
18349
- return maybe(args2.callback, Promise.resolve(me.schema));
18349
+ return maybe(args.callback, Promise.resolve(me.schema));
18350
18350
  } catch (err) {
18351
- return maybe(args2.callback, Promise.reject(err));
18351
+ return maybe(args.callback, Promise.reject(err));
18352
18352
  }
18353
18353
  }
18354
18354
  };
@@ -18360,25 +18360,25 @@ var require_lib4 = __commonJS({
18360
18360
  }
18361
18361
  });
18362
18362
  var defaultExport = SwaggerParser2;
18363
- defaultExport.validate = (...args2) => {
18363
+ defaultExport.validate = (...args) => {
18364
18364
  const defaultInstance = new SwaggerParser2();
18365
- return defaultInstance.validate(...args2);
18365
+ return defaultInstance.validate(...args);
18366
18366
  };
18367
- defaultExport.dereference = (...args2) => {
18367
+ defaultExport.dereference = (...args) => {
18368
18368
  const defaultInstance = new SwaggerParser2();
18369
- return defaultInstance.dereference(...args2);
18369
+ return defaultInstance.dereference(...args);
18370
18370
  };
18371
- defaultExport.bundle = (...args2) => {
18371
+ defaultExport.bundle = (...args) => {
18372
18372
  const defaultInstance = new SwaggerParser2();
18373
- return defaultInstance.bundle(...args2);
18373
+ return defaultInstance.bundle(...args);
18374
18374
  };
18375
- defaultExport.parse = (...args2) => {
18375
+ defaultExport.parse = (...args) => {
18376
18376
  const defaultInstance = new SwaggerParser2();
18377
- return defaultInstance.parse(...args2);
18377
+ return defaultInstance.parse(...args);
18378
18378
  };
18379
- defaultExport.resolve = (...args2) => {
18379
+ defaultExport.resolve = (...args) => {
18380
18380
  const defaultInstance = new SwaggerParser2();
18381
- return defaultInstance.resolve(...args2);
18381
+ return defaultInstance.resolve(...args);
18382
18382
  };
18383
18383
  defaultExport.default = defaultExport;
18384
18384
  defaultExport.SwaggerParser = defaultExport;
@@ -18387,7 +18387,8 @@ var require_lib4 = __commonJS({
18387
18387
  });
18388
18388
 
18389
18389
  // src/cli.ts
18390
- var import_node_path3 = require("node:path");
18390
+ var import_node_fs = require("node:fs");
18391
+ var import_node_path4 = require("node:path");
18391
18392
 
18392
18393
  // src/generator.ts
18393
18394
  var import_promises2 = require("node:fs/promises");
@@ -18451,8 +18452,8 @@ function validateInputPath(resolvedInput) {
18451
18452
  }
18452
18453
  }
18453
18454
  }
18454
- async function loadConfig(cwd2, configPath) {
18455
- const resolvedConfigPath = configPath ?? (0, import_node_path.join)(cwd2, "openapi-server.config.json");
18455
+ async function loadConfig(cwd, configPath) {
18456
+ const resolvedConfigPath = configPath ?? (0, import_node_path.join)(cwd, "openapi-server.config.json");
18456
18457
  if (configPath !== void 0) {
18457
18458
  validateConfigPath(configPath);
18458
18459
  }
@@ -18462,16 +18463,16 @@ async function loadConfig(cwd2, configPath) {
18462
18463
  } catch {
18463
18464
  throw new Error(`Config file not found: ${resolvedConfigPath}`);
18464
18465
  }
18465
- let parsed;
18466
+ let parsed2;
18466
18467
  try {
18467
- parsed = JSON.parse(raw);
18468
+ parsed2 = JSON.parse(raw);
18468
18469
  } catch {
18469
18470
  throw new Error(`Config file is not valid JSON: ${resolvedConfigPath}`);
18470
18471
  }
18471
- if (typeof parsed !== "object" || parsed === null) {
18472
+ if (typeof parsed2 !== "object" || parsed2 === null) {
18472
18473
  throw new Error("Config must be a JSON object");
18473
18474
  }
18474
- const config = parsed;
18475
+ const config = parsed2;
18475
18476
  if (typeof config["input_openapi"] !== "string" || !config["input_openapi"]) {
18476
18477
  throw new Error('Config missing required field: "input_openapi" (path to OpenAPI 3.1 spec)');
18477
18478
  }
@@ -18484,8 +18485,8 @@ async function loadConfig(cwd2, configPath) {
18484
18485
  if (config["input_schema"] !== void 0 && (typeof config["input_schema"] !== "string" || !config["input_schema"])) {
18485
18486
  throw new Error('"input_schema" must be a non-empty string path to your Zod schema file');
18486
18487
  }
18487
- const resolvedInput = (0, import_node_path.resolve)(cwd2, config["input_openapi"]);
18488
- const resolvedOutput = (0, import_node_path.resolve)(cwd2, config["output"]);
18488
+ const resolvedInput = (0, import_node_path.resolve)(cwd, config["input_openapi"]);
18489
+ const resolvedOutput = (0, import_node_path.resolve)(cwd, config["output"]);
18489
18490
  validateInputPath(resolvedInput);
18490
18491
  validateOutputPath(resolvedOutput);
18491
18492
  return {
@@ -18498,8 +18499,225 @@ async function loadConfig(cwd2, configPath) {
18498
18499
 
18499
18500
  // ../openapi-gen/dist/parser.js
18500
18501
  var import_swagger_parser = __toESM(require_lib4(), 1);
18502
+
18503
+ // ../openapi-gen/dist/utils/schema-depth.js
18504
+ var MAX_SCHEMA_DEPTH = 100;
18505
+ function isRef(schema) {
18506
+ return "$ref" in schema;
18507
+ }
18508
+ function inlineChildren(s) {
18509
+ const children = [];
18510
+ for (const key of ["allOf", "anyOf", "oneOf"]) {
18511
+ const list = s[key];
18512
+ if (list !== void 0)
18513
+ children.push(...list);
18514
+ }
18515
+ if (s.properties !== void 0) {
18516
+ children.push(...Object.values(s.properties));
18517
+ }
18518
+ const items = s.items;
18519
+ if (items !== void 0)
18520
+ children.push(items);
18521
+ if (s.additionalProperties !== void 0 && typeof s.additionalProperties === "object") {
18522
+ children.push(s.additionalProperties);
18523
+ }
18524
+ return children;
18525
+ }
18526
+ function assertBoundedDepth(root) {
18527
+ const stack = [
18528
+ { node: root, depth: 0 }
18529
+ ];
18530
+ while (stack.length > 0) {
18531
+ const { node, depth } = stack.pop();
18532
+ if (depth > MAX_SCHEMA_DEPTH) {
18533
+ throw new Error(`Schema nesting exceeds the maximum supported depth (${MAX_SCHEMA_DEPTH}). This usually indicates a malformed or hostile OpenAPI spec.`);
18534
+ }
18535
+ if (isRef(node))
18536
+ continue;
18537
+ for (const child of inlineChildren(node)) {
18538
+ stack.push({ node: child, depth: depth + 1 });
18539
+ }
18540
+ }
18541
+ }
18542
+
18543
+ // ../openapi-gen/dist/utils/normalize-nullable.js
18544
+ function isRef2(schema) {
18545
+ return "$ref" in schema;
18546
+ }
18547
+ var PRIMITIVE_TYPES = /* @__PURE__ */ new Set(["string", "number", "integer", "boolean"]);
18548
+ function wrapInNullableAnyOf(s) {
18549
+ const innerCopy = {};
18550
+ for (const key of Object.keys(s)) {
18551
+ innerCopy[key] = s[key];
18552
+ }
18553
+ for (const key of Object.keys(s)) {
18554
+ delete s[key];
18555
+ }
18556
+ s["anyOf"] = [innerCopy, { type: "null" }];
18557
+ }
18558
+ function hasStructuralKeywords(s) {
18559
+ return s["properties"] !== void 0 || s["items"] !== void 0 || s["additionalProperties"] !== void 0 && typeof s["additionalProperties"] === "object" || Array.isArray(s["allOf"]) || Array.isArray(s["anyOf"]) || Array.isArray(s["oneOf"]);
18560
+ }
18561
+ function applyNullableEnum(s) {
18562
+ if (!s["enum"].includes(null)) {
18563
+ s["enum"] = [...s["enum"], null];
18564
+ }
18565
+ delete s["type"];
18566
+ }
18567
+ function applyNullableTypeArray(s) {
18568
+ if (!s["type"].includes("null")) {
18569
+ s["type"] = [...s["type"], "null"];
18570
+ }
18571
+ }
18572
+ function applyNullablePrimitiveType(s) {
18573
+ s["type"] = [s["type"], "null"];
18574
+ }
18575
+ function normalizeNode(schema) {
18576
+ const s = schema;
18577
+ const isNullable = s["nullable"] === true || s["x-nullable"] === true;
18578
+ if (!isNullable)
18579
+ return;
18580
+ delete s["nullable"];
18581
+ delete s["x-nullable"];
18582
+ if (Array.isArray(s["enum"])) {
18583
+ applyNullableEnum(s);
18584
+ return;
18585
+ }
18586
+ if (Array.isArray(s["type"])) {
18587
+ applyNullableTypeArray(s);
18588
+ return;
18589
+ }
18590
+ if (typeof s["type"] === "string" && PRIMITIVE_TYPES.has(s["type"]) && !hasStructuralKeywords(s)) {
18591
+ applyNullablePrimitiveType(s);
18592
+ return;
18593
+ }
18594
+ wrapInNullableAnyOf(s);
18595
+ }
18596
+ function walkSchema(schema, visited) {
18597
+ if (visited.has(schema))
18598
+ return;
18599
+ visited.add(schema);
18600
+ if (isRef2(schema))
18601
+ return;
18602
+ normalizeNode(schema);
18603
+ walkSchemaChildren(schema, visited);
18604
+ }
18605
+ function walkSchemaChildren(s, visited) {
18606
+ walkCompositionArrays(s, visited);
18607
+ walkPropertySchemas(s, visited);
18608
+ walkArrayItems(s, visited);
18609
+ walkAdditionalProperties(s, visited);
18610
+ }
18611
+ function walkCompositionArrays(s, visited) {
18612
+ for (const key of ["allOf", "anyOf", "oneOf"]) {
18613
+ const list = s[key];
18614
+ if (list !== void 0) {
18615
+ for (const item of list) {
18616
+ walkSchema(item, visited);
18617
+ }
18618
+ }
18619
+ }
18620
+ }
18621
+ function walkPropertySchemas(s, visited) {
18622
+ if (s.properties === void 0)
18623
+ return;
18624
+ for (const propSchema of Object.values(s.properties)) {
18625
+ walkSchema(propSchema, visited);
18626
+ }
18627
+ }
18628
+ function walkArrayItems(s, visited) {
18629
+ const items = s.items;
18630
+ if (items !== void 0) {
18631
+ walkSchema(items, visited);
18632
+ }
18633
+ }
18634
+ function walkAdditionalProperties(s, visited) {
18635
+ if (s.additionalProperties !== void 0 && typeof s.additionalProperties === "object") {
18636
+ walkSchema(s.additionalProperties, visited);
18637
+ }
18638
+ }
18639
+ function walkComponentSchemas(spec, visited) {
18640
+ const schemas = spec.components?.schemas;
18641
+ if (schemas === void 0)
18642
+ return;
18643
+ for (const schema of Object.values(schemas)) {
18644
+ walkSchema(schema, visited);
18645
+ }
18646
+ }
18647
+ function walkParameterSchema(param, visited) {
18648
+ if ("schema" in param && param.schema !== void 0) {
18649
+ walkSchema(param.schema, visited);
18650
+ }
18651
+ }
18652
+ function walkRequestBody(requestBody, visited) {
18653
+ if (isRef2(requestBody))
18654
+ return;
18655
+ const body = requestBody;
18656
+ if (body.content === void 0)
18657
+ return;
18658
+ for (const mediaType of Object.values(body.content)) {
18659
+ if (mediaType.schema !== void 0) {
18660
+ walkSchema(mediaType.schema, visited);
18661
+ }
18662
+ }
18663
+ }
18664
+ function walkResponses(responses, visited) {
18665
+ for (const response of Object.values(responses)) {
18666
+ if (isRef2(response))
18667
+ continue;
18668
+ const r = response;
18669
+ if (r.content === void 0)
18670
+ continue;
18671
+ for (const mediaType of Object.values(r.content)) {
18672
+ if (mediaType.schema !== void 0) {
18673
+ walkSchema(mediaType.schema, visited);
18674
+ }
18675
+ }
18676
+ }
18677
+ }
18678
+ function walkOperation(operation, visited) {
18679
+ if (operation.parameters !== void 0) {
18680
+ for (const param of operation.parameters) {
18681
+ walkParameterSchema(param, visited);
18682
+ }
18683
+ }
18684
+ if (operation.requestBody !== void 0) {
18685
+ walkRequestBody(operation.requestBody, visited);
18686
+ }
18687
+ if (operation.responses !== void 0) {
18688
+ walkResponses(operation.responses, visited);
18689
+ }
18690
+ }
18691
+ var HTTP_METHODS = ["get", "put", "post", "delete", "options", "head", "patch", "trace"];
18692
+ function walkPathSchemas(spec, visited) {
18693
+ const paths = spec.paths;
18694
+ if (paths === void 0)
18695
+ return;
18696
+ for (const pathItem of Object.values(paths)) {
18697
+ if (pathItem == null || typeof pathItem !== "object")
18698
+ continue;
18699
+ const pi = pathItem;
18700
+ for (const method of HTTP_METHODS) {
18701
+ const op = pi[method];
18702
+ if (op == null || typeof op !== "object")
18703
+ continue;
18704
+ walkOperation(op, visited);
18705
+ }
18706
+ }
18707
+ }
18708
+ function normalizeNullable(spec) {
18709
+ const visited = /* @__PURE__ */ new Set();
18710
+ walkComponentSchemas(spec, visited);
18711
+ walkPathSchemas(spec, visited);
18712
+ }
18713
+
18714
+ // ../openapi-gen/dist/parser.js
18501
18715
  async function parseSpec(inputPath) {
18502
18716
  const api = await import_swagger_parser.default.bundle(inputPath);
18717
+ for (const schema of Object.values(api.components?.schemas ?? {})) {
18718
+ assertBoundedDepth(schema);
18719
+ }
18720
+ normalizeNullable(api);
18503
18721
  return api;
18504
18722
  }
18505
18723
 
@@ -18517,7 +18735,7 @@ function toTypeName(name) {
18517
18735
 
18518
18736
  // src/plugins/service.ts
18519
18737
  var SUPPORTED_METHODS = ["get", "post", "put", "patch", "delete"];
18520
- function isRef(obj) {
18738
+ function isRef3(obj) {
18521
18739
  return typeof obj === "object" && obj !== null && "$ref" in obj;
18522
18740
  }
18523
18741
  function refToName(ref) {
@@ -18530,13 +18748,13 @@ function extractPathParamsFromPath(path) {
18530
18748
  return matches.map((m) => sanitizeOperationId(m.slice(1, -1)));
18531
18749
  }
18532
18750
  function resolveParam(p, spec) {
18533
- if (!isRef(p)) return p;
18751
+ if (!isRef3(p)) return p;
18534
18752
  const refStr = p.$ref;
18535
18753
  const name = refToName(refStr);
18536
18754
  const components = spec.components;
18537
18755
  if (components?.parameters === void 0) return void 0;
18538
18756
  const resolved = components.parameters[name];
18539
- if (resolved === void 0 || isRef(resolved)) return void 0;
18757
+ if (resolved === void 0 || isRef3(resolved)) return void 0;
18540
18758
  return resolved;
18541
18759
  }
18542
18760
  function deriveServiceName(spec) {
@@ -18603,7 +18821,7 @@ function getQueryParams(operation, spec) {
18603
18821
  if (resolved === void 0 || resolved.in !== "query") continue;
18604
18822
  const schema = resolved.schema;
18605
18823
  let tsType = "string";
18606
- if (schema !== void 0 && !isRef(schema)) {
18824
+ if (schema !== void 0 && !isRef3(schema)) {
18607
18825
  const s = schema;
18608
18826
  if (s.type === "number" || s.type === "integer") tsType = "number";
18609
18827
  else if (s.type === "boolean") tsType = "boolean";
@@ -18619,14 +18837,14 @@ function getQueryParams(operation, spec) {
18619
18837
  function getBodyInfo(operation) {
18620
18838
  const requestBody = operation.requestBody;
18621
18839
  if (requestBody === void 0) return void 0;
18622
- if (isRef(requestBody)) return { typeName: void 0 };
18840
+ if (isRef3(requestBody)) return { typeName: void 0 };
18623
18841
  const rb = requestBody;
18624
18842
  const content = rb.content;
18625
18843
  if (content === void 0) return { typeName: void 0 };
18626
18844
  const jsonContent = content["application/json"];
18627
18845
  if (jsonContent === void 0 || jsonContent.schema === void 0) return { typeName: void 0 };
18628
18846
  const schema = jsonContent.schema;
18629
- if (isRef(schema)) {
18847
+ if (isRef3(schema)) {
18630
18848
  return { typeName: refToName(schema.$ref) };
18631
18849
  }
18632
18850
  return { typeName: void 0 };
@@ -18637,14 +18855,14 @@ function getReturnInfo(operation) {
18637
18855
  for (const code of ["200", "201"]) {
18638
18856
  const response = responses[code];
18639
18857
  if (response === void 0) continue;
18640
- if (isRef(response)) continue;
18858
+ if (isRef3(response)) continue;
18641
18859
  const resp = response;
18642
18860
  const content = resp.content;
18643
18861
  if (content === void 0) continue;
18644
18862
  const jsonContent = content["application/json"];
18645
18863
  if (jsonContent === void 0 || jsonContent.schema === void 0) continue;
18646
18864
  const schema = jsonContent.schema;
18647
- if (isRef(schema)) {
18865
+ if (isRef3(schema)) {
18648
18866
  return {
18649
18867
  typeName: refToName(schema.$ref),
18650
18868
  isArray: false,
@@ -18654,7 +18872,7 @@ function getReturnInfo(operation) {
18654
18872
  const s = schema;
18655
18873
  if (s.type === "array") {
18656
18874
  const items = s.items;
18657
- if (items !== void 0 && isRef(items)) {
18875
+ if (items !== void 0 && isRef3(items)) {
18658
18876
  return {
18659
18877
  typeName: refToName(items.$ref),
18660
18878
  isArray: true,
@@ -18704,22 +18922,22 @@ function collectOperations(spec) {
18704
18922
  return operations;
18705
18923
  }
18706
18924
  function buildMethodSignature(op) {
18707
- const args2 = [];
18925
+ const args = [];
18708
18926
  for (const p of op.pathParams) {
18709
- args2.push(`${p}: string`);
18927
+ args.push(`${p}: string`);
18710
18928
  }
18711
18929
  if (op.bodyInfo !== void 0) {
18712
18930
  const typeName = op.bodyInfo.typeName ?? "unknown";
18713
- args2.push(`body: ${typeName}`);
18931
+ args.push(`body: ${typeName}`);
18714
18932
  }
18715
18933
  if (op.queryParams.length > 0) {
18716
18934
  const allOptional = op.queryParams.every((q) => !q.required);
18717
18935
  const fields = op.queryParams.map((q) => `${q.name}${q.required ? "" : "?"}: ${q.tsType}`).join("; ");
18718
18936
  const paramsToken = allOptional ? "params?" : "params";
18719
- args2.push(`${paramsToken}: { ${fields} }`);
18937
+ args.push(`${paramsToken}: { ${fields} }`);
18720
18938
  }
18721
18939
  const returnType = buildReturnType(op.returnInfo);
18722
- const argStr = args2.join(", ");
18940
+ const argStr = args.join(", ");
18723
18941
  return `${op.methodName}(${argStr}): ${returnType}`;
18724
18942
  }
18725
18943
  function generateService(spec) {
@@ -18757,7 +18975,7 @@ function generateService(spec) {
18757
18975
 
18758
18976
  // src/plugins/router.ts
18759
18977
  var SUPPORTED_METHODS2 = ["get", "post", "put", "patch", "delete"];
18760
- function isRef2(obj) {
18978
+ function isRef4(obj) {
18761
18979
  return typeof obj === "object" && obj !== null && "$ref" in obj;
18762
18980
  }
18763
18981
  function refToName2(ref) {
@@ -18773,13 +18991,13 @@ function toHonoPath(openapiPath) {
18773
18991
  return openapiPath.replace(/\{([^}]+)\}/g, ":$1");
18774
18992
  }
18775
18993
  function resolveParam2(p, spec) {
18776
- if (!isRef2(p)) return p;
18994
+ if (!isRef4(p)) return p;
18777
18995
  const refStr = p.$ref;
18778
18996
  const name = refToName2(refStr);
18779
18997
  const components = spec.components;
18780
18998
  if (components?.parameters === void 0) return void 0;
18781
18999
  const resolved = components.parameters[name];
18782
- if (resolved === void 0 || isRef2(resolved)) return void 0;
19000
+ if (resolved === void 0 || isRef4(resolved)) return void 0;
18783
19001
  return resolved;
18784
19002
  }
18785
19003
  function deriveServiceName2(spec) {
@@ -18838,7 +19056,7 @@ function normalizeParamName2(name) {
18838
19056
  return /^[^a-zA-Z_$]/.test(camel) ? `_${camel}` : camel;
18839
19057
  }
18840
19058
  function schemaToTsType(schema) {
18841
- if (schema === void 0 || isRef2(schema)) return "string";
19059
+ if (schema === void 0 || isRef4(schema)) return "string";
18842
19060
  const s = schema;
18843
19061
  if (s.type === "number" || s.type === "integer") return "number";
18844
19062
  if (s.type === "boolean") return "boolean";
@@ -18860,23 +19078,166 @@ function getQueryParams2(operation, spec) {
18860
19078
  }
18861
19079
  return result;
18862
19080
  }
19081
+ function formatToZodModifier(format) {
19082
+ switch (format) {
19083
+ case "uuid":
19084
+ return ".uuid()";
19085
+ case "email":
19086
+ return ".email()";
19087
+ case "uri":
19088
+ case "url":
19089
+ return ".url()";
19090
+ case "date-time":
19091
+ return ".datetime()";
19092
+ default:
19093
+ return "";
19094
+ }
19095
+ }
19096
+ function pathParamZodExpr(schema) {
19097
+ if (schema === void 0 || isRef4(schema)) return void 0;
19098
+ const s = schema;
19099
+ if (s.type !== "string") return void 0;
19100
+ const format = s.format;
19101
+ if (format === void 0) return void 0;
19102
+ const modifier = formatToZodModifier(format);
19103
+ if (modifier === "") return void 0;
19104
+ return `z.string()${modifier}`;
19105
+ }
19106
+ function paramZodExpr(tsType, required, schema) {
19107
+ let base;
19108
+ if (tsType === "number") {
19109
+ base = "z.number()";
19110
+ } else if (tsType === "boolean") {
19111
+ base = "z.boolean()";
19112
+ } else {
19113
+ if (schema !== void 0 && !isRef4(schema)) {
19114
+ const s = schema;
19115
+ const format = s.format;
19116
+ const modifier = format !== void 0 ? formatToZodModifier(format) : "";
19117
+ base = `z.string()${modifier}`;
19118
+ } else {
19119
+ base = "z.string()";
19120
+ }
19121
+ }
19122
+ return required ? base : `${base}.optional()`;
19123
+ }
19124
+ function getPathParamValidations(operation, spec, rawPathParamNames) {
19125
+ const parameters = operation.parameters;
19126
+ if (parameters === void 0) return [];
19127
+ const zodByName = /* @__PURE__ */ new Map();
19128
+ for (const p of parameters) {
19129
+ const resolved = resolveParam2(p, spec);
19130
+ if (resolved === void 0 || resolved.in !== "path") continue;
19131
+ const schema = resolved.schema;
19132
+ const zodExpr = pathParamZodExpr(schema);
19133
+ if (zodExpr !== void 0) zodByName.set(resolved.name, zodExpr);
19134
+ }
19135
+ const result = [];
19136
+ for (const rawName of rawPathParamNames) {
19137
+ const zodExpr = zodByName.get(rawName);
19138
+ if (zodExpr !== void 0) result.push({ rawName, zodExpr });
19139
+ }
19140
+ return result;
19141
+ }
19142
+ function getHeaderParams(operation, spec) {
19143
+ const parameters = operation.parameters;
19144
+ if (parameters === void 0) return [];
19145
+ const result = [];
19146
+ for (const p of parameters) {
19147
+ const resolved = resolveParam2(p, spec);
19148
+ if (resolved === void 0 || resolved.in !== "header") continue;
19149
+ result.push({
19150
+ rawName: resolved.name,
19151
+ required: resolved.required === true
19152
+ });
19153
+ }
19154
+ return result;
19155
+ }
19156
+ function queryParamsNeedValidation(queryParams) {
19157
+ return queryParams.some((q) => q.required || q.tsType !== "string");
19158
+ }
19159
+ function emitQueryValidation(lines, queryParams, indent) {
19160
+ const inner = `${indent} `;
19161
+ const fieldIndent = `${indent} `;
19162
+ const fields = queryParams.map((q) => {
19163
+ const expr = paramZodExpr(q.tsType, q.required);
19164
+ return `${fieldIndent}${q.name}: ${expr}`;
19165
+ }).join(",\n");
19166
+ lines.push(`${inner}// Validate query parameters: returns 422 with Zod issues on failure`);
19167
+ lines.push(`${inner}const _qv = z.object({`);
19168
+ lines.push(fields);
19169
+ lines.push(`${inner}}).safeParse(params)`);
19170
+ }
19171
+ function emitPathValidation(lines, validations, indent, framework) {
19172
+ const inner = `${indent} `;
19173
+ const fieldIndent = `${indent} `;
19174
+ const schemaFields = validations.map((v) => {
19175
+ const key = /[^a-zA-Z0-9_$]/.test(v.rawName) ? JSON.stringify(v.rawName) : v.rawName;
19176
+ return `${fieldIndent}${key}: ${v.zodExpr}`;
19177
+ }).join(",\n");
19178
+ const rawFields = validations.map((v) => {
19179
+ const key = /[^a-zA-Z0-9_$]/.test(v.rawName) ? JSON.stringify(v.rawName) : v.rawName;
19180
+ let access;
19181
+ if (framework === "hono") {
19182
+ access = `c.req.param(${JSON.stringify(v.rawName)})`;
19183
+ } else if (framework === "express") {
19184
+ access = `req.params[${JSON.stringify(v.rawName)}]`;
19185
+ } else {
19186
+ access = /[^a-zA-Z0-9_$]/.test(v.rawName) ? `req.params[${JSON.stringify(v.rawName)}]` : `req.params.${v.rawName}`;
19187
+ }
19188
+ return `${fieldIndent}${key}: ${access}`;
19189
+ }).join(",\n");
19190
+ lines.push(`${inner}// Validate path parameters: returns 422 with Zod issues on failure`);
19191
+ lines.push(`${inner}const _pv = z.object({`);
19192
+ lines.push(schemaFields);
19193
+ lines.push(`${inner}}).safeParse({`);
19194
+ lines.push(rawFields);
19195
+ lines.push(`${inner}})`);
19196
+ }
19197
+ function emitHeaderValidation(lines, headerParams, indent, framework) {
19198
+ const inner = `${indent} `;
19199
+ const fieldIndent = `${indent} `;
19200
+ const schemaFields = headerParams.map((h) => {
19201
+ const key = JSON.stringify(h.rawName);
19202
+ const expr = h.required ? "z.string()" : "z.string().optional()";
19203
+ return `${fieldIndent}${key}: ${expr}`;
19204
+ }).join(",\n");
19205
+ const rawFields = headerParams.map((h) => {
19206
+ const key = JSON.stringify(h.rawName);
19207
+ let access;
19208
+ if (framework === "hono") {
19209
+ access = `c.req.header(${key})`;
19210
+ } else if (framework === "express") {
19211
+ access = `req.headers[${key}] as string | undefined`;
19212
+ } else {
19213
+ access = `req.headers[${key}]`;
19214
+ }
19215
+ return `${fieldIndent}${key}: ${access}`;
19216
+ }).join(",\n");
19217
+ lines.push(`${inner}// Validate request headers: returns 422 with Zod issues on failure`);
19218
+ lines.push(`${inner}const _hv = z.object({`);
19219
+ lines.push(schemaFields);
19220
+ lines.push(`${inner}}).safeParse({`);
19221
+ lines.push(rawFields);
19222
+ lines.push(`${inner}})`);
19223
+ }
18863
19224
  function getBodyInfo2(operation) {
18864
19225
  const requestBody = operation.requestBody;
18865
19226
  if (requestBody === void 0) return void 0;
18866
- if (isRef2(requestBody)) return { typeName: void 0 };
19227
+ if (isRef4(requestBody)) return { typeName: void 0 };
18867
19228
  const rb = requestBody;
18868
19229
  const content = rb.content;
18869
19230
  if (content === void 0) return { typeName: void 0 };
18870
19231
  const jsonContent = content["application/json"];
18871
19232
  if (jsonContent === void 0 || jsonContent.schema === void 0) return { typeName: void 0 };
18872
19233
  const schema = jsonContent.schema;
18873
- if (isRef2(schema)) {
19234
+ if (isRef4(schema)) {
18874
19235
  return { typeName: refToName2(schema.$ref) };
18875
19236
  }
18876
19237
  return { typeName: void 0 };
18877
19238
  }
18878
19239
  function response200IsVoid(resp) {
18879
- if (isRef2(resp)) return false;
19240
+ if (isRef4(resp)) return false;
18880
19241
  const r = resp;
18881
19242
  const content = r.content;
18882
19243
  return content === void 0 || Object.keys(content).length === 0;
@@ -18904,7 +19265,9 @@ function collectOperations2(spec) {
18904
19265
  if (operation === void 0) continue;
18905
19266
  const methodName = deriveMethodName2(operation.operationId, method, path);
18906
19267
  const pathParams = extractPathParamsFromPath2(path);
19268
+ const pathParamValidations = getPathParamValidations(operation, spec, pathParams);
18907
19269
  const queryParams = getQueryParams2(operation, spec);
19270
+ const headerParams = getHeaderParams(operation, spec);
18908
19271
  const bodyInfo = getBodyInfo2(operation);
18909
19272
  const responseStatus = getResponseStatus(operation, method);
18910
19273
  operations.push({
@@ -18913,7 +19276,9 @@ function collectOperations2(spec) {
18913
19276
  path,
18914
19277
  honoPath: toHonoPath(path),
18915
19278
  pathParams,
19279
+ pathParamValidations,
18916
19280
  queryParams,
19281
+ headerParams,
18917
19282
  bodyInfo,
18918
19283
  responseStatus
18919
19284
  });
@@ -18921,9 +19286,40 @@ function collectOperations2(spec) {
18921
19286
  }
18922
19287
  return operations;
18923
19288
  }
19289
+ function collectSortedBodyTypes(operations) {
19290
+ const bodyTypes = /* @__PURE__ */ new Set();
19291
+ for (const op of operations) {
19292
+ if (op.bodyInfo?.typeName !== void 0) bodyTypes.add(op.bodyInfo.typeName);
19293
+ }
19294
+ return Array.from(bodyTypes).sort();
19295
+ }
19296
+ function collectUsedSchemaNames(operations, schemaNames) {
19297
+ const used = /* @__PURE__ */ new Set();
19298
+ for (const op of operations) {
19299
+ const typeName = op.bodyInfo?.typeName;
19300
+ if (typeName === void 0) continue;
19301
+ const schemaName = `${typeName}Schema`;
19302
+ if (schemaNames.has(schemaName)) used.add(schemaName);
19303
+ }
19304
+ return used;
19305
+ }
19306
+ function collectGeneratorSetup(operations, options) {
19307
+ const sortedBodyTypes = collectSortedBodyTypes(operations);
19308
+ const usedSchemaNames = options?.schemaNames !== void 0 ? collectUsedSchemaNames(operations, options.schemaNames) : /* @__PURE__ */ new Set();
19309
+ const needsZod = usedSchemaNames.size > 0 && options?.schemaImportPath !== void 0 || operationsNeedZodForParams(operations);
19310
+ return { sortedBodyTypes, usedSchemaNames, needsZod };
19311
+ }
18924
19312
  function buildRouteHandler(op, indent, schemaNames) {
18925
19313
  const lines = [];
18926
- lines.push(`${indent}app.${op.httpMethod}('${op.honoPath}', async (c) => {`);
19314
+ lines.push(`${indent}app.${op.httpMethod}(${JSON.stringify(op.honoPath)}, async (c) => {`);
19315
+ if (op.pathParamValidations.length > 0) {
19316
+ emitPathValidation(lines, op.pathParamValidations, indent, "hono");
19317
+ lines.push(`${indent} if (!_pv.success) {`);
19318
+ lines.push(
19319
+ `${indent} return c.json({ error: 'Invalid path parameters', issues: _pv.error.issues }, 422)`
19320
+ );
19321
+ lines.push(`${indent} }`);
19322
+ }
18927
19323
  if (op.queryParams.length > 0) {
18928
19324
  const fields = op.queryParams.map((q) => {
18929
19325
  if (q.tsType === "number") {
@@ -18934,6 +19330,22 @@ function buildRouteHandler(op, indent, schemaNames) {
18934
19330
  lines.push(`${indent} const params = {`);
18935
19331
  lines.push(fields);
18936
19332
  lines.push(`${indent} }`);
19333
+ if (queryParamsNeedValidation(op.queryParams)) {
19334
+ emitQueryValidation(lines, op.queryParams, indent);
19335
+ lines.push(`${indent} if (!_qv.success) {`);
19336
+ lines.push(
19337
+ `${indent} return c.json({ error: 'Invalid query parameters', issues: _qv.error.issues }, 422)`
19338
+ );
19339
+ lines.push(`${indent} }`);
19340
+ }
19341
+ }
19342
+ if (op.headerParams.length > 0) {
19343
+ emitHeaderValidation(lines, op.headerParams, indent, "hono");
19344
+ lines.push(`${indent} if (!_hv.success) {`);
19345
+ lines.push(
19346
+ `${indent} return c.json({ error: 'Invalid request headers', issues: _hv.error.issues }, 422)`
19347
+ );
19348
+ lines.push(`${indent} }`);
18937
19349
  }
18938
19350
  let bodyVarName = "body";
18939
19351
  if (op.bodyInfo !== void 0) {
@@ -18954,7 +19366,7 @@ function buildRouteHandler(op, indent, schemaNames) {
18954
19366
  }
18955
19367
  const serviceArgs = [];
18956
19368
  for (const p of op.pathParams) {
18957
- serviceArgs.push(`c.req.param('${p}')`);
19369
+ serviceArgs.push(`c.req.param(${JSON.stringify(p)})`);
18958
19370
  }
18959
19371
  if (op.bodyInfo !== void 0) {
18960
19372
  serviceArgs.push(bodyVarName);
@@ -18977,8 +19389,16 @@ function buildRouteHandler(op, indent, schemaNames) {
18977
19389
  function buildExpressRouteHandler(op, indent, schemaNames) {
18978
19390
  const lines = [];
18979
19391
  lines.push(
18980
- `${indent}router.${op.httpMethod}('${op.honoPath}', async (req: Request, res: Response) => {`
19392
+ `${indent}router.${op.httpMethod}(${JSON.stringify(op.honoPath)}, async (req: Request, res: Response) => {`
18981
19393
  );
19394
+ if (op.pathParamValidations.length > 0) {
19395
+ emitPathValidation(lines, op.pathParamValidations, indent, "express");
19396
+ lines.push(`${indent} if (!_pv.success) {`);
19397
+ lines.push(
19398
+ `${indent} return void res.status(422).json({ error: 'Invalid path parameters', issues: _pv.error.issues })`
19399
+ );
19400
+ lines.push(`${indent} }`);
19401
+ }
18982
19402
  if (op.queryParams.length > 0) {
18983
19403
  const fields = op.queryParams.map((q) => {
18984
19404
  if (q.tsType === "number") {
@@ -18992,6 +19412,22 @@ function buildExpressRouteHandler(op, indent, schemaNames) {
18992
19412
  lines.push(`${indent} const params = {`);
18993
19413
  lines.push(fields);
18994
19414
  lines.push(`${indent} }`);
19415
+ if (queryParamsNeedValidation(op.queryParams)) {
19416
+ emitQueryValidation(lines, op.queryParams, indent);
19417
+ lines.push(`${indent} if (!_qv.success) {`);
19418
+ lines.push(
19419
+ `${indent} return void res.status(422).json({ error: 'Invalid query parameters', issues: _qv.error.issues })`
19420
+ );
19421
+ lines.push(`${indent} }`);
19422
+ }
19423
+ }
19424
+ if (op.headerParams.length > 0) {
19425
+ emitHeaderValidation(lines, op.headerParams, indent, "express");
19426
+ lines.push(`${indent} if (!_hv.success) {`);
19427
+ lines.push(
19428
+ `${indent} return void res.status(422).json({ error: 'Invalid request headers', issues: _hv.error.issues })`
19429
+ );
19430
+ lines.push(`${indent} }`);
18995
19431
  }
18996
19432
  let bodyVarName = "body";
18997
19433
  if (op.bodyInfo !== void 0) {
@@ -19034,61 +19470,6 @@ function buildExpressRouteHandler(op, indent, schemaNames) {
19034
19470
  lines.push(`${indent}})`);
19035
19471
  return lines.join("\n");
19036
19472
  }
19037
- function generateExpressRouter(spec, options) {
19038
- const serviceName = deriveServiceName2(spec);
19039
- const operations = collectOperations2(spec);
19040
- const bodyTypes = /* @__PURE__ */ new Set();
19041
- for (const op of operations) {
19042
- if (op.bodyInfo?.typeName !== void 0) {
19043
- bodyTypes.add(op.bodyInfo.typeName);
19044
- }
19045
- }
19046
- const sortedBodyTypes = Array.from(bodyTypes).sort();
19047
- const usedSchemaNames = /* @__PURE__ */ new Set();
19048
- if (options?.schemaNames !== void 0) {
19049
- for (const op of operations) {
19050
- const typeName = op.bodyInfo?.typeName;
19051
- if (typeName !== void 0) {
19052
- const schemaName = `${typeName}Schema`;
19053
- if (options.schemaNames.has(schemaName)) {
19054
- usedSchemaNames.add(schemaName);
19055
- }
19056
- }
19057
- }
19058
- }
19059
- const lines = [];
19060
- lines.push("// This file is auto-generated. Do not edit manually.");
19061
- lines.push(
19062
- "// Express: apply express.json() middleware before mounting this router so req.body is populated."
19063
- );
19064
- lines.push("");
19065
- lines.push("import { Router } from 'express'");
19066
- lines.push("import type { Request, Response } from 'express'");
19067
- if (sortedBodyTypes.length > 0) {
19068
- lines.push(`import type { ${sortedBodyTypes.join(", ")} } from './models.js'`);
19069
- }
19070
- lines.push(`import type { ${serviceName} } from './service.js'`);
19071
- if (usedSchemaNames.size > 0 && options?.schemaImportPath !== void 0) {
19072
- lines.push(`import { z } from 'zod'`);
19073
- const sortedUsedSchemas = Array.from(usedSchemaNames).sort();
19074
- lines.push(`import { ${sortedUsedSchemas.join(", ")} } from '${options.schemaImportPath}'`);
19075
- }
19076
- lines.push("");
19077
- lines.push(`export function createRouter(service: ${serviceName}): Router {`);
19078
- lines.push(" const router = Router()");
19079
- lines.push("");
19080
- for (const op of operations) {
19081
- lines.push(buildExpressRouteHandler(op, " ", options?.schemaNames));
19082
- lines.push("");
19083
- }
19084
- lines.push(" return router");
19085
- lines.push("}");
19086
- lines.push("");
19087
- return {
19088
- filename: "router.ts",
19089
- content: lines.join("\n")
19090
- };
19091
- }
19092
19473
  function buildFastifyRouteHandler(op, indent, schemaNames) {
19093
19474
  const lines = [];
19094
19475
  const genericParts = [];
@@ -19110,12 +19491,41 @@ function buildFastifyRouteHandler(op, indent, schemaNames) {
19110
19491
  genericParts.push(`Params: { ${paramFields} }`);
19111
19492
  }
19112
19493
  const generic = genericParts.length > 0 ? `<{ ${genericParts.join("; ")} }>` : "";
19113
- lines.push(`${indent}app.${op.httpMethod}${generic}('${op.honoPath}', async (req, reply) => {`);
19494
+ lines.push(
19495
+ `${indent}app.${op.httpMethod}${generic}(${JSON.stringify(op.honoPath)}, async (req, reply) => {`
19496
+ );
19497
+ if (op.pathParamValidations.length > 0) {
19498
+ emitPathValidation(lines, op.pathParamValidations, indent, "fastify");
19499
+ lines.push(`${indent} if (!_pv.success) {`);
19500
+ lines.push(`${indent} return reply.status(422).send({`);
19501
+ lines.push(`${indent} error: 'Invalid path parameters',`);
19502
+ lines.push(`${indent} issues: _pv.error.issues,`);
19503
+ lines.push(`${indent} })`);
19504
+ lines.push(`${indent} }`);
19505
+ }
19114
19506
  if (op.queryParams.length > 0) {
19115
19507
  const fields = op.queryParams.map((q) => ` ${q.name}: req.query.${q.name}`).join(",\n");
19116
19508
  lines.push(`${indent} const params = {`);
19117
19509
  lines.push(fields);
19118
19510
  lines.push(`${indent} }`);
19511
+ if (queryParamsNeedValidation(op.queryParams)) {
19512
+ emitQueryValidation(lines, op.queryParams, indent);
19513
+ lines.push(`${indent} if (!_qv.success) {`);
19514
+ lines.push(`${indent} return reply.status(422).send({`);
19515
+ lines.push(`${indent} error: 'Invalid query parameters',`);
19516
+ lines.push(`${indent} issues: _qv.error.issues,`);
19517
+ lines.push(`${indent} })`);
19518
+ lines.push(`${indent} }`);
19519
+ }
19520
+ }
19521
+ if (op.headerParams.length > 0) {
19522
+ emitHeaderValidation(lines, op.headerParams, indent, "fastify");
19523
+ lines.push(`${indent} if (!_hv.success) {`);
19524
+ lines.push(`${indent} return reply.status(422).send({`);
19525
+ lines.push(`${indent} error: 'Invalid request headers',`);
19526
+ lines.push(`${indent} issues: _hv.error.issues,`);
19527
+ lines.push(`${indent} })`);
19528
+ lines.push(`${indent} }`);
19119
19529
  }
19120
19530
  let bodyVarName = "req.body";
19121
19531
  if (op.bodyInfo !== void 0) {
@@ -19155,28 +19565,57 @@ function buildFastifyRouteHandler(op, indent, schemaNames) {
19155
19565
  lines.push(`${indent}})`);
19156
19566
  return lines.join("\n");
19157
19567
  }
19158
- function generateFastifyRouter(spec, options) {
19568
+ function operationsNeedZodForParams(operations) {
19569
+ for (const op of operations) {
19570
+ if (op.pathParamValidations.length > 0) return true;
19571
+ if (queryParamsNeedValidation(op.queryParams)) return true;
19572
+ if (op.headerParams.length > 0) return true;
19573
+ }
19574
+ return false;
19575
+ }
19576
+ function generateExpressRouter(spec, options) {
19159
19577
  const serviceName = deriveServiceName2(spec);
19160
19578
  const operations = collectOperations2(spec);
19161
- const bodyTypes = /* @__PURE__ */ new Set();
19162
- for (const op of operations) {
19163
- if (op.bodyInfo?.typeName !== void 0) {
19164
- bodyTypes.add(op.bodyInfo.typeName);
19165
- }
19579
+ const { sortedBodyTypes, usedSchemaNames, needsZod } = collectGeneratorSetup(operations, options);
19580
+ const lines = [];
19581
+ lines.push("// This file is auto-generated. Do not edit manually.");
19582
+ lines.push(
19583
+ "// Express: apply express.json() middleware before mounting this router so req.body is populated."
19584
+ );
19585
+ lines.push("");
19586
+ lines.push("import { Router } from 'express'");
19587
+ lines.push("import type { Request, Response } from 'express'");
19588
+ if (sortedBodyTypes.length > 0) {
19589
+ lines.push(`import type { ${sortedBodyTypes.join(", ")} } from './models.js'`);
19166
19590
  }
19167
- const sortedBodyTypes = Array.from(bodyTypes).sort();
19168
- const usedSchemaNames = /* @__PURE__ */ new Set();
19169
- if (options?.schemaNames !== void 0) {
19170
- for (const op of operations) {
19171
- const typeName = op.bodyInfo?.typeName;
19172
- if (typeName !== void 0) {
19173
- const schemaName = `${typeName}Schema`;
19174
- if (options.schemaNames.has(schemaName)) {
19175
- usedSchemaNames.add(schemaName);
19176
- }
19177
- }
19178
- }
19591
+ lines.push(`import type { ${serviceName} } from './service.js'`);
19592
+ if (needsZod) {
19593
+ lines.push(`import { z } from 'zod'`);
19594
+ }
19595
+ if (usedSchemaNames.size > 0 && options?.schemaImportPath !== void 0) {
19596
+ const sortedUsedSchemas = Array.from(usedSchemaNames).sort();
19597
+ lines.push(`import { ${sortedUsedSchemas.join(", ")} } from '${options.schemaImportPath}'`);
19179
19598
  }
19599
+ lines.push("");
19600
+ lines.push(`export function createRouter(service: ${serviceName}): Router {`);
19601
+ lines.push(" const router = Router()");
19602
+ lines.push("");
19603
+ for (const op of operations) {
19604
+ lines.push(buildExpressRouteHandler(op, " ", options?.schemaNames));
19605
+ lines.push("");
19606
+ }
19607
+ lines.push(" return router");
19608
+ lines.push("}");
19609
+ lines.push("");
19610
+ return {
19611
+ filename: "router.ts",
19612
+ content: lines.join("\n")
19613
+ };
19614
+ }
19615
+ function generateFastifyRouter(spec, options) {
19616
+ const serviceName = deriveServiceName2(spec);
19617
+ const operations = collectOperations2(spec);
19618
+ const { sortedBodyTypes, usedSchemaNames, needsZod } = collectGeneratorSetup(operations, options);
19180
19619
  const lines = [];
19181
19620
  lines.push("// This file is auto-generated. Do not edit manually.");
19182
19621
  lines.push("");
@@ -19185,8 +19624,10 @@ function generateFastifyRouter(spec, options) {
19185
19624
  lines.push(`import type { ${sortedBodyTypes.join(", ")} } from './models.js'`);
19186
19625
  }
19187
19626
  lines.push(`import type { ${serviceName} } from './service.js'`);
19188
- if (usedSchemaNames.size > 0 && options?.schemaImportPath !== void 0) {
19627
+ if (needsZod) {
19189
19628
  lines.push(`import { z } from 'zod'`);
19629
+ }
19630
+ if (usedSchemaNames.size > 0 && options?.schemaImportPath !== void 0) {
19190
19631
  const sortedUsedSchemas = Array.from(usedSchemaNames).sort();
19191
19632
  lines.push(`import { ${sortedUsedSchemas.join(", ")} } from '${options.schemaImportPath}'`);
19192
19633
  }
@@ -19206,25 +19647,7 @@ function generateFastifyRouter(spec, options) {
19206
19647
  function generateRouter(spec, options) {
19207
19648
  const serviceName = deriveServiceName2(spec);
19208
19649
  const operations = collectOperations2(spec);
19209
- const bodyTypes = /* @__PURE__ */ new Set();
19210
- for (const op of operations) {
19211
- if (op.bodyInfo?.typeName !== void 0) {
19212
- bodyTypes.add(op.bodyInfo.typeName);
19213
- }
19214
- }
19215
- const sortedBodyTypes = Array.from(bodyTypes).sort();
19216
- const usedSchemaNames = /* @__PURE__ */ new Set();
19217
- if (options?.schemaNames !== void 0) {
19218
- for (const op of operations) {
19219
- const typeName = op.bodyInfo?.typeName;
19220
- if (typeName !== void 0) {
19221
- const schemaName = `${typeName}Schema`;
19222
- if (options.schemaNames.has(schemaName)) {
19223
- usedSchemaNames.add(schemaName);
19224
- }
19225
- }
19226
- }
19227
- }
19650
+ const { sortedBodyTypes, usedSchemaNames, needsZod } = collectGeneratorSetup(operations, options);
19228
19651
  const lines = [];
19229
19652
  lines.push("// This file is auto-generated. Do not edit manually.");
19230
19653
  lines.push("");
@@ -19233,8 +19656,10 @@ function generateRouter(spec, options) {
19233
19656
  lines.push(`import type { ${sortedBodyTypes.join(", ")} } from './models.js'`);
19234
19657
  }
19235
19658
  lines.push(`import type { ${serviceName} } from './service.js'`);
19236
- if (usedSchemaNames.size > 0 && options?.schemaImportPath !== void 0) {
19659
+ if (needsZod) {
19237
19660
  lines.push(`import { z } from 'zod'`);
19661
+ }
19662
+ if (usedSchemaNames.size > 0 && options?.schemaImportPath !== void 0) {
19238
19663
  const sortedUsedSchemas = Array.from(usedSchemaNames).sort();
19239
19664
  lines.push(`import { ${sortedUsedSchemas.join(", ")} } from '${options.schemaImportPath}'`);
19240
19665
  }
@@ -19261,11 +19686,11 @@ async function formatTs(content, filePath) {
19261
19686
  const config = await resolveConfig(filePath);
19262
19687
  return format(content, { ...config, parser: "typescript" });
19263
19688
  }
19264
- async function generate2(cwd2, configPath) {
19689
+ async function generate2(cwd, configPath) {
19265
19690
  console.log("Loading config...");
19266
- const config = await loadConfig(cwd2, configPath);
19267
- const inputPath = (0, import_node_path2.resolve)(cwd2, config.input_openapi);
19268
- const outputDir = (0, import_node_path2.resolve)(cwd2, config.output);
19691
+ const config = await loadConfig(cwd, configPath);
19692
+ const inputPath = (0, import_node_path2.resolve)(cwd, config.input_openapi);
19693
+ const outputDir = (0, import_node_path2.resolve)(cwd, config.output);
19269
19694
  const framework = config.framework ?? "none";
19270
19695
  console.log(`Parsing spec: ${inputPath}`);
19271
19696
  const spec = await parseSpec(inputPath);
@@ -19286,7 +19711,7 @@ async function generate2(cwd2, configPath) {
19286
19711
  console.log(` \u2713 ${file.filename}`);
19287
19712
  }
19288
19713
  if ((framework === "hono" || framework === "express" || framework === "fastify") && config.input_schema !== void 0) {
19289
- const schemaPath = (0, import_node_path2.resolve)(cwd2, config.input_schema);
19714
+ const schemaPath = (0, import_node_path2.resolve)(cwd, config.input_schema);
19290
19715
  let schemaContent;
19291
19716
  try {
19292
19717
  schemaContent = await (0, import_promises2.readFile)(schemaPath, "utf-8");
@@ -19320,22 +19745,63 @@ async function generate2(cwd2, configPath) {
19320
19745
  console.log(`Done! Generated ${generatedFiles.length} file(s).`);
19321
19746
  }
19322
19747
 
19748
+ // src/cli-args.ts
19749
+ var import_node_path3 = require("node:path");
19750
+ function parseCliArgs(argv, cwd) {
19751
+ const args = argv.slice(2);
19752
+ if (args.includes("--help") || args.includes("-h")) {
19753
+ return { action: "help" };
19754
+ }
19755
+ if (args.includes("--version") || args.includes("-v")) {
19756
+ return { action: "version" };
19757
+ }
19758
+ const configIdx = args.indexOf("--config");
19759
+ if (configIdx !== -1) {
19760
+ const next = args[configIdx + 1];
19761
+ if (next === void 0 || next.startsWith("--")) {
19762
+ return {
19763
+ action: "error",
19764
+ message: [
19765
+ "Error: --config requires a file path argument",
19766
+ "Usage: openapi-server [--config <path-to-config.json>]"
19767
+ ].join("\n")
19768
+ };
19769
+ }
19770
+ const configFile = (0, import_node_path3.resolve)(cwd, next);
19771
+ return { action: "run", configFile, cwd: (0, import_node_path3.dirname)(configFile) };
19772
+ }
19773
+ return { action: "run", cwd };
19774
+ }
19775
+
19323
19776
  // src/cli.ts
19324
- var args = process.argv.slice(2);
19325
- var configIdx = args.indexOf("--config");
19326
- var cwd = process.cwd();
19327
- var configFile;
19328
- if (configIdx !== -1) {
19329
- const next = args[configIdx + 1];
19330
- if (next === void 0 || next.startsWith("--")) {
19331
- console.error("Error: --config requires a file path argument");
19332
- console.error("Usage: openapi-server [--config <path-to-config.json>]");
19333
- process.exit(1);
19334
- }
19335
- configFile = (0, import_node_path3.resolve)(cwd, next);
19336
- cwd = (0, import_node_path3.dirname)(configFile);
19777
+ var parsed = parseCliArgs(process.argv, process.cwd());
19778
+ if (parsed.action === "help") {
19779
+ console.log(
19780
+ [
19781
+ "Usage: openapi-server [--config <path>]",
19782
+ "",
19783
+ "Generate a typed service interface and a Hono router from an OpenAPI 3.1 spec.",
19784
+ "",
19785
+ "Options:",
19786
+ " --config <path> Path to config file (default: openapi-server.config.json in cwd)",
19787
+ " --help, -h Show this help message",
19788
+ " --version, -v Show version number"
19789
+ ].join("\n")
19790
+ );
19791
+ process.exit(0);
19792
+ }
19793
+ if (parsed.action === "version") {
19794
+ const pkg = JSON.parse(
19795
+ (0, import_node_fs.readFileSync)((0, import_node_path4.join)(__dirname, "../package.json"), "utf-8")
19796
+ );
19797
+ console.log(pkg.version);
19798
+ process.exit(0);
19799
+ }
19800
+ if (parsed.action === "error") {
19801
+ console.error(parsed.message);
19802
+ process.exit(1);
19337
19803
  }
19338
- generate2(cwd, configFile).catch((err) => {
19804
+ generate2(parsed.cwd, parsed.configFile).catch((err) => {
19339
19805
  console.error(`Error: ${err.message}`);
19340
19806
  process.exit(1);
19341
19807
  });