@sebspark/openapi-typegen 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/dist/index.js +9 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -325,11 +325,18 @@ var parseArgs = (route) => {
325
325
  if (args.headers || args.params || args.query || args.body)
326
326
  return args;
327
327
  };
328
+ var optional = (params) => {
329
+ const rxRequiredParams = /(?<!\?\s*)\b['"]?\w+['"]?\s*:\s*\w+/gim;
330
+ const anyRequired = rxRequiredParams.test(params) || !params.includes(":");
331
+ return anyRequired ? "" : "?";
332
+ };
328
333
  var serializeArgs = (args) => {
329
334
  if (!args)
330
335
  return "";
331
- const argsString = Object.entries(args).map(([key, value]) => `${key}: ${value}`).join(",");
332
- return `args: {${argsString}}`;
336
+ const argsString = Object.entries(args).map(([key, value]) => {
337
+ return `${key}${optional(value)}: ${value}`;
338
+ }).join(",");
339
+ return `args${optional(argsString)}: {${argsString}}`;
333
340
  };
334
341
 
335
342
  // src/openapi/parser.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebspark/openapi-typegen",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",