@kubb/adapter-oas 5.0.0-alpha.13 → 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
@@ -914,29 +892,13 @@ function extractSchemaFromContent(content, preferredContentType) {
914
892
  * Returns the PascalCase suffix appended to a component name when resolving
915
893
  * cross-source name collisions (schemas vs. responses vs. requestBodies).
916
894
  */
895
+ const semanticSuffixes = {
896
+ schemas: "Schema",
897
+ responses: "Response",
898
+ requestBodies: "Request"
899
+ };
917
900
  function getSemanticSuffix(source) {
918
- switch (source) {
919
- case "schemas": return "Schema";
920
- case "responses": return "Response";
921
- case "requestBodies": return "Request";
922
- }
923
- }
924
- /**
925
- * Builds `GetSchemasResult` without any collision detection.
926
- * Each schema is registered under its original component name and its full
927
- * `#/components/<source>/<name>` ref path.
928
- */
929
- function legacyResolve(schemasWithMeta) {
930
- const schemas = {};
931
- const nameMapping = /* @__PURE__ */ new Map();
932
- for (const item of schemasWithMeta) {
933
- schemas[item.originalName] = item.schema;
934
- nameMapping.set(`#/components/${item.source}/${item.originalName}`, item.originalName);
935
- }
936
- return {
937
- schemas,
938
- nameMapping
939
- };
901
+ return semanticSuffixes[source];
940
902
  }
941
903
  /**
942
904
  * Builds `GetSchemasResult` with automatic name-collision resolution.
@@ -1157,13 +1119,8 @@ function toMediaType(contentType) {
1157
1119
  * const root = parser.parse({ emptySchemaType: 'unknown' })
1158
1120
  * ```
1159
1121
  */
1160
- function createOasParser(oas, { contentType, collisionDetection } = {}) {
1161
- const { schemas: schemaObjects, nameMapping } = oas.getSchemas({
1162
- contentType,
1163
- collisionDetection
1164
- });
1165
- const usedEnumNames = {};
1166
- const isLegacyNaming = collisionDetection === false;
1122
+ function createOasParser(oas, { contentType } = {}) {
1123
+ const { schemas: schemaObjects, nameMapping } = oas.getSchemas({ contentType });
1167
1124
  /**
1168
1125
  * Maps an `'any' | 'unknown' | 'void'` option string to the corresponding `SchemaType` constant.
1169
1126
  * Used for both `unknownType` (unannotated schemas) and `emptySchemaType` (empty `{}` schemas).
@@ -1362,7 +1319,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
1362
1319
  const discriminator = isDiscriminator(schema) ? schema.discriminator : void 0;
1363
1320
  const sharedPropertiesNode = convertSchema({
1364
1321
  schema: discriminator ? Object.fromEntries(Object.entries(schemaWithoutUnion).filter(([key]) => key !== "discriminator")) : schemaWithoutUnion,
1365
- name: isLegacyNaming ? void 0 : name
1322
+ name
1366
1323
  }, options);
1367
1324
  return (0, _kubb_ast.createSchema)({
1368
1325
  type: "union",
@@ -1585,29 +1542,24 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
1585
1542
  /**
1586
1543
  * Builds the propagation name for a child property during recursive schema conversion.
1587
1544
  *
1588
- * - **Legacy naming** (`isLegacyNaming`): only the immediate property key is used
1589
- * (e.g. `Params` for property `params`), keeping nested names short.
1590
- * - **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
1591
1546
  * (e.g. `OrderParams` when parent is `Order`).
1592
1547
  */
1593
1548
  function resolveChildName(parentName, propName) {
1594
- if (isLegacyNaming) return pascalCase(propName);
1595
1549
  return parentName ? pascalCase([parentName, propName].join(" ")) : void 0;
1596
1550
  }
1597
1551
  /**
1598
1552
  * Derives the final name for an enum property schema node.
1599
1553
  *
1600
- * The raw name always includes the enum suffix (e.g. `StatusEnum`).
1601
- * In legacy mode an additional deduplication step appends a numeric suffix
1602
- * 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`).
1603
1556
  */
1604
1557
  function resolveEnumPropName(parentName, propName, enumSuffix) {
1605
- const raw = pascalCase([
1558
+ return pascalCase([
1606
1559
  parentName,
1607
1560
  propName,
1608
1561
  enumSuffix
1609
1562
  ].filter(Boolean).join(" "));
1610
- return isLegacyNaming ? getUniqueName(raw, usedEnumNames) : raw;
1611
1563
  }
1612
1564
  /**
1613
1565
  * Given a freshly-converted property schema, returns the node with a correct
@@ -1647,9 +1599,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
1647
1599
  name: propName,
1648
1600
  schema: {
1649
1601
  ...schemaNode,
1650
- nullable: schemaNode.type === "null" ? void 0 : propNullable || void 0,
1651
- optional: !required && !propNullable ? true : void 0,
1652
- nullish: !required && propNullable ? true : void 0
1602
+ nullable: schemaNode.type === "null" ? void 0 : propNullable || void 0
1653
1603
  },
1654
1604
  required
1655
1605
  });
@@ -1871,8 +1821,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
1871
1821
  in: param["in"],
1872
1822
  schema: {
1873
1823
  ...schema,
1874
- description: param["description"] ?? schema.description,
1875
- optional: !required || !!schema.optional ? true : void 0
1824
+ description: param["description"] ?? schema.description
1876
1825
  },
1877
1826
  required
1878
1827
  });
@@ -1997,7 +1946,7 @@ const adapterOasName = "oas";
1997
1946
  * ```
1998
1947
  */
1999
1948
  const adapterOas = (0, _kubb_core.createAdapter)((options) => {
2000
- 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;
2001
1950
  const nameMapping = /* @__PURE__ */ new Map();
2002
1951
  return {
2003
1952
  name: "oas",
@@ -2008,7 +1957,6 @@ const adapterOas = (0, _kubb_core.createAdapter)((options) => {
2008
1957
  serverIndex,
2009
1958
  serverVariables,
2010
1959
  discriminator,
2011
- collisionDetection,
2012
1960
  dateType,
2013
1961
  integerType,
2014
1962
  unknownType,
@@ -2027,18 +1975,14 @@ const adapterOas = (0, _kubb_core.createAdapter)((options) => {
2027
1975
  const oas = await parseFromConfig(sourceToFakeConfig(source), oasClass);
2028
1976
  oas.setOptions({
2029
1977
  contentType,
2030
- discriminator,
2031
- collisionDetection
1978
+ discriminator
2032
1979
  });
2033
1980
  if (validate) try {
2034
1981
  await oas.validate();
2035
1982
  } catch (_err) {}
2036
1983
  const server = serverIndex !== void 0 ? oas.api.servers?.at(serverIndex) : void 0;
2037
1984
  const baseURL = server?.url ? resolveServerUrl(server, serverVariables) : void 0;
2038
- const parser = createOasParser(oas, {
2039
- contentType,
2040
- collisionDetection
2041
- });
1985
+ const parser = createOasParser(oas, { contentType });
2042
1986
  const root = parser.parse({
2043
1987
  dateType,
2044
1988
  integerType,