@codewithagents/openapi-server 1.3.2 → 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 {
@@ -18539,12 +18540,184 @@ function assertBoundedDepth(root) {
18539
18540
  }
18540
18541
  }
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
+
18542
18714
  // ../openapi-gen/dist/parser.js
18543
18715
  async function parseSpec(inputPath) {
18544
18716
  const api = await import_swagger_parser.default.bundle(inputPath);
18545
18717
  for (const schema of Object.values(api.components?.schemas ?? {})) {
18546
18718
  assertBoundedDepth(schema);
18547
18719
  }
18720
+ normalizeNullable(api);
18548
18721
  return api;
18549
18722
  }
18550
18723
 
@@ -18562,7 +18735,7 @@ function toTypeName(name) {
18562
18735
 
18563
18736
  // src/plugins/service.ts
18564
18737
  var SUPPORTED_METHODS = ["get", "post", "put", "patch", "delete"];
18565
- function isRef2(obj) {
18738
+ function isRef3(obj) {
18566
18739
  return typeof obj === "object" && obj !== null && "$ref" in obj;
18567
18740
  }
18568
18741
  function refToName(ref) {
@@ -18575,13 +18748,13 @@ function extractPathParamsFromPath(path) {
18575
18748
  return matches.map((m) => sanitizeOperationId(m.slice(1, -1)));
18576
18749
  }
18577
18750
  function resolveParam(p, spec) {
18578
- if (!isRef2(p)) return p;
18751
+ if (!isRef3(p)) return p;
18579
18752
  const refStr = p.$ref;
18580
18753
  const name = refToName(refStr);
18581
18754
  const components = spec.components;
18582
18755
  if (components?.parameters === void 0) return void 0;
18583
18756
  const resolved = components.parameters[name];
18584
- if (resolved === void 0 || isRef2(resolved)) return void 0;
18757
+ if (resolved === void 0 || isRef3(resolved)) return void 0;
18585
18758
  return resolved;
18586
18759
  }
18587
18760
  function deriveServiceName(spec) {
@@ -18648,7 +18821,7 @@ function getQueryParams(operation, spec) {
18648
18821
  if (resolved === void 0 || resolved.in !== "query") continue;
18649
18822
  const schema = resolved.schema;
18650
18823
  let tsType = "string";
18651
- if (schema !== void 0 && !isRef2(schema)) {
18824
+ if (schema !== void 0 && !isRef3(schema)) {
18652
18825
  const s = schema;
18653
18826
  if (s.type === "number" || s.type === "integer") tsType = "number";
18654
18827
  else if (s.type === "boolean") tsType = "boolean";
@@ -18664,14 +18837,14 @@ function getQueryParams(operation, spec) {
18664
18837
  function getBodyInfo(operation) {
18665
18838
  const requestBody = operation.requestBody;
18666
18839
  if (requestBody === void 0) return void 0;
18667
- if (isRef2(requestBody)) return { typeName: void 0 };
18840
+ if (isRef3(requestBody)) return { typeName: void 0 };
18668
18841
  const rb = requestBody;
18669
18842
  const content = rb.content;
18670
18843
  if (content === void 0) return { typeName: void 0 };
18671
18844
  const jsonContent = content["application/json"];
18672
18845
  if (jsonContent === void 0 || jsonContent.schema === void 0) return { typeName: void 0 };
18673
18846
  const schema = jsonContent.schema;
18674
- if (isRef2(schema)) {
18847
+ if (isRef3(schema)) {
18675
18848
  return { typeName: refToName(schema.$ref) };
18676
18849
  }
18677
18850
  return { typeName: void 0 };
@@ -18682,14 +18855,14 @@ function getReturnInfo(operation) {
18682
18855
  for (const code of ["200", "201"]) {
18683
18856
  const response = responses[code];
18684
18857
  if (response === void 0) continue;
18685
- if (isRef2(response)) continue;
18858
+ if (isRef3(response)) continue;
18686
18859
  const resp = response;
18687
18860
  const content = resp.content;
18688
18861
  if (content === void 0) continue;
18689
18862
  const jsonContent = content["application/json"];
18690
18863
  if (jsonContent === void 0 || jsonContent.schema === void 0) continue;
18691
18864
  const schema = jsonContent.schema;
18692
- if (isRef2(schema)) {
18865
+ if (isRef3(schema)) {
18693
18866
  return {
18694
18867
  typeName: refToName(schema.$ref),
18695
18868
  isArray: false,
@@ -18699,7 +18872,7 @@ function getReturnInfo(operation) {
18699
18872
  const s = schema;
18700
18873
  if (s.type === "array") {
18701
18874
  const items = s.items;
18702
- if (items !== void 0 && isRef2(items)) {
18875
+ if (items !== void 0 && isRef3(items)) {
18703
18876
  return {
18704
18877
  typeName: refToName(items.$ref),
18705
18878
  isArray: true,
@@ -18749,22 +18922,22 @@ function collectOperations(spec) {
18749
18922
  return operations;
18750
18923
  }
18751
18924
  function buildMethodSignature(op) {
18752
- const args2 = [];
18925
+ const args = [];
18753
18926
  for (const p of op.pathParams) {
18754
- args2.push(`${p}: string`);
18927
+ args.push(`${p}: string`);
18755
18928
  }
18756
18929
  if (op.bodyInfo !== void 0) {
18757
18930
  const typeName = op.bodyInfo.typeName ?? "unknown";
18758
- args2.push(`body: ${typeName}`);
18931
+ args.push(`body: ${typeName}`);
18759
18932
  }
18760
18933
  if (op.queryParams.length > 0) {
18761
18934
  const allOptional = op.queryParams.every((q) => !q.required);
18762
18935
  const fields = op.queryParams.map((q) => `${q.name}${q.required ? "" : "?"}: ${q.tsType}`).join("; ");
18763
18936
  const paramsToken = allOptional ? "params?" : "params";
18764
- args2.push(`${paramsToken}: { ${fields} }`);
18937
+ args.push(`${paramsToken}: { ${fields} }`);
18765
18938
  }
18766
18939
  const returnType = buildReturnType(op.returnInfo);
18767
- const argStr = args2.join(", ");
18940
+ const argStr = args.join(", ");
18768
18941
  return `${op.methodName}(${argStr}): ${returnType}`;
18769
18942
  }
18770
18943
  function generateService(spec) {
@@ -18802,7 +18975,7 @@ function generateService(spec) {
18802
18975
 
18803
18976
  // src/plugins/router.ts
18804
18977
  var SUPPORTED_METHODS2 = ["get", "post", "put", "patch", "delete"];
18805
- function isRef3(obj) {
18978
+ function isRef4(obj) {
18806
18979
  return typeof obj === "object" && obj !== null && "$ref" in obj;
18807
18980
  }
18808
18981
  function refToName2(ref) {
@@ -18818,13 +18991,13 @@ function toHonoPath(openapiPath) {
18818
18991
  return openapiPath.replace(/\{([^}]+)\}/g, ":$1");
18819
18992
  }
18820
18993
  function resolveParam2(p, spec) {
18821
- if (!isRef3(p)) return p;
18994
+ if (!isRef4(p)) return p;
18822
18995
  const refStr = p.$ref;
18823
18996
  const name = refToName2(refStr);
18824
18997
  const components = spec.components;
18825
18998
  if (components?.parameters === void 0) return void 0;
18826
18999
  const resolved = components.parameters[name];
18827
- if (resolved === void 0 || isRef3(resolved)) return void 0;
19000
+ if (resolved === void 0 || isRef4(resolved)) return void 0;
18828
19001
  return resolved;
18829
19002
  }
18830
19003
  function deriveServiceName2(spec) {
@@ -18883,7 +19056,7 @@ function normalizeParamName2(name) {
18883
19056
  return /^[^a-zA-Z_$]/.test(camel) ? `_${camel}` : camel;
18884
19057
  }
18885
19058
  function schemaToTsType(schema) {
18886
- if (schema === void 0 || isRef3(schema)) return "string";
19059
+ if (schema === void 0 || isRef4(schema)) return "string";
18887
19060
  const s = schema;
18888
19061
  if (s.type === "number" || s.type === "integer") return "number";
18889
19062
  if (s.type === "boolean") return "boolean";
@@ -18905,23 +19078,166 @@ function getQueryParams2(operation, spec) {
18905
19078
  }
18906
19079
  return result;
18907
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
+ }
18908
19224
  function getBodyInfo2(operation) {
18909
19225
  const requestBody = operation.requestBody;
18910
19226
  if (requestBody === void 0) return void 0;
18911
- if (isRef3(requestBody)) return { typeName: void 0 };
19227
+ if (isRef4(requestBody)) return { typeName: void 0 };
18912
19228
  const rb = requestBody;
18913
19229
  const content = rb.content;
18914
19230
  if (content === void 0) return { typeName: void 0 };
18915
19231
  const jsonContent = content["application/json"];
18916
19232
  if (jsonContent === void 0 || jsonContent.schema === void 0) return { typeName: void 0 };
18917
19233
  const schema = jsonContent.schema;
18918
- if (isRef3(schema)) {
19234
+ if (isRef4(schema)) {
18919
19235
  return { typeName: refToName2(schema.$ref) };
18920
19236
  }
18921
19237
  return { typeName: void 0 };
18922
19238
  }
18923
19239
  function response200IsVoid(resp) {
18924
- if (isRef3(resp)) return false;
19240
+ if (isRef4(resp)) return false;
18925
19241
  const r = resp;
18926
19242
  const content = r.content;
18927
19243
  return content === void 0 || Object.keys(content).length === 0;
@@ -18949,7 +19265,9 @@ function collectOperations2(spec) {
18949
19265
  if (operation === void 0) continue;
18950
19266
  const methodName = deriveMethodName2(operation.operationId, method, path);
18951
19267
  const pathParams = extractPathParamsFromPath2(path);
19268
+ const pathParamValidations = getPathParamValidations(operation, spec, pathParams);
18952
19269
  const queryParams = getQueryParams2(operation, spec);
19270
+ const headerParams = getHeaderParams(operation, spec);
18953
19271
  const bodyInfo = getBodyInfo2(operation);
18954
19272
  const responseStatus = getResponseStatus(operation, method);
18955
19273
  operations.push({
@@ -18958,7 +19276,9 @@ function collectOperations2(spec) {
18958
19276
  path,
18959
19277
  honoPath: toHonoPath(path),
18960
19278
  pathParams,
19279
+ pathParamValidations,
18961
19280
  queryParams,
19281
+ headerParams,
18962
19282
  bodyInfo,
18963
19283
  responseStatus
18964
19284
  });
@@ -18966,9 +19286,40 @@ function collectOperations2(spec) {
18966
19286
  }
18967
19287
  return operations;
18968
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
+ }
18969
19312
  function buildRouteHandler(op, indent, schemaNames) {
18970
19313
  const lines = [];
18971
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
+ }
18972
19323
  if (op.queryParams.length > 0) {
18973
19324
  const fields = op.queryParams.map((q) => {
18974
19325
  if (q.tsType === "number") {
@@ -18979,6 +19330,22 @@ function buildRouteHandler(op, indent, schemaNames) {
18979
19330
  lines.push(`${indent} const params = {`);
18980
19331
  lines.push(fields);
18981
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} }`);
18982
19349
  }
18983
19350
  let bodyVarName = "body";
18984
19351
  if (op.bodyInfo !== void 0) {
@@ -19024,6 +19391,14 @@ function buildExpressRouteHandler(op, indent, schemaNames) {
19024
19391
  lines.push(
19025
19392
  `${indent}router.${op.httpMethod}(${JSON.stringify(op.honoPath)}, async (req: Request, res: Response) => {`
19026
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
+ }
19027
19402
  if (op.queryParams.length > 0) {
19028
19403
  const fields = op.queryParams.map((q) => {
19029
19404
  if (q.tsType === "number") {
@@ -19037,6 +19412,22 @@ function buildExpressRouteHandler(op, indent, schemaNames) {
19037
19412
  lines.push(`${indent} const params = {`);
19038
19413
  lines.push(fields);
19039
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} }`);
19040
19431
  }
19041
19432
  let bodyVarName = "body";
19042
19433
  if (op.bodyInfo !== void 0) {
@@ -19079,61 +19470,6 @@ function buildExpressRouteHandler(op, indent, schemaNames) {
19079
19470
  lines.push(`${indent}})`);
19080
19471
  return lines.join("\n");
19081
19472
  }
19082
- function generateExpressRouter(spec, options) {
19083
- const serviceName = deriveServiceName2(spec);
19084
- const operations = collectOperations2(spec);
19085
- const bodyTypes = /* @__PURE__ */ new Set();
19086
- for (const op of operations) {
19087
- if (op.bodyInfo?.typeName !== void 0) {
19088
- bodyTypes.add(op.bodyInfo.typeName);
19089
- }
19090
- }
19091
- const sortedBodyTypes = Array.from(bodyTypes).sort();
19092
- const usedSchemaNames = /* @__PURE__ */ new Set();
19093
- if (options?.schemaNames !== void 0) {
19094
- for (const op of operations) {
19095
- const typeName = op.bodyInfo?.typeName;
19096
- if (typeName !== void 0) {
19097
- const schemaName = `${typeName}Schema`;
19098
- if (options.schemaNames.has(schemaName)) {
19099
- usedSchemaNames.add(schemaName);
19100
- }
19101
- }
19102
- }
19103
- }
19104
- const lines = [];
19105
- lines.push("// This file is auto-generated. Do not edit manually.");
19106
- lines.push(
19107
- "// Express: apply express.json() middleware before mounting this router so req.body is populated."
19108
- );
19109
- lines.push("");
19110
- lines.push("import { Router } from 'express'");
19111
- lines.push("import type { Request, Response } from 'express'");
19112
- if (sortedBodyTypes.length > 0) {
19113
- lines.push(`import type { ${sortedBodyTypes.join(", ")} } from './models.js'`);
19114
- }
19115
- lines.push(`import type { ${serviceName} } from './service.js'`);
19116
- if (usedSchemaNames.size > 0 && options?.schemaImportPath !== void 0) {
19117
- lines.push(`import { z } from 'zod'`);
19118
- const sortedUsedSchemas = Array.from(usedSchemaNames).sort();
19119
- lines.push(`import { ${sortedUsedSchemas.join(", ")} } from '${options.schemaImportPath}'`);
19120
- }
19121
- lines.push("");
19122
- lines.push(`export function createRouter(service: ${serviceName}): Router {`);
19123
- lines.push(" const router = Router()");
19124
- lines.push("");
19125
- for (const op of operations) {
19126
- lines.push(buildExpressRouteHandler(op, " ", options?.schemaNames));
19127
- lines.push("");
19128
- }
19129
- lines.push(" return router");
19130
- lines.push("}");
19131
- lines.push("");
19132
- return {
19133
- filename: "router.ts",
19134
- content: lines.join("\n")
19135
- };
19136
- }
19137
19473
  function buildFastifyRouteHandler(op, indent, schemaNames) {
19138
19474
  const lines = [];
19139
19475
  const genericParts = [];
@@ -19158,11 +19494,38 @@ function buildFastifyRouteHandler(op, indent, schemaNames) {
19158
19494
  lines.push(
19159
19495
  `${indent}app.${op.httpMethod}${generic}(${JSON.stringify(op.honoPath)}, async (req, reply) => {`
19160
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
+ }
19161
19506
  if (op.queryParams.length > 0) {
19162
19507
  const fields = op.queryParams.map((q) => ` ${q.name}: req.query.${q.name}`).join(",\n");
19163
19508
  lines.push(`${indent} const params = {`);
19164
19509
  lines.push(fields);
19165
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} }`);
19166
19529
  }
19167
19530
  let bodyVarName = "req.body";
19168
19531
  if (op.bodyInfo !== void 0) {
@@ -19202,28 +19565,57 @@ function buildFastifyRouteHandler(op, indent, schemaNames) {
19202
19565
  lines.push(`${indent}})`);
19203
19566
  return lines.join("\n");
19204
19567
  }
19205
- 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) {
19206
19577
  const serviceName = deriveServiceName2(spec);
19207
19578
  const operations = collectOperations2(spec);
19208
- const bodyTypes = /* @__PURE__ */ new Set();
19209
- for (const op of operations) {
19210
- if (op.bodyInfo?.typeName !== void 0) {
19211
- bodyTypes.add(op.bodyInfo.typeName);
19212
- }
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'`);
19213
19590
  }
19214
- const sortedBodyTypes = Array.from(bodyTypes).sort();
19215
- const usedSchemaNames = /* @__PURE__ */ new Set();
19216
- if (options?.schemaNames !== void 0) {
19217
- for (const op of operations) {
19218
- const typeName = op.bodyInfo?.typeName;
19219
- if (typeName !== void 0) {
19220
- const schemaName = `${typeName}Schema`;
19221
- if (options.schemaNames.has(schemaName)) {
19222
- usedSchemaNames.add(schemaName);
19223
- }
19224
- }
19225
- }
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}'`);
19226
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);
19227
19619
  const lines = [];
19228
19620
  lines.push("// This file is auto-generated. Do not edit manually.");
19229
19621
  lines.push("");
@@ -19232,8 +19624,10 @@ function generateFastifyRouter(spec, options) {
19232
19624
  lines.push(`import type { ${sortedBodyTypes.join(", ")} } from './models.js'`);
19233
19625
  }
19234
19626
  lines.push(`import type { ${serviceName} } from './service.js'`);
19235
- if (usedSchemaNames.size > 0 && options?.schemaImportPath !== void 0) {
19627
+ if (needsZod) {
19236
19628
  lines.push(`import { z } from 'zod'`);
19629
+ }
19630
+ if (usedSchemaNames.size > 0 && options?.schemaImportPath !== void 0) {
19237
19631
  const sortedUsedSchemas = Array.from(usedSchemaNames).sort();
19238
19632
  lines.push(`import { ${sortedUsedSchemas.join(", ")} } from '${options.schemaImportPath}'`);
19239
19633
  }
@@ -19253,25 +19647,7 @@ function generateFastifyRouter(spec, options) {
19253
19647
  function generateRouter(spec, options) {
19254
19648
  const serviceName = deriveServiceName2(spec);
19255
19649
  const operations = collectOperations2(spec);
19256
- const bodyTypes = /* @__PURE__ */ new Set();
19257
- for (const op of operations) {
19258
- if (op.bodyInfo?.typeName !== void 0) {
19259
- bodyTypes.add(op.bodyInfo.typeName);
19260
- }
19261
- }
19262
- const sortedBodyTypes = Array.from(bodyTypes).sort();
19263
- const usedSchemaNames = /* @__PURE__ */ new Set();
19264
- if (options?.schemaNames !== void 0) {
19265
- for (const op of operations) {
19266
- const typeName = op.bodyInfo?.typeName;
19267
- if (typeName !== void 0) {
19268
- const schemaName = `${typeName}Schema`;
19269
- if (options.schemaNames.has(schemaName)) {
19270
- usedSchemaNames.add(schemaName);
19271
- }
19272
- }
19273
- }
19274
- }
19650
+ const { sortedBodyTypes, usedSchemaNames, needsZod } = collectGeneratorSetup(operations, options);
19275
19651
  const lines = [];
19276
19652
  lines.push("// This file is auto-generated. Do not edit manually.");
19277
19653
  lines.push("");
@@ -19280,8 +19656,10 @@ function generateRouter(spec, options) {
19280
19656
  lines.push(`import type { ${sortedBodyTypes.join(", ")} } from './models.js'`);
19281
19657
  }
19282
19658
  lines.push(`import type { ${serviceName} } from './service.js'`);
19283
- if (usedSchemaNames.size > 0 && options?.schemaImportPath !== void 0) {
19659
+ if (needsZod) {
19284
19660
  lines.push(`import { z } from 'zod'`);
19661
+ }
19662
+ if (usedSchemaNames.size > 0 && options?.schemaImportPath !== void 0) {
19285
19663
  const sortedUsedSchemas = Array.from(usedSchemaNames).sort();
19286
19664
  lines.push(`import { ${sortedUsedSchemas.join(", ")} } from '${options.schemaImportPath}'`);
19287
19665
  }
@@ -19308,11 +19686,11 @@ async function formatTs(content, filePath) {
19308
19686
  const config = await resolveConfig(filePath);
19309
19687
  return format(content, { ...config, parser: "typescript" });
19310
19688
  }
19311
- async function generate2(cwd2, configPath) {
19689
+ async function generate2(cwd, configPath) {
19312
19690
  console.log("Loading config...");
19313
- const config = await loadConfig(cwd2, configPath);
19314
- const inputPath = (0, import_node_path2.resolve)(cwd2, config.input_openapi);
19315
- 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);
19316
19694
  const framework = config.framework ?? "none";
19317
19695
  console.log(`Parsing spec: ${inputPath}`);
19318
19696
  const spec = await parseSpec(inputPath);
@@ -19333,7 +19711,7 @@ async function generate2(cwd2, configPath) {
19333
19711
  console.log(` \u2713 ${file.filename}`);
19334
19712
  }
19335
19713
  if ((framework === "hono" || framework === "express" || framework === "fastify") && config.input_schema !== void 0) {
19336
- const schemaPath = (0, import_node_path2.resolve)(cwd2, config.input_schema);
19714
+ const schemaPath = (0, import_node_path2.resolve)(cwd, config.input_schema);
19337
19715
  let schemaContent;
19338
19716
  try {
19339
19717
  schemaContent = await (0, import_promises2.readFile)(schemaPath, "utf-8");
@@ -19367,22 +19745,63 @@ async function generate2(cwd2, configPath) {
19367
19745
  console.log(`Done! Generated ${generatedFiles.length} file(s).`);
19368
19746
  }
19369
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
+
19370
19776
  // src/cli.ts
19371
- var args = process.argv.slice(2);
19372
- var configIdx = args.indexOf("--config");
19373
- var cwd = process.cwd();
19374
- var configFile;
19375
- if (configIdx !== -1) {
19376
- const next = args[configIdx + 1];
19377
- if (next === void 0 || next.startsWith("--")) {
19378
- console.error("Error: --config requires a file path argument");
19379
- console.error("Usage: openapi-server [--config <path-to-config.json>]");
19380
- process.exit(1);
19381
- }
19382
- configFile = (0, import_node_path3.resolve)(cwd, next);
19383
- 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);
19384
19803
  }
19385
- generate2(cwd, configFile).catch((err) => {
19804
+ generate2(parsed.cwd, parsed.configFile).catch((err) => {
19386
19805
  console.error(`Error: ${err.message}`);
19387
19806
  process.exit(1);
19388
19807
  });