@kubb/oas 4.12.9 → 4.12.11
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 +57 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -23
- package/dist/index.d.ts +41 -23
- package/dist/index.js +56 -31
- package/dist/index.js.map +1 -1
- package/package.json +3 -13
- package/src/Oas.ts +118 -68
- package/src/index.ts +0 -1
- package/src/types.ts +29 -6
- package/src/utils.ts +10 -10
- package/dist/index-BuoKUWab.d.cts +0 -376
- package/dist/index-CT3Sz4Y8.d.ts +0 -376
- package/dist/infer.cjs +0 -1
- package/dist/infer.d.cts +0 -2
- package/dist/infer.d.ts +0 -2
- package/dist/infer.js +0 -1
- package/src/infer/index.ts +0 -7
- package/src/infer/infer.ts +0 -51
- package/src/infer/mappers.ts +0 -75
- package/src/infer/model.ts +0 -38
- package/src/infer/requestParams.ts +0 -137
- package/src/infer/response.ts +0 -30
- package/src/infer/security.ts +0 -157
package/dist/index.cjs
CHANGED
|
@@ -46,12 +46,12 @@ let jsonpointer = require("jsonpointer");
|
|
|
46
46
|
jsonpointer = __toESM(jsonpointer);
|
|
47
47
|
let oas = require("oas");
|
|
48
48
|
oas = __toESM(oas);
|
|
49
|
-
let oas_normalize = require("oas-normalize");
|
|
50
|
-
oas_normalize = __toESM(oas_normalize);
|
|
51
49
|
let node_path = require("node:path");
|
|
52
50
|
node_path = __toESM(node_path);
|
|
53
51
|
let _kubb_core_utils = require("@kubb/core/utils");
|
|
54
52
|
let oas_types = require("oas/types");
|
|
53
|
+
let oas_normalize = require("oas-normalize");
|
|
54
|
+
oas_normalize = __toESM(oas_normalize);
|
|
55
55
|
let remeda = require("remeda");
|
|
56
56
|
let swagger2openapi = require("swagger2openapi");
|
|
57
57
|
swagger2openapi = __toESM(swagger2openapi);
|
|
@@ -4193,9 +4193,9 @@ async function parse(pathOrApi, { oasClass = Oas, canBundle = true, enablePaths
|
|
|
4193
4193
|
}).load();
|
|
4194
4194
|
if (isOpenApiV2Document(document)) {
|
|
4195
4195
|
const { openapi } = await swagger2openapi.default.convertObj(document, { anchors: true });
|
|
4196
|
-
return new oasClass(
|
|
4196
|
+
return new oasClass(openapi);
|
|
4197
4197
|
}
|
|
4198
|
-
return new oasClass(
|
|
4198
|
+
return new oasClass(document);
|
|
4199
4199
|
}
|
|
4200
4200
|
async function merge(pathOrApi, { oasClass = Oas } = {}) {
|
|
4201
4201
|
const instances = await Promise.all(pathOrApi.map((p) => parse(p, {
|
|
@@ -4234,11 +4234,10 @@ function parseFromConfig(config, oasClass = Oas) {
|
|
|
4234
4234
|
//#region src/Oas.ts
|
|
4235
4235
|
var Oas = class extends oas.default {
|
|
4236
4236
|
#options = { discriminator: "strict" };
|
|
4237
|
-
document
|
|
4238
|
-
constructor(
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
this.document = oas$1;
|
|
4237
|
+
document;
|
|
4238
|
+
constructor(document) {
|
|
4239
|
+
super(document, void 0);
|
|
4240
|
+
this.document = document;
|
|
4242
4241
|
}
|
|
4243
4242
|
setOptions(options) {
|
|
4244
4243
|
this.#options = {
|
|
@@ -4253,7 +4252,7 @@ var Oas = class extends oas.default {
|
|
|
4253
4252
|
get($ref) {
|
|
4254
4253
|
const origRef = $ref;
|
|
4255
4254
|
$ref = $ref.trim();
|
|
4256
|
-
if ($ref === "") return
|
|
4255
|
+
if ($ref === "") return null;
|
|
4257
4256
|
if ($ref.startsWith("#")) $ref = globalThis.decodeURIComponent($ref.substring(1));
|
|
4258
4257
|
else return null;
|
|
4259
4258
|
const current = jsonpointer.default.get(this.api, $ref);
|
|
@@ -4277,6 +4276,7 @@ var Oas = class extends oas.default {
|
|
|
4277
4276
|
if (this.#options.discriminator === "inherit") Object.entries(mapping).forEach(([mappingKey, mappingValue]) => {
|
|
4278
4277
|
if (mappingValue) {
|
|
4279
4278
|
const childSchema = this.get(mappingValue);
|
|
4279
|
+
if (!childSchema) return;
|
|
4280
4280
|
if (!childSchema.properties) childSchema.properties = {};
|
|
4281
4281
|
const property = childSchema.properties[propertyName];
|
|
4282
4282
|
if (childSchema.properties) {
|
|
@@ -4284,33 +4284,58 @@ var Oas = class extends oas.default {
|
|
|
4284
4284
|
...childSchema.properties ? childSchema.properties[propertyName] : {},
|
|
4285
4285
|
enum: [...property?.enum?.filter((value) => value !== mappingKey) ?? [], mappingKey]
|
|
4286
4286
|
};
|
|
4287
|
-
childSchema.required = [...new Set([...childSchema.required ?? [], propertyName])];
|
|
4287
|
+
childSchema.required = typeof childSchema.required === "boolean" ? childSchema.required : [...new Set([...childSchema.required ?? [], propertyName])];
|
|
4288
4288
|
this.set(mappingValue, childSchema);
|
|
4289
4289
|
}
|
|
4290
4290
|
}
|
|
4291
4291
|
});
|
|
4292
4292
|
}
|
|
4293
4293
|
getDiscriminator(schema) {
|
|
4294
|
-
if (!isDiscriminator(schema)) return;
|
|
4294
|
+
if (!isDiscriminator(schema) || !schema) return null;
|
|
4295
4295
|
const { mapping = {}, propertyName } = schema.discriminator;
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
|
|
4306
|
-
if (
|
|
4307
|
-
const
|
|
4308
|
-
|
|
4309
|
-
const canAdd = key && !Object.values(mapping).includes(schema$1.$ref);
|
|
4310
|
-
if (canAdd && propertySchema?.enum?.length === 1) mapping[propertySchema.enum[0]] = schema$1.$ref;
|
|
4311
|
-
else if (canAdd) mapping[key] = schema$1.$ref;
|
|
4296
|
+
/**
|
|
4297
|
+
* Helper to extract discriminator value from a schema.
|
|
4298
|
+
* Checks in order:
|
|
4299
|
+
* 1. Extension property matching propertyName (e.g., x-linode-ref-name)
|
|
4300
|
+
* 2. Property with const value
|
|
4301
|
+
* 3. Property with single enum value
|
|
4302
|
+
* 4. Title as fallback
|
|
4303
|
+
*/
|
|
4304
|
+
const getDiscriminatorValue = (schema$1) => {
|
|
4305
|
+
if (!schema$1) return null;
|
|
4306
|
+
if (propertyName.startsWith("x-")) {
|
|
4307
|
+
const extensionValue = schema$1[propertyName];
|
|
4308
|
+
if (extensionValue && typeof extensionValue === "string") return extensionValue;
|
|
4312
4309
|
}
|
|
4313
|
-
|
|
4310
|
+
const propertySchema = schema$1.properties?.[propertyName];
|
|
4311
|
+
if (propertySchema && "const" in propertySchema && propertySchema.const !== void 0) return String(propertySchema.const);
|
|
4312
|
+
if (propertySchema && propertySchema.enum?.length === 1) return String(propertySchema.enum[0]);
|
|
4313
|
+
return schema$1.title || null;
|
|
4314
|
+
};
|
|
4315
|
+
/**
|
|
4316
|
+
* Process oneOf/anyOf items to build mapping.
|
|
4317
|
+
* Handles both $ref and inline schemas.
|
|
4318
|
+
*/
|
|
4319
|
+
const processSchemas = (schemas, existingMapping) => {
|
|
4320
|
+
schemas.forEach((schemaItem, index) => {
|
|
4321
|
+
if (isReference(schemaItem)) {
|
|
4322
|
+
const key = this.getKey(schemaItem.$ref);
|
|
4323
|
+
try {
|
|
4324
|
+
const discriminatorValue = getDiscriminatorValue(this.get(schemaItem.$ref));
|
|
4325
|
+
const canAdd = key && !Object.values(existingMapping).includes(schemaItem.$ref);
|
|
4326
|
+
if (canAdd && discriminatorValue) existingMapping[discriminatorValue] = schemaItem.$ref;
|
|
4327
|
+
else if (canAdd) existingMapping[key] = schemaItem.$ref;
|
|
4328
|
+
} catch (_error) {
|
|
4329
|
+
if (key && !Object.values(existingMapping).includes(schemaItem.$ref)) existingMapping[key] = schemaItem.$ref;
|
|
4330
|
+
}
|
|
4331
|
+
} else {
|
|
4332
|
+
const discriminatorValue = getDiscriminatorValue(schemaItem);
|
|
4333
|
+
if (discriminatorValue) existingMapping[discriminatorValue] = `#kubb-inline-${index}`;
|
|
4334
|
+
}
|
|
4335
|
+
});
|
|
4336
|
+
};
|
|
4337
|
+
if (schema.oneOf) processSchemas(schema.oneOf, mapping);
|
|
4338
|
+
if (schema.anyOf) processSchemas(schema.anyOf, mapping);
|
|
4314
4339
|
return {
|
|
4315
4340
|
...schema.discriminator,
|
|
4316
4341
|
mapping
|
|
@@ -4419,7 +4444,7 @@ var Oas = class extends oas.default {
|
|
|
4419
4444
|
if (!params.length) return null;
|
|
4420
4445
|
return params.reduce((schema, pathParameters) => {
|
|
4421
4446
|
const property = pathParameters.content?.[contentType]?.schema ?? pathParameters.schema;
|
|
4422
|
-
const required = [...schema.required || [], pathParameters.required ? pathParameters.name : void 0].filter(Boolean);
|
|
4447
|
+
const required = typeof schema.required === "boolean" ? schema.required : [...schema.required || [], pathParameters.required ? pathParameters.name : void 0].filter(Boolean);
|
|
4423
4448
|
const getDefaultStyle = (location) => {
|
|
4424
4449
|
if (location === "query") return "form";
|
|
4425
4450
|
if (location === "path") return "simple";
|
|
@@ -4455,13 +4480,13 @@ var Oas = class extends oas.default {
|
|
|
4455
4480
|
});
|
|
4456
4481
|
}
|
|
4457
4482
|
async valdiate() {
|
|
4458
|
-
return new
|
|
4483
|
+
return new (await (import("oas-normalize").then((m) => m.default)))(this.api, {
|
|
4459
4484
|
enablePaths: true,
|
|
4460
4485
|
colorizeErrors: true
|
|
4461
4486
|
}).validate({ parser: { validate: { errors: { colorize: true } } } });
|
|
4462
4487
|
}
|
|
4463
4488
|
flattenSchema(schema) {
|
|
4464
|
-
if (!schema?.allOf || schema.allOf.length === 0) return schema;
|
|
4489
|
+
if (!schema?.allOf || schema.allOf.length === 0) return schema || null;
|
|
4465
4490
|
if (schema.allOf.some((item) => isReference(item))) return schema;
|
|
4466
4491
|
const isPlainFragment = (item) => !Object.keys(item).some((key) => STRUCTURAL_KEYS.has(key));
|
|
4467
4492
|
if (!schema.allOf.every((item) => isPlainFragment(item))) return schema;
|
|
@@ -4488,7 +4513,6 @@ const HttpMethods = {
|
|
|
4488
4513
|
//#endregion
|
|
4489
4514
|
exports.HttpMethods = HttpMethods;
|
|
4490
4515
|
exports.Oas = Oas;
|
|
4491
|
-
exports.__toCommonJS = __toCommonJS;
|
|
4492
4516
|
Object.defineProperty(exports, 'findSchemaDefinition', {
|
|
4493
4517
|
enumerable: true,
|
|
4494
4518
|
get: function () {
|