@kubb/adapter-oas 5.0.0-beta.20 → 5.0.0-beta.22

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/index.js CHANGED
@@ -340,12 +340,13 @@ var URLPath = class {
340
340
  * @example
341
341
  * new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
342
342
  */
343
- toTemplateString({ prefix = "", replacer } = {}) {
344
- return `\`${prefix}${this.path.split(/\{([^}]+)\}/).map((part, i) => {
343
+ toTemplateString({ prefix, replacer } = {}) {
344
+ const result = this.path.split(/\{([^}]+)\}/).map((part, i) => {
345
345
  if (i % 2 === 0) return part;
346
346
  const param = this.#transformParam(part);
347
347
  return `\${${replacer ? replacer(param) : param}}`;
348
- }).join("")}\``;
348
+ }).join("");
349
+ return `\`${prefix ?? ""}${result}\``;
349
350
  }
350
351
  /**
351
352
  * Extracts all `{param}` segments from the path and returns them as a key-value map.
@@ -1151,7 +1152,7 @@ function createSchemaParser(ctx) {
1151
1152
  * Circular refs are detected via `resolvingRefs` and leave `schema` as `undefined`.
1152
1153
  */
1153
1154
  function convertRef({ schema, name, nullable, defaultValue, rawOptions }) {
1154
- let resolvedSchema;
1155
+ let resolvedSchema = null;
1155
1156
  const refPath = schema.$ref;
1156
1157
  if (refPath && !resolvingRefs.has(refPath)) {
1157
1158
  if (!resolvedRefCache.has(refPath)) {
@@ -1165,7 +1166,7 @@ function createSchemaParser(ctx) {
1165
1166
  } catch {}
1166
1167
  resolvedRefCache.set(refPath, resolvedSchema);
1167
1168
  }
1168
- resolvedSchema = resolvedRefCache.get(refPath);
1169
+ resolvedSchema = resolvedRefCache.get(refPath) ?? null;
1169
1170
  }
1170
1171
  return ast.createSchema({
1171
1172
  ...buildSchemaNode(schema, name, nullable, defaultValue),
@@ -1551,7 +1552,7 @@ function createSchemaParser(ctx) {
1551
1552
  */
1552
1553
  function convertArray({ schema, name, nullable, defaultValue, rawOptions, options }) {
1553
1554
  const rawItems = schema.items;
1554
- const itemName = rawItems?.enum?.length && name ? ast.enumPropName(void 0, name, options.enumSuffix) : void 0;
1555
+ const itemName = rawItems?.enum?.length && name ? ast.enumPropName(null, name, options.enumSuffix) : void 0;
1555
1556
  const items = rawItems ? [parseSchema({
1556
1557
  schema: rawItems,
1557
1558
  name: itemName
@@ -1742,13 +1743,13 @@ function createSchemaParser(ctx) {
1742
1743
  * `$ref` entries are skipped since their flags live on the dereferenced target.
1743
1744
  */
1744
1745
  function collectPropertyKeysByFlag(schema, flag) {
1745
- if (!schema?.properties) return void 0;
1746
+ if (!schema?.properties) return null;
1746
1747
  const keys = [];
1747
1748
  for (const key in schema.properties) {
1748
1749
  const prop = schema.properties[key];
1749
1750
  if (prop && !isReference(prop) && prop[flag]) keys.push(key);
1750
1751
  }
1751
- return keys.length ? keys : void 0;
1752
+ return keys.length ? keys : null;
1752
1753
  }
1753
1754
  /**
1754
1755
  * Converts an OAS `Operation` into an `OperationNode`.
@@ -1834,15 +1835,15 @@ function buildDiscriminatorChildMap(schemas) {
1834
1835
  for (const member of members) {
1835
1836
  const intersectionNode = ast.narrowSchema(member, "intersection");
1836
1837
  if (!intersectionNode?.members) continue;
1837
- let refNode;
1838
- let objNode;
1838
+ let refNode = null;
1839
+ let objNode = null;
1839
1840
  for (const m of intersectionNode.members) {
1840
1841
  refNode ??= ast.narrowSchema(m, "ref");
1841
1842
  objNode ??= ast.narrowSchema(m, "object");
1842
1843
  }
1843
1844
  if (!refNode?.name || !objNode) continue;
1844
1845
  const prop = objNode.properties.find((p) => p.name === discriminatorPropertyName);
1845
- const enumNode = prop ? ast.narrowSchema(prop.schema, "enum") : void 0;
1846
+ const enumNode = prop ? ast.narrowSchema(prop.schema, "enum") : null;
1846
1847
  if (!enumNode?.enumValues?.length) continue;
1847
1848
  const enumValues = enumNode.enumValues.filter((v) => v !== null);
1848
1849
  if (!enumValues.length) continue;
@@ -1890,7 +1891,7 @@ function patchDiscriminatorNode(node, entry) {
1890
1891
  * Reads the server URL from the document's `servers` array at `serverIndex`,
1891
1892
  * interpolating any `serverVariables` into the URL template.
1892
1893
  *
1893
- * Returns `undefined` when `serverIndex` is omitted or out of range.
1894
+ * Returns `null` when `serverIndex` is omitted or out of range.
1894
1895
  *
1895
1896
  * @example Resolve the first server
1896
1897
  * `resolveBaseUrl({ document, serverIndex: 0 })`
@@ -1900,7 +1901,7 @@ function patchDiscriminatorNode(node, entry) {
1900
1901
  */
1901
1902
  function resolveBaseUrl({ document, serverIndex, serverVariables }) {
1902
1903
  const server = serverIndex !== void 0 ? document.servers?.at(serverIndex) : void 0;
1903
- return server?.url ? resolveServerUrl(server, serverVariables) : void 0;
1904
+ return server?.url ? resolveServerUrl(server, serverVariables) : null;
1904
1905
  }
1905
1906
  /**
1906
1907
  * Parses every schema once to build the lookup structures that streaming needs upfront.
@@ -2116,7 +2117,7 @@ const adapterOas = createAdapter((options) => {
2116
2117
  nameMapping,
2117
2118
  resolve: (schemaName) => {
2118
2119
  const result = resolve(schemaName);
2119
- if (!result) return;
2120
+ if (!result) return null;
2120
2121
  return ast.createImport({
2121
2122
  name: [result.name],
2122
2123
  path: result.path