@kubb/adapter-oas 5.0.0-alpha.8 → 5.0.0-alpha.9

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
@@ -289,9 +289,8 @@ const formatMap = {
289
289
  };
290
290
  /**
291
291
  * Exhaustive list of media types that Kubb recognizes.
292
- * Kept as a module-level constant to avoid re-allocating the array on every call.
293
292
  */
294
- const knownMediaTypes = [
293
+ const knownMediaTypes = new Set([
295
294
  "application/json",
296
295
  "application/xml",
297
296
  "application/x-www-form-urlencoded",
@@ -311,12 +310,22 @@ const knownMediaTypes = [
311
310
  "image/svg+xml",
312
311
  "audio/mpeg",
313
312
  "video/mp4"
314
- ];
313
+ ]);
315
314
  /**
316
315
  * Vendor extension keys used to attach human-readable labels to enum values.
317
316
  * Checked in priority order: the first key found wins.
318
317
  */
319
318
  const enumExtensionKeys = ["x-enumNames", "x-enum-varnames"];
319
+ /**
320
+ * Scalar primitive schema types used for union member simplification.
321
+ */
322
+ const SCALAR_PRIMITIVE_TYPES = new Set([
323
+ "string",
324
+ "number",
325
+ "integer",
326
+ "bigint",
327
+ "boolean"
328
+ ]);
320
329
  //#endregion
321
330
  //#region src/oas/Oas.ts
322
331
  /**
@@ -529,8 +538,15 @@ var Oas = class extends oas.default {
529
538
  if (!schema) return;
530
539
  return this.dereferenceWithRef(schema);
531
540
  }
532
- getParametersSchema(operation, inKey) {
533
- const { contentType = operation.getContentType() } = this.#options;
541
+ /**
542
+ * Returns all resolved parameters for an operation, merging path-level and operation-level
543
+ * parameters and deduplicating by `in:name` (operation-level takes precedence).
544
+ *
545
+ * oas v31+ filters out `$ref` parameters in `getParameters()`, so this method accesses the
546
+ * raw `operation.schema.parameters` and path-item parameters directly and resolves `$ref`
547
+ * pointers via `dereferenceWithRef` to preserve backward compatibility.
548
+ */
549
+ getParameters(operation) {
534
550
  const resolveParams = (params) => params.map((p) => this.dereferenceWithRef(p)).filter((p) => !!p && typeof p === "object" && "in" in p && "name" in p);
535
551
  const operationParams = resolveParams(operation.schema?.parameters || []);
536
552
  const pathItem = this.api?.paths?.[operation.path];
@@ -538,7 +554,11 @@ var Oas = class extends oas.default {
538
554
  const paramMap = /* @__PURE__ */ new Map();
539
555
  for (const p of pathLevelParams) if (p.name && p.in) paramMap.set(`${p.in}:${p.name}`, p);
540
556
  for (const p of operationParams) if (p.name && p.in) paramMap.set(`${p.in}:${p.name}`, p);
541
- const params = Array.from(paramMap.values()).filter((v) => v.in === inKey);
557
+ return Array.from(paramMap.values());
558
+ }
559
+ getParametersSchema(operation, inKey) {
560
+ const { contentType = operation.getContentType() } = this.#options;
561
+ const params = this.getParameters(operation).filter((v) => v.in === inKey);
542
562
  if (!params.length) return null;
543
563
  return params.reduce((schema, pathParameters) => {
544
564
  const property = pathParameters.content?.[contentType]?.schema ?? pathParameters.schema;
@@ -1005,20 +1025,19 @@ function mergeAdjacentAnonymousObjects(members) {
1005
1025
  *
1006
1026
  * Only scalar primitives (`string`, `number`, `integer`, `bigint`, `boolean`) are
1007
1027
  * considered — object, array, and ref members are left untouched.
1028
+ *
1029
+ * Const-derived enums (those without an `enumType`, produced from an OpenAPI `const`
1030
+ * keyword) are **never** removed — `'accepted' | string` must stay as-is because the
1031
+ * literal is intentional.
1008
1032
  */
1009
1033
  function simplifyUnionMembers(members) {
1010
- const scalarPrimitives = new Set(members.filter((m) => [
1011
- "string",
1012
- "number",
1013
- "integer",
1014
- "bigint",
1015
- "boolean"
1016
- ].includes(m.type)).map((m) => m.type));
1034
+ const scalarPrimitives = new Set(members.filter((m) => SCALAR_PRIMITIVE_TYPES.has(m.type)).map((m) => m.type));
1017
1035
  if (!scalarPrimitives.size) return members;
1018
1036
  return members.filter((m) => {
1019
1037
  if (m.type !== "enum") return true;
1020
1038
  const prim = m.primitive;
1021
1039
  if (!prim) return true;
1040
+ if (!m.enumType) return true;
1022
1041
  if (scalarPrimitives.has(prim)) return false;
1023
1042
  if ((prim === "integer" || prim === "number") && (scalarPrimitives.has("integer") || scalarPrimitives.has("number"))) return false;
1024
1043
  return true;
@@ -1093,7 +1112,7 @@ function getPrimitiveType(type) {
1093
1112
  * Returns `undefined` for content types not present in `KNOWN_MEDIA_TYPES`.
1094
1113
  */
1095
1114
  function toMediaType(contentType) {
1096
- return knownMediaTypes.includes(contentType) ? contentType : void 0;
1115
+ return knownMediaTypes.has(contentType) ? contentType : void 0;
1097
1116
  }
1098
1117
  /**
1099
1118
  * Creates an OAS parser that converts an OpenAPI/Swagger spec into
@@ -1738,6 +1757,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
1738
1757
  in: param["in"],
1739
1758
  schema: {
1740
1759
  ...schema,
1760
+ description: param["description"] ?? schema.description,
1741
1761
  optional: !required || !!schema.optional ? true : void 0
1742
1762
  },
1743
1763
  required
@@ -1748,15 +1768,13 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
1748
1768
  * request body, and all response codes into their AST node equivalents.
1749
1769
  */
1750
1770
  function parseOperation(options, oas, operation) {
1751
- const parameters = operation.getParameters().map((param) => {
1752
- return parseParameter(options, oas.dereferenceWithRef(param));
1753
- });
1771
+ const parameters = oas.getParameters(operation).map((param) => parseParameter(options, param));
1754
1772
  const requestBodySchema = oas.getRequestSchema(operation);
1755
1773
  const requestBody = requestBodySchema ? convertSchema({ schema: requestBodySchema }, options) : void 0;
1756
1774
  const responses = operation.getResponseStatusCodes().map((statusCode) => {
1757
1775
  const responseObj = operation.getResponseByStatusCode(statusCode);
1758
1776
  const responseSchema = oas.getResponseSchema(operation, statusCode);
1759
- const schema = responseSchema && Object.keys(responseSchema).length > 0 ? convertSchema({ schema: responseSchema }, options) : void 0;
1777
+ const schema = responseSchema && Object.keys(responseSchema).length > 0 ? convertSchema({ schema: responseSchema }, options) : (0, _kubb_ast.createSchema)({ type: resolveTypeOption(options.emptySchemaType) });
1760
1778
  const description = typeof responseObj === "object" && responseObj !== null && !Array.isArray(responseObj) ? responseObj.description : void 0;
1761
1779
  const rawContent = typeof responseObj === "object" && responseObj !== null && !Array.isArray(responseObj) ? responseObj.content : void 0;
1762
1780
  return (0, _kubb_ast.createResponse)({