@sdk-it/spec 0.45.0 → 0.46.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.
Files changed (121) hide show
  1. package/dist/index.d.ts +5 -3
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +9 -3
  4. package/dist/index.js.map +2 -2
  5. package/dist/lib/find-polymorphic-varients.d.ts.map +1 -1
  6. package/dist/lib/find-polymorphic-varients.js +5 -10
  7. package/dist/lib/find-polymorphic-varients.js.map +2 -2
  8. package/dist/lib/for-each-operation.d.ts +11 -3
  9. package/dist/lib/for-each-operation.d.ts.map +1 -1
  10. package/dist/lib/for-each-operation.js +23 -15
  11. package/dist/lib/for-each-operation.js.map +2 -2
  12. package/dist/lib/format-name.d.ts.map +1 -1
  13. package/dist/lib/format-name.js +0 -1
  14. package/dist/lib/format-name.js.map +2 -2
  15. package/dist/lib/ir.d.ts +2 -2
  16. package/dist/lib/ir.d.ts.map +1 -1
  17. package/dist/lib/ir.js +6 -120
  18. package/dist/lib/ir.js.map +2 -2
  19. package/dist/lib/is.d.ts.map +1 -1
  20. package/dist/lib/is.js +1 -3
  21. package/dist/lib/is.js.map +2 -2
  22. package/dist/lib/loaders/postman/postman-converter.d.ts.map +1 -1
  23. package/dist/lib/loaders/postman/postman-converter.js +1 -11
  24. package/dist/lib/loaders/postman/postman-converter.js.map +2 -2
  25. package/dist/lib/options.d.ts +7 -45
  26. package/dist/lib/options.d.ts.map +1 -1
  27. package/dist/lib/options.js +26 -28
  28. package/dist/lib/options.js.map +2 -2
  29. package/dist/lib/overview-docs/overview-pagination.d.ts +1 -1
  30. package/dist/lib/overview-docs/overview-pagination.d.ts.map +1 -1
  31. package/dist/lib/overview-docs/overview-pagination.js +1 -1
  32. package/dist/lib/overview-docs/overview-pagination.js.map +2 -2
  33. package/dist/lib/pagination/guess-pagination.d.ts.map +1 -1
  34. package/dist/lib/pagination/guess-pagination.js.map +2 -2
  35. package/dist/lib/pagination/pagination-result.d.ts.map +1 -1
  36. package/dist/lib/pagination/pagination-result.js +15 -5
  37. package/dist/lib/pagination/pagination-result.js.map +2 -2
  38. package/dist/lib/pagination/pagination.d.ts.map +1 -1
  39. package/dist/lib/pagination/pagination.js +7 -6
  40. package/dist/lib/pagination/pagination.js.map +2 -2
  41. package/dist/lib/processing-plugins/canonicalize-spec.d.ts +3 -0
  42. package/dist/lib/processing-plugins/canonicalize-spec.d.ts.map +1 -0
  43. package/dist/lib/processing-plugins/canonicalize-spec.js +29 -0
  44. package/dist/lib/processing-plugins/canonicalize-spec.js.map +7 -0
  45. package/dist/lib/processing-plugins/create-default-processing-plugins.d.ts +5 -0
  46. package/dist/lib/processing-plugins/create-default-processing-plugins.d.ts.map +1 -0
  47. package/dist/lib/processing-plugins/create-default-processing-plugins.js +30 -0
  48. package/dist/lib/processing-plugins/create-default-processing-plugins.js.map +7 -0
  49. package/dist/lib/processing-plugins/enrich-examples.d.ts +25 -0
  50. package/dist/lib/processing-plugins/enrich-examples.d.ts.map +1 -0
  51. package/dist/lib/processing-plugins/enrich-examples.js +93 -0
  52. package/dist/lib/processing-plugins/enrich-examples.js.map +7 -0
  53. package/dist/lib/processing-plugins/extract-inline-schemas.d.ts +3 -0
  54. package/dist/lib/processing-plugins/extract-inline-schemas.d.ts.map +1 -0
  55. package/dist/lib/processing-plugins/extract-inline-schemas.js +14 -0
  56. package/dist/lib/processing-plugins/extract-inline-schemas.js.map +7 -0
  57. package/dist/lib/processing-plugins/extract-overview-docs.d.ts +3 -0
  58. package/dist/lib/processing-plugins/extract-overview-docs.d.ts.map +1 -0
  59. package/dist/lib/processing-plugins/extract-overview-docs.js +13 -0
  60. package/dist/lib/processing-plugins/extract-overview-docs.js.map +7 -0
  61. package/dist/lib/processing-plugins/index.d.ts +14 -0
  62. package/dist/lib/processing-plugins/index.d.ts.map +1 -0
  63. package/dist/lib/processing-plugins/index.js +14 -0
  64. package/dist/lib/processing-plugins/index.js.map +7 -0
  65. package/dist/lib/processing-plugins/infer-pagination.d.ts +3 -0
  66. package/dist/lib/processing-plugins/infer-pagination.d.ts.map +1 -0
  67. package/dist/lib/processing-plugins/infer-pagination.js +21 -0
  68. package/dist/lib/processing-plugins/infer-pagination.js.map +7 -0
  69. package/dist/lib/processing-plugins/normalize-operation-ids.d.ts +3 -0
  70. package/dist/lib/processing-plugins/normalize-operation-ids.d.ts.map +1 -0
  71. package/dist/lib/processing-plugins/normalize-operation-ids.js +74 -0
  72. package/dist/lib/processing-plugins/normalize-operation-ids.js.map +7 -0
  73. package/dist/lib/processing-plugins/normalize-parameters.d.ts +3 -0
  74. package/dist/lib/processing-plugins/normalize-parameters.d.ts.map +1 -0
  75. package/dist/lib/processing-plugins/normalize-parameters.js +29 -0
  76. package/dist/lib/processing-plugins/normalize-parameters.js.map +7 -0
  77. package/dist/lib/processing-plugins/normalize-paths.d.ts +3 -0
  78. package/dist/lib/processing-plugins/normalize-paths.d.ts.map +1 -0
  79. package/dist/lib/processing-plugins/normalize-paths.js +67 -0
  80. package/dist/lib/processing-plugins/normalize-paths.js.map +7 -0
  81. package/dist/lib/processing-plugins/normalize-request-bodies.d.ts +3 -0
  82. package/dist/lib/processing-plugins/normalize-request-bodies.d.ts.map +1 -0
  83. package/dist/lib/processing-plugins/normalize-request-bodies.js +44 -0
  84. package/dist/lib/processing-plugins/normalize-request-bodies.js.map +7 -0
  85. package/dist/lib/processing-plugins/normalize-responses.d.ts +3 -0
  86. package/dist/lib/processing-plugins/normalize-responses.d.ts.map +1 -0
  87. package/dist/lib/processing-plugins/normalize-responses.js +38 -0
  88. package/dist/lib/processing-plugins/normalize-responses.js.map +7 -0
  89. package/dist/lib/processing-plugins/normalize-schemas.d.ts +3 -0
  90. package/dist/lib/processing-plugins/normalize-schemas.d.ts.map +1 -0
  91. package/dist/lib/processing-plugins/normalize-schemas.js +13 -0
  92. package/dist/lib/processing-plugins/normalize-schemas.js.map +7 -0
  93. package/dist/lib/processing-plugins/normalize-tags.d.ts +3 -0
  94. package/dist/lib/processing-plugins/normalize-tags.d.ts.map +1 -0
  95. package/dist/lib/processing-plugins/normalize-tags.js +18 -0
  96. package/dist/lib/processing-plugins/normalize-tags.js.map +7 -0
  97. package/dist/lib/processing.d.ts +33 -0
  98. package/dist/lib/processing.d.ts.map +1 -0
  99. package/dist/lib/processing.js +41 -0
  100. package/dist/lib/processing.js.map +7 -0
  101. package/dist/lib/reserved-keywords.d.ts.map +1 -1
  102. package/dist/lib/reserved-keywords.js +18 -1
  103. package/dist/lib/reserved-keywords.js.map +2 -2
  104. package/dist/lib/tag.js +2 -2
  105. package/dist/lib/tag.js.map +2 -2
  106. package/dist/lib/tune-request-body.d.ts.map +1 -1
  107. package/dist/lib/tune-request-body.js +22 -12
  108. package/dist/lib/tune-request-body.js.map +2 -2
  109. package/dist/lib/tune-response.d.ts.map +1 -1
  110. package/dist/lib/tune-response.js +16 -12
  111. package/dist/lib/tune-response.js.map +2 -2
  112. package/dist/lib/tune.d.ts.map +1 -1
  113. package/dist/lib/tune.js +31 -7
  114. package/dist/lib/tune.js.map +2 -2
  115. package/dist/lib/types.d.ts +4 -1
  116. package/dist/lib/types.d.ts.map +1 -1
  117. package/dist/lib/walk-schemas.d.ts +8 -0
  118. package/dist/lib/walk-schemas.d.ts.map +1 -0
  119. package/dist/lib/walk-schemas.js +51 -0
  120. package/dist/lib/walk-schemas.js.map +7 -0
  121. package/package.json +2 -2
@@ -0,0 +1,67 @@
1
+ import { methods } from "@sdk-it/core/paths.js";
2
+ import { followRef } from "@sdk-it/core/ref.js";
3
+ function normalizePaths() {
4
+ return {
5
+ name: "normalize-paths",
6
+ process({ spec, report }) {
7
+ const paths = {};
8
+ const operationSources = /* @__PURE__ */ new Map();
9
+ for (const [path, pathItem] of Object.entries(spec.paths)) {
10
+ const normalizedPath = path.replace(/:([^/]+)/g, "{$1}");
11
+ const target = paths[normalizedPath] ??= {};
12
+ const source = pathItem.$ref ? {
13
+ ...followRef(spec, pathItem.$ref),
14
+ ...pathItem
15
+ } : pathItem;
16
+ delete source.$ref;
17
+ Object.assign(
18
+ target,
19
+ Object.fromEntries(
20
+ Object.entries(source).filter(
21
+ ([key]) => key !== "parameters" && !methods.some((method) => method === key)
22
+ )
23
+ )
24
+ );
25
+ for (const method of methods) {
26
+ const operation = source[method];
27
+ if (operation) {
28
+ const operationKey = `${normalizedPath}:${method}`;
29
+ const previousPath = operationSources.get(operationKey);
30
+ if (previousPath) {
31
+ const message = `Both ${previousPath} and ${path} define ${method.toUpperCase()} after path normalization`;
32
+ report({
33
+ severity: "error",
34
+ code: "path-operation-collision",
35
+ message,
36
+ path: `${method.toUpperCase()} ${normalizedPath}`
37
+ });
38
+ throw new Error(message);
39
+ }
40
+ const parameters = [
41
+ ...source.parameters ?? [],
42
+ ...operation.parameters ?? []
43
+ ];
44
+ target[method] = {
45
+ ...operation,
46
+ ...parameters.length > 0 ? { parameters } : {}
47
+ };
48
+ operationSources.set(operationKey, path);
49
+ }
50
+ }
51
+ if (normalizedPath !== path) {
52
+ report({
53
+ severity: "info",
54
+ code: "path-normalized",
55
+ message: `Normalized path ${path} to ${normalizedPath}`,
56
+ path
57
+ });
58
+ }
59
+ }
60
+ spec.paths = paths;
61
+ }
62
+ };
63
+ }
64
+ export {
65
+ normalizePaths
66
+ };
67
+ //# sourceMappingURL=normalize-paths.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/lib/processing-plugins/normalize-paths.ts"],
4
+ "sourcesContent": ["import type { PathItemObject, PathsObject } from 'openapi3-ts/oas31';\n\nimport { methods } from '@sdk-it/core/paths.js';\nimport { followRef } from '@sdk-it/core/ref.js';\n\nimport type { ProcessingPlugin } from '../processing.js';\n\nexport function normalizePaths(): ProcessingPlugin {\n return {\n name: 'normalize-paths',\n process({ spec, report }) {\n const paths: PathsObject = {};\n const operationSources = new Map<string, string>();\n for (const [path, pathItem] of Object.entries(spec.paths)) {\n const normalizedPath = path.replace(/:([^/]+)/g, '{$1}');\n const target = (paths[normalizedPath] ??= {});\n const source = pathItem.$ref\n ? {\n ...followRef<PathItemObject>(spec, pathItem.$ref),\n ...pathItem,\n }\n : pathItem;\n delete source.$ref;\n Object.assign(\n target,\n Object.fromEntries(\n Object.entries(source).filter(\n ([key]) =>\n key !== 'parameters' &&\n !methods.some((method) => method === key),\n ),\n ),\n );\n for (const method of methods) {\n const operation = source[method];\n if (operation) {\n const operationKey = `${normalizedPath}:${method}`;\n const previousPath = operationSources.get(operationKey);\n if (previousPath) {\n const message = `Both ${previousPath} and ${path} define ${method.toUpperCase()} after path normalization`;\n report({\n severity: 'error',\n code: 'path-operation-collision',\n message,\n path: `${method.toUpperCase()} ${normalizedPath}`,\n });\n throw new Error(message);\n }\n const parameters = [\n ...(source.parameters ?? []),\n ...(operation.parameters ?? []),\n ];\n target[method] = {\n ...operation,\n ...(parameters.length > 0 ? { parameters } : {}),\n };\n operationSources.set(operationKey, path);\n }\n }\n if (normalizedPath !== path) {\n report({\n severity: 'info',\n code: 'path-normalized',\n message: `Normalized path ${path} to ${normalizedPath}`,\n path,\n });\n }\n }\n spec.paths = paths;\n },\n };\n}\n"],
5
+ "mappings": "AAEA,SAAS,eAAe;AACxB,SAAS,iBAAiB;AAInB,SAAS,iBAAmC;AACjD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ,EAAE,MAAM,OAAO,GAAG;AACxB,YAAM,QAAqB,CAAC;AAC5B,YAAM,mBAAmB,oBAAI,IAAoB;AACjD,iBAAW,CAAC,MAAM,QAAQ,KAAK,OAAO,QAAQ,KAAK,KAAK,GAAG;AACzD,cAAM,iBAAiB,KAAK,QAAQ,aAAa,MAAM;AACvD,cAAM,SAAU,MAAM,cAAc,MAAM,CAAC;AAC3C,cAAM,SAAS,SAAS,OACpB;AAAA,UACE,GAAG,UAA0B,MAAM,SAAS,IAAI;AAAA,UAChD,GAAG;AAAA,QACL,IACA;AACJ,eAAO,OAAO;AACd,eAAO;AAAA,UACL;AAAA,UACA,OAAO;AAAA,YACL,OAAO,QAAQ,MAAM,EAAE;AAAA,cACrB,CAAC,CAAC,GAAG,MACH,QAAQ,gBACR,CAAC,QAAQ,KAAK,CAAC,WAAW,WAAW,GAAG;AAAA,YAC5C;AAAA,UACF;AAAA,QACF;AACA,mBAAW,UAAU,SAAS;AAC5B,gBAAM,YAAY,OAAO,MAAM;AAC/B,cAAI,WAAW;AACb,kBAAM,eAAe,GAAG,cAAc,IAAI,MAAM;AAChD,kBAAM,eAAe,iBAAiB,IAAI,YAAY;AACtD,gBAAI,cAAc;AAChB,oBAAM,UAAU,QAAQ,YAAY,QAAQ,IAAI,WAAW,OAAO,YAAY,CAAC;AAC/E,qBAAO;AAAA,gBACL,UAAU;AAAA,gBACV,MAAM;AAAA,gBACN;AAAA,gBACA,MAAM,GAAG,OAAO,YAAY,CAAC,IAAI,cAAc;AAAA,cACjD,CAAC;AACD,oBAAM,IAAI,MAAM,OAAO;AAAA,YACzB;AACA,kBAAM,aAAa;AAAA,cACjB,GAAI,OAAO,cAAc,CAAC;AAAA,cAC1B,GAAI,UAAU,cAAc,CAAC;AAAA,YAC/B;AACA,mBAAO,MAAM,IAAI;AAAA,cACf,GAAG;AAAA,cACH,GAAI,WAAW,SAAS,IAAI,EAAE,WAAW,IAAI,CAAC;AAAA,YAChD;AACA,6BAAiB,IAAI,cAAc,IAAI;AAAA,UACzC;AAAA,QACF;AACA,YAAI,mBAAmB,MAAM;AAC3B,iBAAO;AAAA,YACL,UAAU;AAAA,YACV,MAAM;AAAA,YACN,SAAS,mBAAmB,IAAI,OAAO,cAAc;AAAA,YACrD;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF;AACA,WAAK,QAAQ;AAAA,IACf;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,3 @@
1
+ import type { ProcessingPlugin } from '../processing.js';
2
+ export declare function normalizeRequestBodies(): ProcessingPlugin;
3
+ //# sourceMappingURL=normalize-request-bodies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-request-bodies.d.ts","sourceRoot":"","sources":["../../../src/lib/processing-plugins/normalize-request-bodies.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAIzD,wBAAgB,sBAAsB,IAAI,gBAAgB,CAwCzD"}
@@ -0,0 +1,44 @@
1
+ import { resolveRef } from "@sdk-it/core/ref.js";
2
+ import { iterateOperations } from "../for-each-operation.js";
3
+ import { patchParameters, tuneRequestBody } from "../tune-request-body.js";
4
+ function normalizeRequestBodies() {
5
+ return {
6
+ name: "normalize-request-bodies",
7
+ process({ spec }) {
8
+ for (const { operation } of iterateOperations(spec)) {
9
+ const tunedOperation = operation;
10
+ if (operation.requestBody) {
11
+ const requestBody = resolveRef(
12
+ spec,
13
+ operation.requestBody
14
+ );
15
+ const schemas = Object.values(requestBody.content).map(
16
+ ({ schema }) => schema ? resolveRef(spec, schema) : void 0
17
+ );
18
+ if (schemas.length > 0 && schemas.every((schema) => schema?.["x-requestbody"])) {
19
+ for (const schema of new Set(schemas)) {
20
+ patchParameters(
21
+ spec,
22
+ schema,
23
+ tunedOperation.parameters,
24
+ operation.security ?? []
25
+ );
26
+ }
27
+ continue;
28
+ }
29
+ }
30
+ tunedOperation.requestBody = tuneRequestBody(
31
+ spec,
32
+ tunedOperation.operationId,
33
+ operation,
34
+ tunedOperation.parameters,
35
+ operation.security ?? []
36
+ );
37
+ }
38
+ }
39
+ };
40
+ }
41
+ export {
42
+ normalizeRequestBodies
43
+ };
44
+ //# sourceMappingURL=normalize-request-bodies.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/lib/processing-plugins/normalize-request-bodies.ts"],
4
+ "sourcesContent": ["import type { RequestBodyObject, SchemaObject } from 'openapi3-ts/oas31';\n\nimport { resolveRef } from '@sdk-it/core/ref.js';\n\nimport { iterateOperations } from '../for-each-operation.js';\nimport type { ProcessingPlugin } from '../processing.js';\nimport { patchParameters, tuneRequestBody } from '../tune-request-body.js';\nimport type { TunedOperationObject } from '../types.js';\n\nexport function normalizeRequestBodies(): ProcessingPlugin {\n return {\n name: 'normalize-request-bodies',\n process({ spec }) {\n for (const { operation } of iterateOperations(spec)) {\n const tunedOperation = operation as TunedOperationObject;\n if (operation.requestBody) {\n const requestBody = resolveRef<RequestBodyObject>(\n spec,\n operation.requestBody,\n );\n const schemas = Object.values(requestBody.content).map(\n ({ schema }) =>\n schema ? resolveRef<SchemaObject>(spec, schema) : undefined,\n );\n if (\n schemas.length > 0 &&\n schemas.every((schema) => schema?.['x-requestbody'])\n ) {\n for (const schema of new Set(schemas)) {\n patchParameters(\n spec,\n schema as SchemaObject,\n tunedOperation.parameters,\n operation.security ?? [],\n );\n }\n continue;\n }\n }\n tunedOperation.requestBody = tuneRequestBody(\n spec,\n tunedOperation.operationId,\n operation,\n tunedOperation.parameters,\n operation.security ?? [],\n );\n }\n },\n };\n}\n"],
5
+ "mappings": "AAEA,SAAS,kBAAkB;AAE3B,SAAS,yBAAyB;AAElC,SAAS,iBAAiB,uBAAuB;AAG1C,SAAS,yBAA2C;AACzD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ,EAAE,KAAK,GAAG;AAChB,iBAAW,EAAE,UAAU,KAAK,kBAAkB,IAAI,GAAG;AACnD,cAAM,iBAAiB;AACvB,YAAI,UAAU,aAAa;AACzB,gBAAM,cAAc;AAAA,YAClB;AAAA,YACA,UAAU;AAAA,UACZ;AACA,gBAAM,UAAU,OAAO,OAAO,YAAY,OAAO,EAAE;AAAA,YACjD,CAAC,EAAE,OAAO,MACR,SAAS,WAAyB,MAAM,MAAM,IAAI;AAAA,UACtD;AACA,cACE,QAAQ,SAAS,KACjB,QAAQ,MAAM,CAAC,WAAW,SAAS,eAAe,CAAC,GACnD;AACA,uBAAW,UAAU,IAAI,IAAI,OAAO,GAAG;AACrC;AAAA,gBACE;AAAA,gBACA;AAAA,gBACA,eAAe;AAAA,gBACf,UAAU,YAAY,CAAC;AAAA,cACzB;AAAA,YACF;AACA;AAAA,UACF;AAAA,QACF;AACA,uBAAe,cAAc;AAAA,UAC3B;AAAA,UACA,eAAe;AAAA,UACf;AAAA,UACA,eAAe;AAAA,UACf,UAAU,YAAY,CAAC;AAAA,QACzB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,3 @@
1
+ import type { ProcessingPlugin } from '../processing.js';
2
+ export declare function normalizeResponses(): ProcessingPlugin;
3
+ //# sourceMappingURL=normalize-responses.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-responses.d.ts","sourceRoot":"","sources":["../../../src/lib/processing-plugins/normalize-responses.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAIzD,wBAAgB,kBAAkB,IAAI,gBAAgB,CA8BrD"}
@@ -0,0 +1,38 @@
1
+ import { iterateOperations } from "../for-each-operation.js";
2
+ import { isSuccessStatusCode } from "../is.js";
3
+ import { resolveResponses } from "../tune-response.js";
4
+ function normalizeResponses() {
5
+ return {
6
+ name: "normalize-responses",
7
+ process({ spec, options, report }) {
8
+ for (const { entry, operation } of iterateOperations(spec)) {
9
+ if (!operation.operationId) {
10
+ throw new Error(
11
+ `Cannot normalize responses before assigning an operation ID for ${entry.method.toUpperCase()} ${entry.path}`
12
+ );
13
+ }
14
+ const hadSuccessResponse = Object.keys(operation.responses ?? {}).some(
15
+ isSuccessStatusCode
16
+ );
17
+ operation.responses = resolveResponses(
18
+ spec,
19
+ operation.operationId,
20
+ operation,
21
+ options.responses
22
+ );
23
+ if (!hadSuccessResponse) {
24
+ report({
25
+ severity: "warning",
26
+ code: "success-response-added",
27
+ message: "Added a default 200 success response",
28
+ path: `${entry.method.toUpperCase()} ${entry.path}`
29
+ });
30
+ }
31
+ }
32
+ }
33
+ };
34
+ }
35
+ export {
36
+ normalizeResponses
37
+ };
38
+ //# sourceMappingURL=normalize-responses.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/lib/processing-plugins/normalize-responses.ts"],
4
+ "sourcesContent": ["import { iterateOperations } from '../for-each-operation.js';\nimport { isSuccessStatusCode } from '../is.js';\nimport type { ProcessingPlugin } from '../processing.js';\nimport { resolveResponses } from '../tune-response.js';\nimport type { TunedOperationObject } from '../types.js';\n\nexport function normalizeResponses(): ProcessingPlugin {\n return {\n name: 'normalize-responses',\n process({ spec, options, report }) {\n for (const { entry, operation } of iterateOperations(spec)) {\n if (!operation.operationId) {\n throw new Error(\n `Cannot normalize responses before assigning an operation ID for ${entry.method.toUpperCase()} ${entry.path}`,\n );\n }\n const hadSuccessResponse = Object.keys(operation.responses ?? {}).some(\n isSuccessStatusCode,\n );\n (operation as TunedOperationObject).responses = resolveResponses(\n spec,\n operation.operationId,\n operation,\n options.responses,\n );\n if (!hadSuccessResponse) {\n report({\n severity: 'warning',\n code: 'success-response-added',\n message: 'Added a default 200 success response',\n path: `${entry.method.toUpperCase()} ${entry.path}`,\n });\n }\n }\n },\n };\n}\n"],
5
+ "mappings": "AAAA,SAAS,yBAAyB;AAClC,SAAS,2BAA2B;AAEpC,SAAS,wBAAwB;AAG1B,SAAS,qBAAuC;AACrD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ,EAAE,MAAM,SAAS,OAAO,GAAG;AACjC,iBAAW,EAAE,OAAO,UAAU,KAAK,kBAAkB,IAAI,GAAG;AAC1D,YAAI,CAAC,UAAU,aAAa;AAC1B,gBAAM,IAAI;AAAA,YACR,mEAAmE,MAAM,OAAO,YAAY,CAAC,IAAI,MAAM,IAAI;AAAA,UAC7G;AAAA,QACF;AACA,cAAM,qBAAqB,OAAO,KAAK,UAAU,aAAa,CAAC,CAAC,EAAE;AAAA,UAChE;AAAA,QACF;AACA,QAAC,UAAmC,YAAY;AAAA,UAC9C;AAAA,UACA,UAAU;AAAA,UACV;AAAA,UACA,QAAQ;AAAA,QACV;AACA,YAAI,CAAC,oBAAoB;AACvB,iBAAO;AAAA,YACL,UAAU;AAAA,YACV,MAAM;AAAA,YACN,SAAS;AAAA,YACT,MAAM,GAAG,MAAM,OAAO,YAAY,CAAC,IAAI,MAAM,IAAI;AAAA,UACnD,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,3 @@
1
+ import type { ProcessingPlugin } from '../processing.js';
2
+ export declare function normalizeSchemas(): ProcessingPlugin;
3
+ //# sourceMappingURL=normalize-schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-schemas.d.ts","sourceRoot":"","sources":["../../../src/lib/processing-plugins/normalize-schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGzD,wBAAgB,gBAAgB,IAAI,gBAAgB,CAOnD"}
@@ -0,0 +1,13 @@
1
+ import { fixSpec } from "../tune.js";
2
+ function normalizeSchemas() {
3
+ return {
4
+ name: "normalize-schemas",
5
+ process({ spec }) {
6
+ fixSpec(spec, Object.values(spec.components.schemas));
7
+ }
8
+ };
9
+ }
10
+ export {
11
+ normalizeSchemas
12
+ };
13
+ //# sourceMappingURL=normalize-schemas.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/lib/processing-plugins/normalize-schemas.ts"],
4
+ "sourcesContent": ["import type { ProcessingPlugin } from '../processing.js';\nimport { fixSpec } from '../tune.js';\n\nexport function normalizeSchemas(): ProcessingPlugin {\n return {\n name: 'normalize-schemas',\n process({ spec }) {\n fixSpec(spec, Object.values(spec.components.schemas));\n },\n };\n}\n"],
5
+ "mappings": "AACA,SAAS,eAAe;AAEjB,SAAS,mBAAqC;AACnD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ,EAAE,KAAK,GAAG;AAChB,cAAQ,MAAM,OAAO,OAAO,KAAK,WAAW,OAAO,CAAC;AAAA,IACtD;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,3 @@
1
+ import type { ProcessingPlugin } from '../processing.js';
2
+ export declare function normalizeTags(): ProcessingPlugin;
3
+ //# sourceMappingURL=normalize-tags.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-tags.d.ts","sourceRoot":"","sources":["../../../src/lib/processing-plugins/normalize-tags.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,wBAAgB,aAAa,IAAI,gBAAgB,CAWhD"}
@@ -0,0 +1,18 @@
1
+ import { snakecase } from "@sdk-it/core/utils.js";
2
+ import { iterateOperations } from "../for-each-operation.js";
3
+ function normalizeTags() {
4
+ return {
5
+ name: "normalize-tags",
6
+ process({ spec, options }) {
7
+ for (const { entry, operation } of iterateOperations(spec)) {
8
+ const tag = options.tag(operation, entry.path);
9
+ operation["x-fn-group"] = tag;
10
+ operation.tags = [snakecase(tag)];
11
+ }
12
+ }
13
+ };
14
+ }
15
+ export {
16
+ normalizeTags
17
+ };
18
+ //# sourceMappingURL=normalize-tags.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/lib/processing-plugins/normalize-tags.ts"],
4
+ "sourcesContent": ["import { snakecase } from '@sdk-it/core/utils.js';\n\nimport { iterateOperations } from '../for-each-operation.js';\nimport type { ProcessingPlugin } from '../processing.js';\n\nexport function normalizeTags(): ProcessingPlugin {\n return {\n name: 'normalize-tags',\n process({ spec, options }) {\n for (const { entry, operation } of iterateOperations(spec)) {\n const tag = options.tag(operation, entry.path);\n operation['x-fn-group'] = tag;\n operation.tags = [snakecase(tag)];\n }\n },\n };\n}\n"],
5
+ "mappings": "AAAA,SAAS,iBAAiB;AAE1B,SAAS,yBAAyB;AAG3B,SAAS,gBAAkC;AAChD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ,EAAE,MAAM,QAAQ,GAAG;AACzB,iBAAW,EAAE,OAAO,UAAU,KAAK,kBAAkB,IAAI,GAAG;AAC1D,cAAM,MAAM,QAAQ,IAAI,WAAW,MAAM,IAAI;AAC7C,kBAAU,YAAY,IAAI;AAC1B,kBAAU,OAAO,CAAC,UAAU,GAAG,CAAC;AAAA,MAClC;AAAA,IACF;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,33 @@
1
+ import { type GenerateSdkConfig, coeraceConfig as coerceConfig } from './options.js';
2
+ import type { IR } from './types.js';
3
+ export type ProcessingDiagnosticSeverity = 'info' | 'warning' | 'error';
4
+ export interface ProcessingDiagnostic {
5
+ plugin: string;
6
+ severity: ProcessingDiagnosticSeverity;
7
+ code: string;
8
+ message: string;
9
+ path?: string;
10
+ }
11
+ export type ProcessingOptions = Omit<ReturnType<typeof coerceConfig>, 'spec'>;
12
+ export interface ProcessingContext {
13
+ spec: IR;
14
+ options: ProcessingOptions;
15
+ diagnostics: ProcessingDiagnostic[];
16
+ signal?: AbortSignal;
17
+ report(diagnostic: Omit<ProcessingDiagnostic, 'plugin'>): ProcessingDiagnostic;
18
+ }
19
+ export interface ProcessingPlugin {
20
+ name: string;
21
+ process(context: ProcessingContext): void | Promise<void>;
22
+ }
23
+ export interface ProcessSpecConfig extends GenerateSdkConfig {
24
+ plugins: readonly ProcessingPlugin[];
25
+ signal?: AbortSignal;
26
+ onDiagnostic?: (diagnostic: ProcessingDiagnostic) => void;
27
+ }
28
+ export interface ProcessingResult {
29
+ spec: IR;
30
+ diagnostics: ProcessingDiagnostic[];
31
+ }
32
+ export declare function processSpec(config: ProcessSpecConfig): Promise<ProcessingResult>;
33
+ //# sourceMappingURL=processing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processing.d.ts","sourceRoot":"","sources":["../../src/lib/processing.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,iBAAiB,EACtB,aAAa,IAAI,YAAY,EAC9B,MAAM,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1,41 @@
1
+ import {
2
+ coeraceConfig as coerceConfig
3
+ } from "./options.js";
4
+ async function processSpec(config) {
5
+ const { plugins, signal, onDiagnostic, ...generateConfig } = config;
6
+ signal?.throwIfAborted();
7
+ const coerced = coerceConfig({
8
+ ...generateConfig,
9
+ spec: structuredClone(generateConfig.spec)
10
+ });
11
+ const { spec, ...options } = coerced;
12
+ const diagnostics = [];
13
+ const pluginNames = plugins.map((plugin) => plugin.name);
14
+ const configuration = JSON.stringify({
15
+ pagination: options.pagination,
16
+ responses: options.responses
17
+ });
18
+ for (const plugin of plugins) {
19
+ signal?.throwIfAborted();
20
+ const context = {
21
+ spec,
22
+ options,
23
+ diagnostics,
24
+ signal,
25
+ report(diagnostic) {
26
+ const reported = { ...diagnostic, plugin: plugin.name };
27
+ diagnostics.push(reported);
28
+ onDiagnostic?.(reported);
29
+ return reported;
30
+ }
31
+ };
32
+ await plugin.process(context);
33
+ signal?.throwIfAborted();
34
+ }
35
+ spec["x-sdk-processing"] = { plugins: pluginNames, configuration };
36
+ return { spec, diagnostics };
37
+ }
38
+ export {
39
+ processSpec
40
+ };
41
+ //# sourceMappingURL=processing.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/lib/processing.ts"],
4
+ "sourcesContent": ["import type { OpenAPIObject } from 'openapi3-ts/oas31';\n\nimport {\n type GenerateSdkConfig,\n coeraceConfig as coerceConfig,\n} from './options.js';\nimport type { IR } from './types.js';\n\nexport type ProcessingDiagnosticSeverity = 'info' | 'warning' | 'error';\n\nexport interface ProcessingDiagnostic {\n plugin: string;\n severity: ProcessingDiagnosticSeverity;\n code: string;\n message: string;\n path?: string;\n}\n\nexport type ProcessingOptions = Omit<ReturnType<typeof coerceConfig>, 'spec'>;\n\nexport interface ProcessingContext {\n spec: IR;\n options: ProcessingOptions;\n diagnostics: ProcessingDiagnostic[];\n signal?: AbortSignal;\n report(\n diagnostic: Omit<ProcessingDiagnostic, 'plugin'>,\n ): ProcessingDiagnostic;\n}\n\nexport interface ProcessingPlugin {\n name: string;\n process(context: ProcessingContext): void | Promise<void>;\n}\n\nexport interface ProcessSpecConfig extends GenerateSdkConfig {\n plugins: readonly ProcessingPlugin[];\n signal?: AbortSignal;\n onDiagnostic?: (diagnostic: ProcessingDiagnostic) => void;\n}\n\nexport interface ProcessingResult {\n spec: IR;\n diagnostics: ProcessingDiagnostic[];\n}\n\nexport async function processSpec(\n config: ProcessSpecConfig,\n): Promise<ProcessingResult> {\n const { plugins, signal, onDiagnostic, ...generateConfig } = config;\n signal?.throwIfAborted();\n const coerced = coerceConfig({\n ...generateConfig,\n spec: structuredClone(generateConfig.spec) as OpenAPIObject,\n });\n const { spec, ...options } = coerced;\n const diagnostics: ProcessingDiagnostic[] = [];\n const pluginNames = plugins.map((plugin) => plugin.name);\n const configuration = JSON.stringify({\n pagination: options.pagination,\n responses: options.responses,\n });\n\n for (const plugin of plugins) {\n signal?.throwIfAborted();\n const context: ProcessingContext = {\n spec,\n options,\n diagnostics,\n signal,\n report(diagnostic) {\n const reported = { ...diagnostic, plugin: plugin.name };\n diagnostics.push(reported);\n onDiagnostic?.(reported);\n return reported;\n },\n };\n await plugin.process(context);\n signal?.throwIfAborted();\n }\n\n spec['x-sdk-processing'] = { plugins: pluginNames, configuration };\n\n return { spec, diagnostics };\n}\n"],
5
+ "mappings": "AAEA;AAAA,EAEE,iBAAiB;AAAA,OACZ;AAyCP,eAAsB,YACpB,QAC2B;AAC3B,QAAM,EAAE,SAAS,QAAQ,cAAc,GAAG,eAAe,IAAI;AAC7D,UAAQ,eAAe;AACvB,QAAM,UAAU,aAAa;AAAA,IAC3B,GAAG;AAAA,IACH,MAAM,gBAAgB,eAAe,IAAI;AAAA,EAC3C,CAAC;AACD,QAAM,EAAE,MAAM,GAAG,QAAQ,IAAI;AAC7B,QAAM,cAAsC,CAAC;AAC7C,QAAM,cAAc,QAAQ,IAAI,CAAC,WAAW,OAAO,IAAI;AACvD,QAAM,gBAAgB,KAAK,UAAU;AAAA,IACnC,YAAY,QAAQ;AAAA,IACpB,WAAW,QAAQ;AAAA,EACrB,CAAC;AAED,aAAW,UAAU,SAAS;AAC5B,YAAQ,eAAe;AACvB,UAAM,UAA6B;AAAA,MACjC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,OAAO,YAAY;AACjB,cAAM,WAAW,EAAE,GAAG,YAAY,QAAQ,OAAO,KAAK;AACtD,oBAAY,KAAK,QAAQ;AACzB,uBAAe,QAAQ;AACvB,eAAO;AAAA,MACT;AAAA,IACF;AACA,UAAM,OAAO,QAAQ,OAAO;AAC5B,YAAQ,eAAe;AAAA,EACzB;AAEA,OAAK,kBAAkB,IAAI,EAAE,SAAS,aAAa,cAAc;AAEjE,SAAO,EAAE,MAAM,YAAY;AAC7B;",
6
+ "names": []
7
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"reserved-keywords.d.ts","sourceRoot":"","sources":["../../src/lib/reserved-keywords.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,gBAAgB,aAkD3B,CAAC;AAEH,eAAO,MAAM,mBAAmB,aAI9B,CAAC"}
1
+ {"version":3,"file":"reserved-keywords.d.ts","sourceRoot":"","sources":["../../src/lib/reserved-keywords.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,gBAAgB,aAmE3B,CAAC;AAEH,eAAO,MAAM,mBAAmB,aAI9B,CAAC"}
@@ -57,7 +57,24 @@ const reservedKeywords = /* @__PURE__ */ new Set([
57
57
  // Strict mode / Generator functions
58
58
  // 'arguments' is not technically a reserved word, but it's a special identifier within functions
59
59
  // and assigning to it or declaring it can cause issues or unexpected behavior.
60
- "arguments"
60
+ "arguments",
61
+ // Common operation verbs are ambiguous group identifiers in generated SDKs.
62
+ "get",
63
+ "list",
64
+ "create",
65
+ "update",
66
+ "post",
67
+ "put",
68
+ "patch",
69
+ "do",
70
+ "send",
71
+ "add",
72
+ "remove",
73
+ "set",
74
+ "find",
75
+ "search",
76
+ "check",
77
+ "make"
61
78
  ]);
62
79
  const reservedSdkKeywords = /* @__PURE__ */ new Set([
63
80
  "ClientError",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/lib/reserved-keywords.ts"],
4
- "sourcesContent": ["/**\n * Set of reserved TypeScript keywords and common verbs potentially used as tags.\n */\nexport const reservedKeywords = new Set([\n 'await', // Reserved in async functions\n 'break',\n 'case',\n 'catch',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'else',\n 'enum',\n 'export',\n 'extends',\n 'false',\n 'finally',\n 'for',\n 'function',\n 'if',\n 'implements', // Strict mode\n 'import',\n 'in',\n 'instanceof',\n 'interface', // Strict mode\n 'let', // Strict mode\n 'new',\n 'null',\n 'package', // Strict mode\n 'private', // Strict mode\n 'protected', // Strict mode\n 'public', // Strict mode\n 'return',\n 'static', // Strict mode\n 'super',\n 'switch',\n 'this',\n 'throw',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'while',\n 'with',\n 'yield', // Strict mode / Generator functions\n // 'arguments' is not technically a reserved word, but it's a special identifier within functions\n // and assigning to it or declaring it can cause issues or unexpected behavior.\n 'arguments',\n]);\n\nexport const reservedSdkKeywords = new Set([\n 'ClientError',\n 'Error',\n 'ConflictError',\n]);\n"],
5
- "mappings": "AAGO,MAAM,mBAAmB,oBAAI,IAAI;AAAA,EACtC;AAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA,EAGA;AACF,CAAC;AAEM,MAAM,sBAAsB,oBAAI,IAAI;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AACF,CAAC;",
4
+ "sourcesContent": ["/**\n * Set of reserved TypeScript keywords and common verbs potentially used as tags.\n */\nexport const reservedKeywords = new Set([\n 'await', // Reserved in async functions\n 'break',\n 'case',\n 'catch',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'else',\n 'enum',\n 'export',\n 'extends',\n 'false',\n 'finally',\n 'for',\n 'function',\n 'if',\n 'implements', // Strict mode\n 'import',\n 'in',\n 'instanceof',\n 'interface', // Strict mode\n 'let', // Strict mode\n 'new',\n 'null',\n 'package', // Strict mode\n 'private', // Strict mode\n 'protected', // Strict mode\n 'public', // Strict mode\n 'return',\n 'static', // Strict mode\n 'super',\n 'switch',\n 'this',\n 'throw',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'while',\n 'with',\n 'yield', // Strict mode / Generator functions\n // 'arguments' is not technically a reserved word, but it's a special identifier within functions\n // and assigning to it or declaring it can cause issues or unexpected behavior.\n 'arguments',\n // Common operation verbs are ambiguous group identifiers in generated SDKs.\n 'get',\n 'list',\n 'create',\n 'update',\n 'post',\n 'put',\n 'patch',\n 'do',\n 'send',\n 'add',\n 'remove',\n 'set',\n 'find',\n 'search',\n 'check',\n 'make',\n]);\n\nexport const reservedSdkKeywords = new Set([\n 'ClientError',\n 'Error',\n 'ConflictError',\n]);\n"],
5
+ "mappings": "AAGO,MAAM,mBAAmB,oBAAI,IAAI;AAAA,EACtC;AAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA,EAGA;AAAA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEM,MAAM,sBAAsB,oBAAI,IAAI;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AACF,CAAC;",
6
6
  "names": []
7
7
  }
package/dist/lib/tag.js CHANGED
@@ -6,7 +6,7 @@ function sanitizeTag(tag) {
6
6
  }
7
7
  tag = tag.replace(/[^A-Za-z0-9_-]/g, "").replace(/-+/g, "-");
8
8
  if (reservedKeywords.has(tag) || reservedSdkKeywords.has(tag)) {
9
- return `$${tag}`;
9
+ return `${tag}_`;
10
10
  }
11
11
  return tag;
12
12
  }
@@ -16,7 +16,7 @@ function sanitizeImportName(tag) {
16
16
  }
17
17
  tag = tag.replace(/[^A-Za-z0-9_-]/g, "");
18
18
  if (reservedKeywords.has(tag) || reservedSdkKeywords.has(tag)) {
19
- return `$${tag}`;
19
+ return `${tag}_`;
20
20
  }
21
21
  return tag;
22
22
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/lib/tag.ts"],
4
- "sourcesContent": ["import type { OperationObject } from 'openapi3-ts/oas31';\n\nimport { camelcase } from '@sdk-it/core';\n\nimport { reservedKeywords, reservedSdkKeywords } from './reserved-keywords.js';\n\nexport function sanitizeTag(tag: string): string {\n // Prepend underscore if starts with a number\n if (/^\\d/.test(tag)) {\n return `_${tag}`;\n }\n\n tag = tag\n // Remove any non-alphanumeric characters except underscores and dashes\n .replace(/[^A-Za-z0-9_-]/g, '')\n // Normalize multiple dashes to a single dash\n .replace(/-+/g, '-');\n\n // Append underscore if it's a reserved keyword\n if (reservedKeywords.has(tag) || reservedSdkKeywords.has(tag)) {\n return `$${tag}`;\n }\n return tag;\n}\nexport function sanitizeImportName(tag: string): string {\n // Prepend underscore if starts with a number\n if (/^\\d/.test(tag)) {\n return `_${tag}`;\n }\n\n tag = tag\n // Remove any non-alphanumeric characters except underscores\n .replace(/[^A-Za-z0-9_-]/g, '');\n\n // Append underscore if it's a reserved keyword\n if (reservedKeywords.has(tag) || reservedSdkKeywords.has(tag)) {\n return `$${tag}`;\n }\n return tag;\n}\n\n/**\n * Attempts to determine a generic tag for an OpenAPI operation based on path and operationId.\n * Rules and fallbacks are documented within the code.\n * @param pathString The path string.\n * @param operation The OpenAPI Operation Object.\n * @returns A sanitized, camelCased tag name string.\n */\nexport function determineGenericTag(\n pathString: string,\n operation: OperationObject,\n): string {\n const operationId = operation.operationId || '';\n const VERSION_REGEX = /^[vV]\\d+$/;\n const commonVerbs = new Set([\n // Verbs to potentially strip from operationId prefix\n 'get',\n 'list',\n 'create',\n 'update',\n 'delete',\n 'post',\n 'put',\n 'patch',\n 'do',\n 'send',\n 'add',\n 'remove',\n 'set',\n 'find',\n 'search',\n 'check',\n 'make',\n ]);\n\n const segments = pathString.split('/').filter(Boolean);\n\n const potentialCandidates = segments.filter(\n (segment) =>\n segment &&\n !segment.startsWith('{') &&\n !segment.endsWith('}') &&\n !VERSION_REGEX.test(segment),\n );\n\n // --- Heuristic 1: Last non-'@' path segment ---\n for (let i = potentialCandidates.length - 1; i >= 0; i--) {\n const segment = potentialCandidates[i];\n if (!segment.startsWith('@')) {\n // Sanitize just before returning\n return sanitizeTag(camelcase(segment));\n }\n }\n\n const canFallbackToPathSegment = potentialCandidates.length > 0;\n\n // --- Heuristic 2: OperationId parsing ---\n if (operationId) {\n const lowerOpId = operationId.toLowerCase();\n const parts = operationId\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/([A-Z])([A-Z][a-z])/g, '$1_$2')\n .replace(/([a-zA-Z])(\\d)/g, '$1_$2')\n .replace(/(\\d)([a-zA-Z])/g, '$1_$2')\n .toLowerCase()\n .split(/[_-\\s]+/);\n\n const validParts = parts.filter(Boolean);\n\n // Quick skip: If opId is just a verb and we can use Heuristic 3, prefer that.\n if (\n commonVerbs.has(lowerOpId) &&\n validParts.length === 1 &&\n canFallbackToPathSegment\n ) {\n // Proceed directly to Heuristic 3\n }\n // Only process if there are valid parts and the quick skip didn't happen\n else if (validParts.length > 0) {\n const firstPart = validParts[0];\n const isFirstPartVerb = commonVerbs.has(firstPart);\n\n // Case 2a: Starts with verb, has following parts\n if (isFirstPartVerb && validParts.length > 1) {\n const verbPrefixLength = firstPart.length;\n let nextPartStartIndex = -1;\n if (operationId.length > verbPrefixLength) {\n // Simplified check for next part start\n const charAfterPrefix = operationId[verbPrefixLength];\n if (charAfterPrefix >= 'A' && charAfterPrefix <= 'Z') {\n nextPartStartIndex = verbPrefixLength;\n } else if (charAfterPrefix >= '0' && charAfterPrefix <= '9') {\n nextPartStartIndex = verbPrefixLength;\n } else if (['_', '-'].includes(charAfterPrefix)) {\n nextPartStartIndex = verbPrefixLength + 1;\n } else {\n const match = operationId\n .substring(verbPrefixLength)\n .match(/[A-Z0-9]/);\n if (match && match.index !== undefined) {\n nextPartStartIndex = verbPrefixLength + match.index;\n }\n if (\n nextPartStartIndex === -1 &&\n operationId.length > verbPrefixLength\n ) {\n nextPartStartIndex = verbPrefixLength; // Default guess\n }\n }\n }\n\n if (\n nextPartStartIndex !== -1 &&\n nextPartStartIndex < operationId.length\n ) {\n const remainingOriginalSubstring =\n operationId.substring(nextPartStartIndex);\n const potentialTag = camelcase(remainingOriginalSubstring);\n if (potentialTag) {\n // Sanitize just before returning\n return sanitizeTag(potentialTag);\n }\n }\n\n // Fallback: join remaining lowercased parts\n const potentialTagJoined = camelcase(validParts.slice(1).join('_'));\n if (potentialTagJoined) {\n // Sanitize just before returning\n return sanitizeTag(potentialTagJoined);\n }\n }\n\n // Case 2b: Doesn't start with verb, or only one part (might be verb)\n const potentialTagFull = camelcase(operationId);\n if (potentialTagFull) {\n const isResultSingleVerb = validParts.length === 1 && isFirstPartVerb;\n\n // Avoid returning only a verb if Heuristic 3 is possible\n if (!(isResultSingleVerb && canFallbackToPathSegment)) {\n if (potentialTagFull.length > 0) {\n // Sanitize just before returning\n return sanitizeTag(potentialTagFull);\n }\n }\n }\n\n // Case 2c: Further fallbacks within OpId if above failed/skipped\n const firstPartCamel = camelcase(firstPart);\n if (firstPartCamel) {\n const isFirstPartCamelVerb = commonVerbs.has(firstPartCamel);\n if (\n !isFirstPartCamelVerb ||\n validParts.length === 1 ||\n !canFallbackToPathSegment\n ) {\n // Sanitize just before returning\n return sanitizeTag(firstPartCamel);\n }\n }\n if (\n isFirstPartVerb &&\n validParts.length > 1 &&\n validParts[1] &&\n canFallbackToPathSegment\n ) {\n const secondPartCamel = camelcase(validParts[1]);\n if (secondPartCamel) {\n // Sanitize just before returning\n return sanitizeTag(secondPartCamel);\n }\n }\n } // End if(validParts.length > 0) after quick skip check\n } // End if(operationId)\n\n // --- Heuristic 3: First path segment (stripping '@') ---\n if (potentialCandidates.length > 0) {\n let firstCandidate = potentialCandidates[0];\n if (firstCandidate.startsWith('@')) {\n firstCandidate = firstCandidate.substring(1);\n }\n if (firstCandidate) {\n // Sanitize just before returning\n return sanitizeTag(camelcase(firstCandidate));\n }\n }\n\n // --- Heuristic 4: Default ---\n console.warn(\n `Could not determine a suitable tag for path: ${pathString}, operationId: ${operationId}. Using 'unknown'.`,\n );\n return 'unknown'; // 'unknown' is safe\n}\n"],
5
- "mappings": "AAEA,SAAS,iBAAiB;AAE1B,SAAS,kBAAkB,2BAA2B;AAE/C,SAAS,YAAY,KAAqB;AAE/C,MAAI,MAAM,KAAK,GAAG,GAAG;AACnB,WAAO,IAAI,GAAG;AAAA,EAChB;AAEA,QAAM,IAEH,QAAQ,mBAAmB,EAAE,EAE7B,QAAQ,OAAO,GAAG;AAGrB,MAAI,iBAAiB,IAAI,GAAG,KAAK,oBAAoB,IAAI,GAAG,GAAG;AAC7D,WAAO,IAAI,GAAG;AAAA,EAChB;AACA,SAAO;AACT;AACO,SAAS,mBAAmB,KAAqB;AAEtD,MAAI,MAAM,KAAK,GAAG,GAAG;AACnB,WAAO,IAAI,GAAG;AAAA,EAChB;AAEA,QAAM,IAEH,QAAQ,mBAAmB,EAAE;AAGhC,MAAI,iBAAiB,IAAI,GAAG,KAAK,oBAAoB,IAAI,GAAG,GAAG;AAC7D,WAAO,IAAI,GAAG;AAAA,EAChB;AACA,SAAO;AACT;AASO,SAAS,oBACd,YACA,WACQ;AACR,QAAM,cAAc,UAAU,eAAe;AAC7C,QAAM,gBAAgB;AACtB,QAAM,cAAc,oBAAI,IAAI;AAAA;AAAA,IAE1B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,QAAM,WAAW,WAAW,MAAM,GAAG,EAAE,OAAO,OAAO;AAErD,QAAM,sBAAsB,SAAS;AAAA,IACnC,CAAC,YACC,WACA,CAAC,QAAQ,WAAW,GAAG,KACvB,CAAC,QA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AAAA,EACF;AAGA,UAAQ;AAAA,IACN,gDAAgD,UAAU,kBAAkB,WAAW;AAAA,EACzF;AACA,SAAO;AACT;",
4
+ "sourcesContent": ["import type { OperationObject } from 'openapi3-ts/oas31';\n\nimport { camelcase } from '@sdk-it/core';\n\nimport { reservedKeywords, reservedSdkKeywords } from './reserved-keywords.js';\n\nexport function sanitizeTag(tag: string): string {\n // Prepend underscore if starts with a number\n if (/^\\d/.test(tag)) {\n return `_${tag}`;\n }\n\n tag = tag\n // Remove any non-alphanumeric characters except underscores and dashes\n .replace(/[^A-Za-z0-9_-]/g, '')\n // Normalize multiple dashes to a single dash\n .replace(/-+/g, '-');\n\n // Append underscore if it's a reserved keyword\n if (reservedKeywords.has(tag) || reservedSdkKeywords.has(tag)) {\n return `${tag}_`;\n }\n return tag;\n}\nexport function sanitizeImportName(tag: string): string {\n // Prepend underscore if starts with a number\n if (/^\\d/.test(tag)) {\n return `_${tag}`;\n }\n\n tag = tag\n // Remove any non-alphanumeric characters except underscores\n .replace(/[^A-Za-z0-9_-]/g, '');\n\n // Append underscore if it's a reserved keyword\n if (reservedKeywords.has(tag) || reservedSdkKeywords.has(tag)) {\n return `${tag}_`;\n }\n return tag;\n}\n\n/**\n * Attempts to determine a generic tag for an OpenAPI operation based on path and operationId.\n * Rules and fallbacks are documented within the code.\n * @param pathString The path string.\n * @param operation The OpenAPI Operation Object.\n * @returns A sanitized, camelCased tag name string.\n */\nexport function determineGenericTag(\n pathString: string,\n operation: OperationObject,\n): string {\n const operationId = operation.operationId || '';\n const VERSION_REGEX = /^[vV]\\d+$/;\n const commonVerbs = new Set([\n // Verbs to potentially strip from operationId prefix\n 'get',\n 'list',\n 'create',\n 'update',\n 'delete',\n 'post',\n 'put',\n 'patch',\n 'do',\n 'send',\n 'add',\n 'remove',\n 'set',\n 'find',\n 'search',\n 'check',\n 'make',\n ]);\n\n const segments = pathString.split('/').filter(Boolean);\n\n const potentialCandidates = segments.filter(\n (segment) =>\n segment &&\n !segment.startsWith('{') &&\n !segment.endsWith('}') &&\n !VERSION_REGEX.test(segment),\n );\n\n // --- Heuristic 1: Last non-'@' path segment ---\n for (let i = potentialCandidates.length - 1; i >= 0; i--) {\n const segment = potentialCandidates[i];\n if (!segment.startsWith('@')) {\n // Sanitize just before returning\n return sanitizeTag(camelcase(segment));\n }\n }\n\n const canFallbackToPathSegment = potentialCandidates.length > 0;\n\n // --- Heuristic 2: OperationId parsing ---\n if (operationId) {\n const lowerOpId = operationId.toLowerCase();\n const parts = operationId\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/([A-Z])([A-Z][a-z])/g, '$1_$2')\n .replace(/([a-zA-Z])(\\d)/g, '$1_$2')\n .replace(/(\\d)([a-zA-Z])/g, '$1_$2')\n .toLowerCase()\n .split(/[_-\\s]+/);\n\n const validParts = parts.filter(Boolean);\n\n // Quick skip: If opId is just a verb and we can use Heuristic 3, prefer that.\n if (\n commonVerbs.has(lowerOpId) &&\n validParts.length === 1 &&\n canFallbackToPathSegment\n ) {\n // Proceed directly to Heuristic 3\n }\n // Only process if there are valid parts and the quick skip didn't happen\n else if (validParts.length > 0) {\n const firstPart = validParts[0];\n const isFirstPartVerb = commonVerbs.has(firstPart);\n\n // Case 2a: Starts with verb, has following parts\n if (isFirstPartVerb && validParts.length > 1) {\n const verbPrefixLength = firstPart.length;\n let nextPartStartIndex = -1;\n if (operationId.length > verbPrefixLength) {\n // Simplified check for next part start\n const charAfterPrefix = operationId[verbPrefixLength];\n if (charAfterPrefix >= 'A' && charAfterPrefix <= 'Z') {\n nextPartStartIndex = verbPrefixLength;\n } else if (charAfterPrefix >= '0' && charAfterPrefix <= '9') {\n nextPartStartIndex = verbPrefixLength;\n } else if (['_', '-'].includes(charAfterPrefix)) {\n nextPartStartIndex = verbPrefixLength + 1;\n } else {\n const match = operationId\n .substring(verbPrefixLength)\n .match(/[A-Z0-9]/);\n if (match && match.index !== undefined) {\n nextPartStartIndex = verbPrefixLength + match.index;\n }\n if (\n nextPartStartIndex === -1 &&\n operationId.length > verbPrefixLength\n ) {\n nextPartStartIndex = verbPrefixLength; // Default guess\n }\n }\n }\n\n if (\n nextPartStartIndex !== -1 &&\n nextPartStartIndex < operationId.length\n ) {\n const remainingOriginalSubstring =\n operationId.substring(nextPartStartIndex);\n const potentialTag = camelcase(remainingOriginalSubstring);\n if (potentialTag) {\n // Sanitize just before returning\n return sanitizeTag(potentialTag);\n }\n }\n\n // Fallback: join remaining lowercased parts\n const potentialTagJoined = camelcase(validParts.slice(1).join('_'));\n if (potentialTagJoined) {\n // Sanitize just before returning\n return sanitizeTag(potentialTagJoined);\n }\n }\n\n // Case 2b: Doesn't start with verb, or only one part (might be verb)\n const potentialTagFull = camelcase(operationId);\n if (potentialTagFull) {\n const isResultSingleVerb = validParts.length === 1 && isFirstPartVerb;\n\n // Avoid returning only a verb if Heuristic 3 is possible\n if (!(isResultSingleVerb && canFallbackToPathSegment)) {\n if (potentialTagFull.length > 0) {\n // Sanitize just before returning\n return sanitizeTag(potentialTagFull);\n }\n }\n }\n\n // Case 2c: Further fallbacks within OpId if above failed/skipped\n const firstPartCamel = camelcase(firstPart);\n if (firstPartCamel) {\n const isFirstPartCamelVerb = commonVerbs.has(firstPartCamel);\n if (\n !isFirstPartCamelVerb ||\n validParts.length === 1 ||\n !canFallbackToPathSegment\n ) {\n // Sanitize just before returning\n return sanitizeTag(firstPartCamel);\n }\n }\n if (\n isFirstPartVerb &&\n validParts.length > 1 &&\n validParts[1] &&\n canFallbackToPathSegment\n ) {\n const secondPartCamel = camelcase(validParts[1]);\n if (secondPartCamel) {\n // Sanitize just before returning\n return sanitizeTag(secondPartCamel);\n }\n }\n } // End if(validParts.length > 0) after quick skip check\n } // End if(operationId)\n\n // --- Heuristic 3: First path segment (stripping '@') ---\n if (potentialCandidates.length > 0) {\n let firstCandidate = potentialCandidates[0];\n if (firstCandidate.startsWith('@')) {\n firstCandidate = firstCandidate.substring(1);\n }\n if (firstCandidate) {\n // Sanitize just before returning\n return sanitizeTag(camelcase(firstCandidate));\n }\n }\n\n // --- Heuristic 4: Default ---\n console.warn(\n `Could not determine a suitable tag for path: ${pathString}, operationId: ${operationId}. Using 'unknown'.`,\n );\n return 'unknown'; // 'unknown' is safe\n}\n"],
5
+ "mappings": "AAEA,SAAS,iBAAiB;AAE1B,SAAS,kBAAkB,2BAA2B;AAE/C,SAAS,YAAY,KAAqB;AAE/C,MAAI,MAAM,KAAK,GAAG,GAAG;AACnB,WAAO,IAAI,GAAG;AAAA,EAChB;AAEA,QAAM,IAEH,QAAQ,mBAAmB,EAAE,EAE7B,QAAQ,OAAO,GAAG;AAGrB,MAAI,iBAAiB,IAAI,GAAG,KAAK,oBAAoB,IAAI,GAAG,GAAG;AAC7D,WAAO,GAAG,GAAG;AAAA,EACf;AACA,SAAO;AACT;AACO,SAAS,mBAAmB,KAAqB;AAEtD,MAAI,MAAM,KAAK,GAAG,GAAG;AACnB,WAAO,IAAI,GAAG;AAAA,EAChB;AAEA,QAAM,IAEH,QAAQ,mBAAmB,EAAE;AAGhC,MAAI,iBAAiB,IAAI,GAAG,KAAK,oBAAoB,IAAI,GAAG,GAAG;AAC7D,WAAO,GAAG,GAAG;AAAA,EACf;AACA,SAAO;AACT;AASO,SAAS,oBACd,YACA,WACQ;AACR,QAAM,cAAc,UAAU,eAAe;AAC7C,QAAM,gBAAgB;AACtB,QAAM,cAAc,oBAAI,IAAI;AAAA;AAAA,IAE1B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,QAAM,WAAW,WAAW,MAAM,GAAG,EAAE,OAAO,OAAO;AAErD,QAAM,sBAAsB,SAAS;AAAA,IACnC,CAAC,YACC,WACA,CAAC,QAAQ,WAAW,GAAG,KACvB,CAAC,QAAQ,SAAS,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AAGA,UAAQ;AAAA,IACN,gDAAgD,UAAU,kBAAkB,WAAW;AAAA,EACzF;AACA,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"tune-request-body.d.ts","sourceRoot":"","sources":["../../src/lib/tune-request-body.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EAEf,YAAY,EACZ,yBAAyB,EAC1B,MAAM,mBAAmB,CAAC;AAO3B,OAAO,KAAK,EAAE,EAAE,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAE3D,wBAAgB,eAAe,CAC7B,IAAI,EAAE,EAAE,EACR,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,eAAe,EAAE,EAC7B,QAAQ,EAAE,yBAAyB,EAAE,QA+BtC;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,EAAE,EACR,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,eAAe,EAC1B,UAAU,EAAE,eAAe,EAAE,EAC7B,QAAQ,EAAE,yBAAyB,EAAE,GACpC,oBAAoB,CA+DtB"}
1
+ {"version":3,"file":"tune-request-body.d.ts","sourceRoot":"","sources":["../../src/lib/tune-request-body.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EAEf,YAAY,EACZ,yBAAyB,EAC1B,MAAM,mBAAmB,CAAC;AAO3B,OAAO,KAAK,EAAE,EAAE,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAE3D,wBAAgB,eAAe,CAC7B,IAAI,EAAE,EAAE,EACR,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,eAAe,EAAE,EAC7B,QAAQ,EAAE,yBAAyB,EAAE,QAiCtC;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,EAAE,EACR,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,eAAe,EAC1B,UAAU,EAAE,eAAe,EAAE,EAC7B,QAAQ,EAAE,yBAAyB,EAAE,GACpC,oBAAoB,CAuEtB"}
@@ -8,11 +8,13 @@ function patchParameters(spec, schema, parameters, security) {
8
8
  security,
9
9
  spec.components.securitySchemes
10
10
  );
11
- let required = Array.isArray(schema.required) ? schema.required : [];
11
+ const required = new Set(
12
+ Array.isArray(schema.required) ? schema.required : []
13
+ );
12
14
  schema["x-properties"] ??= {};
13
15
  for (const param of parameters) {
14
16
  if (param.required) {
15
- required.push(param.name);
17
+ required.add(param.name);
16
18
  }
17
19
  schema["x-properties"][param.name] = {
18
20
  "x-in": param.in,
@@ -20,25 +22,26 @@ function patchParameters(spec, schema, parameters, security) {
20
22
  };
21
23
  }
22
24
  for (const param of securityOptions) {
23
- required = required.filter((name) => name !== param.name);
25
+ required.delete(param.name);
24
26
  schema["x-properties"][param.name] = {
25
27
  "x-in": "header",
26
28
  ...isRef(param.schema) ? followRef(spec, param.schema.$ref) : param.schema ?? { type: "string" }
27
29
  };
28
30
  }
29
- schema["x-required"] = required;
31
+ schema["x-required"] = [...required];
30
32
  }
31
33
  function tuneRequestBody(spec, operationId, operation, parameters, security) {
32
- const inputName = findUniqueSchemaName(spec, operationId, [
33
- "input",
34
- "payload",
35
- "request"
36
- ]);
37
- const requestBody = isRef(operation.requestBody) ? followRef(spec, operation.requestBody.$ref) : operation.requestBody ?? {
34
+ const requestBodySource = isRef(operation.requestBody) ? followRef(spec, operation.requestBody.$ref) : operation.requestBody ?? {
38
35
  content: {},
39
36
  required: false
40
37
  };
38
+ const requestBody = structuredClone(requestBodySource);
41
39
  if (isEmpty(requestBody.content)) {
40
+ const inputName = findUniqueSchemaName(spec, operationId, [
41
+ "input",
42
+ "payload",
43
+ "request"
44
+ ]);
42
45
  const schema = {
43
46
  "x-inputname": inputName,
44
47
  "x-requestbody": true
@@ -57,10 +60,17 @@ function tuneRequestBody(spec, operationId, operation, parameters, security) {
57
60
  }
58
61
  for (const contentType in requestBody.content) {
59
62
  const mediaType = requestBody.content[contentType];
63
+ const inputName = findUniqueSchemaName(spec, operationId, [
64
+ "input",
65
+ "payload",
66
+ "request"
67
+ ]);
60
68
  let schema;
61
69
  switch (true) {
62
70
  case isRef(mediaType.schema):
63
- schema = followRef(spec, mediaType.schema.$ref);
71
+ schema = structuredClone(
72
+ followRef(spec, mediaType.schema.$ref)
73
+ );
64
74
  break;
65
75
  case isEmpty(mediaType.schema):
66
76
  schema ??= {};
@@ -69,7 +79,7 @@ function tuneRequestBody(spec, operationId, operation, parameters, security) {
69
79
  );
70
80
  break;
71
81
  default:
72
- schema = mediaType.schema;
82
+ schema = structuredClone(mediaType.schema);
73
83
  break;
74
84
  }
75
85
  patchParameters(spec, schema, parameters, security);