@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 +36 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +36 -18
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/constants.ts +9 -5
- package/src/oas/Oas.ts +16 -9
- package/src/oas/utils.ts +1 -1
- package/src/parser.ts +7 -7
- package/src/utils.ts +8 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
2
|
import * as _kubb_core0 from "@kubb/core";
|
|
3
3
|
import { AdapterFactoryOptions } from "@kubb/core";
|
|
4
|
-
import { DiscriminatorObject, OASDocument, SchemaObject } from "oas/types";
|
|
4
|
+
import { DiscriminatorObject, OASDocument, ParameterObject, SchemaObject } from "oas/types";
|
|
5
5
|
import BaseOas from "oas";
|
|
6
6
|
import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
|
|
7
7
|
import { Operation } from "oas/operation";
|
|
@@ -73,6 +73,15 @@ declare class Oas extends BaseOas {
|
|
|
73
73
|
dereferenceWithRef<T = unknown>(schema?: T): T;
|
|
74
74
|
getResponseSchema(operation: Operation$1, statusCode: string | number): SchemaObject$1;
|
|
75
75
|
getRequestSchema(operation: Operation$1): SchemaObject$1 | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Returns all resolved parameters for an operation, merging path-level and operation-level
|
|
78
|
+
* parameters and deduplicating by `in:name` (operation-level takes precedence).
|
|
79
|
+
*
|
|
80
|
+
* oas v31+ filters out `$ref` parameters in `getParameters()`, so this method accesses the
|
|
81
|
+
* raw `operation.schema.parameters` and path-item parameters directly and resolves `$ref`
|
|
82
|
+
* pointers via `dereferenceWithRef` to preserve backward compatibility.
|
|
83
|
+
*/
|
|
84
|
+
getParameters(operation: Operation$1): Array<ParameterObject>;
|
|
76
85
|
getParametersSchema(operation: Operation$1, inKey: 'path' | 'query' | 'header'): SchemaObject$1 | null;
|
|
77
86
|
validate(): Promise<oas_normalize_lib_types0.ValidationResult>;
|
|
78
87
|
flattenSchema(schema: SchemaObject$1 | null): SchemaObject$1 | null;
|
package/dist/index.js
CHANGED
|
@@ -261,9 +261,8 @@ const formatMap = {
|
|
|
261
261
|
};
|
|
262
262
|
/**
|
|
263
263
|
* Exhaustive list of media types that Kubb recognizes.
|
|
264
|
-
* Kept as a module-level constant to avoid re-allocating the array on every call.
|
|
265
264
|
*/
|
|
266
|
-
const knownMediaTypes = [
|
|
265
|
+
const knownMediaTypes = new Set([
|
|
267
266
|
"application/json",
|
|
268
267
|
"application/xml",
|
|
269
268
|
"application/x-www-form-urlencoded",
|
|
@@ -283,12 +282,22 @@ const knownMediaTypes = [
|
|
|
283
282
|
"image/svg+xml",
|
|
284
283
|
"audio/mpeg",
|
|
285
284
|
"video/mp4"
|
|
286
|
-
];
|
|
285
|
+
]);
|
|
287
286
|
/**
|
|
288
287
|
* Vendor extension keys used to attach human-readable labels to enum values.
|
|
289
288
|
* Checked in priority order: the first key found wins.
|
|
290
289
|
*/
|
|
291
290
|
const enumExtensionKeys = ["x-enumNames", "x-enum-varnames"];
|
|
291
|
+
/**
|
|
292
|
+
* Scalar primitive schema types used for union member simplification.
|
|
293
|
+
*/
|
|
294
|
+
const SCALAR_PRIMITIVE_TYPES = new Set([
|
|
295
|
+
"string",
|
|
296
|
+
"number",
|
|
297
|
+
"integer",
|
|
298
|
+
"bigint",
|
|
299
|
+
"boolean"
|
|
300
|
+
]);
|
|
292
301
|
//#endregion
|
|
293
302
|
//#region src/oas/Oas.ts
|
|
294
303
|
/**
|
|
@@ -501,8 +510,15 @@ var Oas = class extends BaseOas {
|
|
|
501
510
|
if (!schema) return;
|
|
502
511
|
return this.dereferenceWithRef(schema);
|
|
503
512
|
}
|
|
504
|
-
|
|
505
|
-
|
|
513
|
+
/**
|
|
514
|
+
* Returns all resolved parameters for an operation, merging path-level and operation-level
|
|
515
|
+
* parameters and deduplicating by `in:name` (operation-level takes precedence).
|
|
516
|
+
*
|
|
517
|
+
* oas v31+ filters out `$ref` parameters in `getParameters()`, so this method accesses the
|
|
518
|
+
* raw `operation.schema.parameters` and path-item parameters directly and resolves `$ref`
|
|
519
|
+
* pointers via `dereferenceWithRef` to preserve backward compatibility.
|
|
520
|
+
*/
|
|
521
|
+
getParameters(operation) {
|
|
506
522
|
const resolveParams = (params) => params.map((p) => this.dereferenceWithRef(p)).filter((p) => !!p && typeof p === "object" && "in" in p && "name" in p);
|
|
507
523
|
const operationParams = resolveParams(operation.schema?.parameters || []);
|
|
508
524
|
const pathItem = this.api?.paths?.[operation.path];
|
|
@@ -510,7 +526,11 @@ var Oas = class extends BaseOas {
|
|
|
510
526
|
const paramMap = /* @__PURE__ */ new Map();
|
|
511
527
|
for (const p of pathLevelParams) if (p.name && p.in) paramMap.set(`${p.in}:${p.name}`, p);
|
|
512
528
|
for (const p of operationParams) if (p.name && p.in) paramMap.set(`${p.in}:${p.name}`, p);
|
|
513
|
-
|
|
529
|
+
return Array.from(paramMap.values());
|
|
530
|
+
}
|
|
531
|
+
getParametersSchema(operation, inKey) {
|
|
532
|
+
const { contentType = operation.getContentType() } = this.#options;
|
|
533
|
+
const params = this.getParameters(operation).filter((v) => v.in === inKey);
|
|
514
534
|
if (!params.length) return null;
|
|
515
535
|
return params.reduce((schema, pathParameters) => {
|
|
516
536
|
const property = pathParameters.content?.[contentType]?.schema ?? pathParameters.schema;
|
|
@@ -977,20 +997,19 @@ function mergeAdjacentAnonymousObjects(members) {
|
|
|
977
997
|
*
|
|
978
998
|
* Only scalar primitives (`string`, `number`, `integer`, `bigint`, `boolean`) are
|
|
979
999
|
* considered — object, array, and ref members are left untouched.
|
|
1000
|
+
*
|
|
1001
|
+
* Const-derived enums (those without an `enumType`, produced from an OpenAPI `const`
|
|
1002
|
+
* keyword) are **never** removed — `'accepted' | string` must stay as-is because the
|
|
1003
|
+
* literal is intentional.
|
|
980
1004
|
*/
|
|
981
1005
|
function simplifyUnionMembers(members) {
|
|
982
|
-
const scalarPrimitives = new Set(members.filter((m) =>
|
|
983
|
-
"string",
|
|
984
|
-
"number",
|
|
985
|
-
"integer",
|
|
986
|
-
"bigint",
|
|
987
|
-
"boolean"
|
|
988
|
-
].includes(m.type)).map((m) => m.type));
|
|
1006
|
+
const scalarPrimitives = new Set(members.filter((m) => SCALAR_PRIMITIVE_TYPES.has(m.type)).map((m) => m.type));
|
|
989
1007
|
if (!scalarPrimitives.size) return members;
|
|
990
1008
|
return members.filter((m) => {
|
|
991
1009
|
if (m.type !== "enum") return true;
|
|
992
1010
|
const prim = m.primitive;
|
|
993
1011
|
if (!prim) return true;
|
|
1012
|
+
if (!m.enumType) return true;
|
|
994
1013
|
if (scalarPrimitives.has(prim)) return false;
|
|
995
1014
|
if ((prim === "integer" || prim === "number") && (scalarPrimitives.has("integer") || scalarPrimitives.has("number"))) return false;
|
|
996
1015
|
return true;
|
|
@@ -1065,7 +1084,7 @@ function getPrimitiveType(type) {
|
|
|
1065
1084
|
* Returns `undefined` for content types not present in `KNOWN_MEDIA_TYPES`.
|
|
1066
1085
|
*/
|
|
1067
1086
|
function toMediaType(contentType) {
|
|
1068
|
-
return knownMediaTypes.
|
|
1087
|
+
return knownMediaTypes.has(contentType) ? contentType : void 0;
|
|
1069
1088
|
}
|
|
1070
1089
|
/**
|
|
1071
1090
|
* Creates an OAS parser that converts an OpenAPI/Swagger spec into
|
|
@@ -1710,6 +1729,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1710
1729
|
in: param["in"],
|
|
1711
1730
|
schema: {
|
|
1712
1731
|
...schema,
|
|
1732
|
+
description: param["description"] ?? schema.description,
|
|
1713
1733
|
optional: !required || !!schema.optional ? true : void 0
|
|
1714
1734
|
},
|
|
1715
1735
|
required
|
|
@@ -1720,15 +1740,13 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1720
1740
|
* request body, and all response codes into their AST node equivalents.
|
|
1721
1741
|
*/
|
|
1722
1742
|
function parseOperation(options, oas, operation) {
|
|
1723
|
-
const parameters =
|
|
1724
|
-
return parseParameter(options, oas.dereferenceWithRef(param));
|
|
1725
|
-
});
|
|
1743
|
+
const parameters = oas.getParameters(operation).map((param) => parseParameter(options, param));
|
|
1726
1744
|
const requestBodySchema = oas.getRequestSchema(operation);
|
|
1727
1745
|
const requestBody = requestBodySchema ? convertSchema({ schema: requestBodySchema }, options) : void 0;
|
|
1728
1746
|
const responses = operation.getResponseStatusCodes().map((statusCode) => {
|
|
1729
1747
|
const responseObj = operation.getResponseByStatusCode(statusCode);
|
|
1730
1748
|
const responseSchema = oas.getResponseSchema(operation, statusCode);
|
|
1731
|
-
const schema = responseSchema && Object.keys(responseSchema).length > 0 ? convertSchema({ schema: responseSchema }, options) :
|
|
1749
|
+
const schema = responseSchema && Object.keys(responseSchema).length > 0 ? convertSchema({ schema: responseSchema }, options) : createSchema({ type: resolveTypeOption(options.emptySchemaType) });
|
|
1732
1750
|
const description = typeof responseObj === "object" && responseObj !== null && !Array.isArray(responseObj) ? responseObj.description : void 0;
|
|
1733
1751
|
const rawContent = typeof responseObj === "object" && responseObj !== null && !Array.isArray(responseObj) ? responseObj.content : void 0;
|
|
1734
1752
|
return createResponse({
|