@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.d.ts CHANGED
@@ -54,11 +54,6 @@ type ReferenceObject = OpenAPIV3.ReferenceObject;
54
54
  type OasOptions = {
55
55
  contentType?: contentType;
56
56
  discriminator?: 'strict' | 'inherit';
57
- /**
58
- * Resolve name collisions when schemas from different components share the same name (case-insensitive).
59
- * @default false
60
- */
61
- collisionDetection?: boolean;
62
57
  };
63
58
  declare class Oas extends BaseOas {
64
59
  #private;
@@ -92,7 +87,6 @@ declare class Oas extends BaseOas {
92
87
  getSchemas(options?: {
93
88
  contentType?: contentType;
94
89
  includes?: Array<'schemas' | 'responses' | 'requestBodies'>;
95
- collisionDetection?: boolean;
96
90
  }): {
97
91
  schemas: Record<string, SchemaObject$1>;
98
92
  nameMapping: Map<string, string>;
@@ -163,16 +157,6 @@ type OasAdapterOptions = {
163
157
  * @default 'strict'
164
158
  */
165
159
  discriminator?: 'strict' | 'inherit';
166
- /**
167
- * Enable collision detection for inline enum and schema type names.
168
- * When `true` (default), full-path names are used and name collisions
169
- * across schema components are automatically resolved (e.g. `OrderParamsStatusEnum`).
170
- * When `false`, enum names use only the immediate property context
171
- * (e.g. `ParamsStatusEnum`) matching the v4 naming conventions, with numeric
172
- * suffixes for deduplication (e.g. `ParamsStatusEnum2`).
173
- * @default true
174
- */
175
- collisionDetection?: boolean;
176
160
  } & Partial<ParserOptions>;
177
161
  type OasAdapterResolvedOptions = {
178
162
  validate: boolean;
@@ -181,7 +165,6 @@ type OasAdapterResolvedOptions = {
181
165
  serverIndex: OasAdapterOptions['serverIndex'];
182
166
  serverVariables: OasAdapterOptions['serverVariables'];
183
167
  discriminator: NonNullable<OasAdapterOptions['discriminator']>;
184
- collisionDetection: boolean;
185
168
  dateType: NonNullable<OasAdapterOptions['dateType']>;
186
169
  integerType: NonNullable<OasAdapterOptions['integerType']>;
187
170
  unknownType: NonNullable<OasAdapterOptions['unknownType']>;
package/dist/index.js CHANGED
@@ -196,27 +196,6 @@ function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
196
196
  return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
197
197
  }
198
198
  //#endregion
199
- //#region ../../internals/utils/src/names.ts
200
- /**
201
- * Returns a unique name by appending an incrementing numeric suffix when the name has already been used.
202
- * Mutates `data` in-place as a usage counter so subsequent calls remain consistent.
203
- *
204
- * @example
205
- * const seen: Record<string, number> = {}
206
- * getUniqueName('Foo', seen) // 'Foo'
207
- * getUniqueName('Foo', seen) // 'Foo2'
208
- * getUniqueName('Foo', seen) // 'Foo3'
209
- */
210
- function getUniqueName(originalName, data) {
211
- let used = data[originalName] || 0;
212
- if (used) {
213
- data[originalName] = ++used;
214
- originalName += used;
215
- }
216
- data[originalName] = 1;
217
- return originalName;
218
- }
219
- //#endregion
220
199
  //#region ../../internals/utils/src/reserved.ts
221
200
  /**
222
201
  * Returns `true` when `name` is a syntactically valid JavaScript variable name.
@@ -620,7 +599,6 @@ var Oas = class extends BaseOas {
620
599
  "requestBodies",
621
600
  "responses"
622
601
  ];
623
- const shouldResolveCollisions = options.collisionDetection ?? this.#options.collisionDetection ?? false;
624
602
  const components = this.getDefinition().components;
625
603
  const schemasWithMeta = [];
626
604
  if (includes.includes("schemas")) {
@@ -674,7 +652,7 @@ var Oas = class extends BaseOas {
674
652
  }
675
653
  }
676
654
  }
677
- const { schemas, nameMapping } = shouldResolveCollisions ? resolveCollisions(schemasWithMeta) : legacyResolve(schemasWithMeta);
655
+ const { schemas, nameMapping } = resolveCollisions(schemasWithMeta);
678
656
  return {
679
657
  schemas: sortSchemas(schemas),
680
658
  nameMapping
@@ -895,23 +873,6 @@ function getSemanticSuffix(source) {
895
873
  return semanticSuffixes[source];
896
874
  }
897
875
  /**
898
- * Builds `GetSchemasResult` without any collision detection.
899
- * Each schema is registered under its original component name and its full
900
- * `#/components/<source>/<name>` ref path.
901
- */
902
- function legacyResolve(schemasWithMeta) {
903
- const schemas = {};
904
- const nameMapping = /* @__PURE__ */ new Map();
905
- for (const item of schemasWithMeta) {
906
- schemas[item.originalName] = item.schema;
907
- nameMapping.set(`#/components/${item.source}/${item.originalName}`, item.originalName);
908
- }
909
- return {
910
- schemas,
911
- nameMapping
912
- };
913
- }
914
- /**
915
876
  * Builds `GetSchemasResult` with automatic name-collision resolution.
916
877
  *
917
878
  * When two or more schemas normalize to the same PascalCase name:
@@ -1130,13 +1091,8 @@ function toMediaType(contentType) {
1130
1091
  * const root = parser.parse({ emptySchemaType: 'unknown' })
1131
1092
  * ```
1132
1093
  */
1133
- function createOasParser(oas, { contentType, collisionDetection } = {}) {
1134
- const { schemas: schemaObjects, nameMapping } = oas.getSchemas({
1135
- contentType,
1136
- collisionDetection
1137
- });
1138
- const usedEnumNames = {};
1139
- const isLegacyNaming = collisionDetection === false;
1094
+ function createOasParser(oas, { contentType } = {}) {
1095
+ const { schemas: schemaObjects, nameMapping } = oas.getSchemas({ contentType });
1140
1096
  /**
1141
1097
  * Maps an `'any' | 'unknown' | 'void'` option string to the corresponding `SchemaType` constant.
1142
1098
  * Used for both `unknownType` (unannotated schemas) and `emptySchemaType` (empty `{}` schemas).
@@ -1335,7 +1291,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
1335
1291
  const discriminator = isDiscriminator(schema) ? schema.discriminator : void 0;
1336
1292
  const sharedPropertiesNode = convertSchema({
1337
1293
  schema: discriminator ? Object.fromEntries(Object.entries(schemaWithoutUnion).filter(([key]) => key !== "discriminator")) : schemaWithoutUnion,
1338
- name: isLegacyNaming ? void 0 : name
1294
+ name
1339
1295
  }, options);
1340
1296
  return createSchema({
1341
1297
  type: "union",
@@ -1558,29 +1514,24 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
1558
1514
  /**
1559
1515
  * Builds the propagation name for a child property during recursive schema conversion.
1560
1516
  *
1561
- * - **Legacy naming** (`isLegacyNaming`): only the immediate property key is used
1562
- * (e.g. `Params` for property `params`), keeping nested names short.
1563
- * - **Default naming**: the parent name is prepended so the full path is encoded
1517
+ * The parent name is prepended so the full path is encoded
1564
1518
  * (e.g. `OrderParams` when parent is `Order`).
1565
1519
  */
1566
1520
  function resolveChildName(parentName, propName) {
1567
- if (isLegacyNaming) return pascalCase(propName);
1568
1521
  return parentName ? pascalCase([parentName, propName].join(" ")) : void 0;
1569
1522
  }
1570
1523
  /**
1571
1524
  * Derives the final name for an enum property schema node.
1572
1525
  *
1573
- * The raw name always includes the enum suffix (e.g. `StatusEnum`).
1574
- * In legacy mode an additional deduplication step appends a numeric suffix
1575
- * when the same name has already been used (e.g. `ParamsStatusEnum2`).
1526
+ * The resulting name always includes the enum suffix and full parent path context
1527
+ * (e.g. `OrderParamsStatusEnum`).
1576
1528
  */
1577
1529
  function resolveEnumPropName(parentName, propName, enumSuffix) {
1578
- const raw = pascalCase([
1530
+ return pascalCase([
1579
1531
  parentName,
1580
1532
  propName,
1581
1533
  enumSuffix
1582
1534
  ].filter(Boolean).join(" "));
1583
- return isLegacyNaming ? getUniqueName(raw, usedEnumNames) : raw;
1584
1535
  }
1585
1536
  /**
1586
1537
  * Given a freshly-converted property schema, returns the node with a correct
@@ -1967,7 +1918,7 @@ const adapterOasName = "oas";
1967
1918
  * ```
1968
1919
  */
1969
1920
  const adapterOas = createAdapter((options) => {
1970
- 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;
1921
+ 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;
1971
1922
  const nameMapping = /* @__PURE__ */ new Map();
1972
1923
  return {
1973
1924
  name: "oas",
@@ -1978,7 +1929,6 @@ const adapterOas = createAdapter((options) => {
1978
1929
  serverIndex,
1979
1930
  serverVariables,
1980
1931
  discriminator,
1981
- collisionDetection,
1982
1932
  dateType,
1983
1933
  integerType,
1984
1934
  unknownType,
@@ -1997,18 +1947,14 @@ const adapterOas = createAdapter((options) => {
1997
1947
  const oas = await parseFromConfig(sourceToFakeConfig(source), oasClass);
1998
1948
  oas.setOptions({
1999
1949
  contentType,
2000
- discriminator,
2001
- collisionDetection
1950
+ discriminator
2002
1951
  });
2003
1952
  if (validate) try {
2004
1953
  await oas.validate();
2005
1954
  } catch (_err) {}
2006
1955
  const server = serverIndex !== void 0 ? oas.api.servers?.at(serverIndex) : void 0;
2007
1956
  const baseURL = server?.url ? resolveServerUrl(server, serverVariables) : void 0;
2008
- const parser = createOasParser(oas, {
2009
- contentType,
2010
- collisionDetection
2011
- });
1957
+ const parser = createOasParser(oas, { contentType });
2012
1958
  const root = parser.parse({
2013
1959
  dateType,
2014
1960
  integerType,