@kubb/adapter-oas 5.0.0-alpha.14 → 5.0.0-alpha.15

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.cjs CHANGED
@@ -224,27 +224,6 @@ function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
224
224
  return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
225
225
  }
226
226
  //#endregion
227
- //#region ../../internals/utils/src/names.ts
228
- /**
229
- * Returns a unique name by appending an incrementing numeric suffix when the name has already been used.
230
- * Mutates `data` in-place as a usage counter so subsequent calls remain consistent.
231
- *
232
- * @example
233
- * const seen: Record<string, number> = {}
234
- * getUniqueName('Foo', seen) // 'Foo'
235
- * getUniqueName('Foo', seen) // 'Foo2'
236
- * getUniqueName('Foo', seen) // 'Foo3'
237
- */
238
- function getUniqueName(originalName, data) {
239
- let used = data[originalName] || 0;
240
- if (used) {
241
- data[originalName] = ++used;
242
- originalName += used;
243
- }
244
- data[originalName] = 1;
245
- return originalName;
246
- }
247
- //#endregion
248
227
  //#region ../../internals/utils/src/reserved.ts
249
228
  /**
250
229
  * Returns `true` when `name` is a syntactically valid JavaScript variable name.
@@ -648,7 +627,6 @@ var Oas = class extends oas.default {
648
627
  "requestBodies",
649
628
  "responses"
650
629
  ];
651
- const shouldResolveCollisions = options.collisionDetection ?? this.#options.collisionDetection ?? false;
652
630
  const components = this.getDefinition().components;
653
631
  const schemasWithMeta = [];
654
632
  if (includes.includes("schemas")) {
@@ -702,7 +680,7 @@ var Oas = class extends oas.default {
702
680
  }
703
681
  }
704
682
  }
705
- const { schemas, nameMapping } = shouldResolveCollisions ? resolveCollisions(schemasWithMeta) : legacyResolve(schemasWithMeta);
683
+ const { schemas, nameMapping } = resolveCollisions(schemasWithMeta);
706
684
  return {
707
685
  schemas: sortSchemas(schemas),
708
686
  nameMapping
@@ -923,23 +901,6 @@ function getSemanticSuffix(source) {
923
901
  return semanticSuffixes[source];
924
902
  }
925
903
  /**
926
- * Builds `GetSchemasResult` without any collision detection.
927
- * Each schema is registered under its original component name and its full
928
- * `#/components/<source>/<name>` ref path.
929
- */
930
- function legacyResolve(schemasWithMeta) {
931
- const schemas = {};
932
- const nameMapping = /* @__PURE__ */ new Map();
933
- for (const item of schemasWithMeta) {
934
- schemas[item.originalName] = item.schema;
935
- nameMapping.set(`#/components/${item.source}/${item.originalName}`, item.originalName);
936
- }
937
- return {
938
- schemas,
939
- nameMapping
940
- };
941
- }
942
- /**
943
904
  * Builds `GetSchemasResult` with automatic name-collision resolution.
944
905
  *
945
906
  * When two or more schemas normalize to the same PascalCase name:
@@ -1158,13 +1119,8 @@ function toMediaType(contentType) {
1158
1119
  * const root = parser.parse({ emptySchemaType: 'unknown' })
1159
1120
  * ```
1160
1121
  */
1161
- function createOasParser(oas, { contentType, collisionDetection } = {}) {
1162
- const { schemas: schemaObjects, nameMapping } = oas.getSchemas({
1163
- contentType,
1164
- collisionDetection
1165
- });
1166
- const usedEnumNames = {};
1167
- const isLegacyNaming = collisionDetection === false;
1122
+ function createOasParser(oas, { contentType } = {}) {
1123
+ const { schemas: schemaObjects, nameMapping } = oas.getSchemas({ contentType });
1168
1124
  /**
1169
1125
  * Maps an `'any' | 'unknown' | 'void'` option string to the corresponding `SchemaType` constant.
1170
1126
  * Used for both `unknownType` (unannotated schemas) and `emptySchemaType` (empty `{}` schemas).
@@ -1363,7 +1319,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
1363
1319
  const discriminator = isDiscriminator(schema) ? schema.discriminator : void 0;
1364
1320
  const sharedPropertiesNode = convertSchema({
1365
1321
  schema: discriminator ? Object.fromEntries(Object.entries(schemaWithoutUnion).filter(([key]) => key !== "discriminator")) : schemaWithoutUnion,
1366
- name: isLegacyNaming ? void 0 : name
1322
+ name
1367
1323
  }, options);
1368
1324
  return (0, _kubb_ast.createSchema)({
1369
1325
  type: "union",
@@ -1586,29 +1542,24 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
1586
1542
  /**
1587
1543
  * Builds the propagation name for a child property during recursive schema conversion.
1588
1544
  *
1589
- * - **Legacy naming** (`isLegacyNaming`): only the immediate property key is used
1590
- * (e.g. `Params` for property `params`), keeping nested names short.
1591
- * - **Default naming**: the parent name is prepended so the full path is encoded
1545
+ * The parent name is prepended so the full path is encoded
1592
1546
  * (e.g. `OrderParams` when parent is `Order`).
1593
1547
  */
1594
1548
  function resolveChildName(parentName, propName) {
1595
- if (isLegacyNaming) return pascalCase(propName);
1596
1549
  return parentName ? pascalCase([parentName, propName].join(" ")) : void 0;
1597
1550
  }
1598
1551
  /**
1599
1552
  * Derives the final name for an enum property schema node.
1600
1553
  *
1601
- * The raw name always includes the enum suffix (e.g. `StatusEnum`).
1602
- * In legacy mode an additional deduplication step appends a numeric suffix
1603
- * when the same name has already been used (e.g. `ParamsStatusEnum2`).
1554
+ * The resulting name always includes the enum suffix and full parent path context
1555
+ * (e.g. `OrderParamsStatusEnum`).
1604
1556
  */
1605
1557
  function resolveEnumPropName(parentName, propName, enumSuffix) {
1606
- const raw = pascalCase([
1558
+ return pascalCase([
1607
1559
  parentName,
1608
1560
  propName,
1609
1561
  enumSuffix
1610
1562
  ].filter(Boolean).join(" "));
1611
- return isLegacyNaming ? getUniqueName(raw, usedEnumNames) : raw;
1612
1563
  }
1613
1564
  /**
1614
1565
  * Given a freshly-converted property schema, returns the node with a correct
@@ -1995,7 +1946,7 @@ const adapterOasName = "oas";
1995
1946
  * ```
1996
1947
  */
1997
1948
  const adapterOas = (0, _kubb_core.createAdapter)((options) => {
1998
- const { validate = true, oasClass, contentType, serverIndex, serverVariables, discriminator = "strict", collisionDetection = true, dateType = DEFAULT_PARSER_OPTIONS.dateType, integerType = DEFAULT_PARSER_OPTIONS.integerType, unknownType = DEFAULT_PARSER_OPTIONS.unknownType, enumSuffix = DEFAULT_PARSER_OPTIONS.enumSuffix, emptySchemaType = unknownType || DEFAULT_PARSER_OPTIONS.emptySchemaType } = options;
1949
+ const { validate = true, oasClass, contentType, serverIndex, serverVariables, discriminator = "strict", dateType = DEFAULT_PARSER_OPTIONS.dateType, integerType = DEFAULT_PARSER_OPTIONS.integerType, unknownType = DEFAULT_PARSER_OPTIONS.unknownType, enumSuffix = DEFAULT_PARSER_OPTIONS.enumSuffix, emptySchemaType = unknownType || DEFAULT_PARSER_OPTIONS.emptySchemaType } = options;
1999
1950
  const nameMapping = /* @__PURE__ */ new Map();
2000
1951
  return {
2001
1952
  name: "oas",
@@ -2006,7 +1957,6 @@ const adapterOas = (0, _kubb_core.createAdapter)((options) => {
2006
1957
  serverIndex,
2007
1958
  serverVariables,
2008
1959
  discriminator,
2009
- collisionDetection,
2010
1960
  dateType,
2011
1961
  integerType,
2012
1962
  unknownType,
@@ -2025,18 +1975,14 @@ const adapterOas = (0, _kubb_core.createAdapter)((options) => {
2025
1975
  const oas = await parseFromConfig(sourceToFakeConfig(source), oasClass);
2026
1976
  oas.setOptions({
2027
1977
  contentType,
2028
- discriminator,
2029
- collisionDetection
1978
+ discriminator
2030
1979
  });
2031
1980
  if (validate) try {
2032
1981
  await oas.validate();
2033
1982
  } catch (_err) {}
2034
1983
  const server = serverIndex !== void 0 ? oas.api.servers?.at(serverIndex) : void 0;
2035
1984
  const baseURL = server?.url ? resolveServerUrl(server, serverVariables) : void 0;
2036
- const parser = createOasParser(oas, {
2037
- contentType,
2038
- collisionDetection
2039
- });
1985
+ const parser = createOasParser(oas, { contentType });
2040
1986
  const root = parser.parse({
2041
1987
  dateType,
2042
1988
  integerType,