@kubb/adapter-oas 5.24.0 → 5.24.1
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 +68 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +68 -14
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ var compatibility = {
|
|
|
15
15
|
"node": ">=22.22"
|
|
16
16
|
};
|
|
17
17
|
// package.json
|
|
18
|
-
var version = "5.24.
|
|
18
|
+
var version = "5.24.1";
|
|
19
19
|
// src/constants.ts
|
|
20
20
|
/**
|
|
21
21
|
* Default parser options applied when no explicit options are provided.
|
|
@@ -390,18 +390,32 @@ function isPathInside(path, parent) {
|
|
|
390
390
|
return rel !== "" && !rel.startsWith("..") && !isAbsolute(rel);
|
|
391
391
|
}
|
|
392
392
|
// src/oas.ts
|
|
393
|
+
const legacyDocuments = /* @__PURE__ */ new WeakSet();
|
|
394
|
+
/**
|
|
395
|
+
* Marks a document upgraded from Swagger 2.0 or OpenAPI 3.0, so its enums keep the loose `nullable` reading.
|
|
396
|
+
*/
|
|
397
|
+
function markLegacyDocument(document) {
|
|
398
|
+
legacyDocuments.add(document);
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Returns `true` for a document upgraded from Swagger 2.0 or OpenAPI 3.0.
|
|
402
|
+
*/
|
|
403
|
+
function isLegacyDocument(document) {
|
|
404
|
+
return !!document && legacyDocuments.has(document);
|
|
405
|
+
}
|
|
393
406
|
/**
|
|
394
407
|
* Returns `true` when a schema should be treated as nullable.
|
|
395
408
|
*
|
|
396
409
|
* Recognizes all nullable signals across OAS versions: `nullable: true` (OAS 3.0),
|
|
397
410
|
* `x-nullable: true` (vendor extension), `type: 'null'`, and `type: ['null', ...]` (OAS 3.1).
|
|
411
|
+
* A sibling `enum` without `null` makes the schema non-nullable, except in documents upgraded from 3.0.
|
|
398
412
|
*/
|
|
399
|
-
function isNullable(schema) {
|
|
413
|
+
function isNullable(schema, document) {
|
|
400
414
|
if ((schema?.nullable ?? schema?.["x-nullable"]) === true) return true;
|
|
401
415
|
const schemaType = schema?.type;
|
|
402
|
-
|
|
403
|
-
if (Array.isArray(
|
|
404
|
-
return
|
|
416
|
+
const typeAllowsNull = schemaType === "null" || Array.isArray(schemaType) && schemaType.includes("null");
|
|
417
|
+
if (typeAllowsNull && Array.isArray(schema?.enum) && !schema.enum.includes(null)) return isLegacyDocument(document);
|
|
418
|
+
return typeAllowsNull;
|
|
405
419
|
}
|
|
406
420
|
/**
|
|
407
421
|
* Returns `true` for an OpenAPI 3.2 or later document. Swagger 2.0 and OpenAPI 3.0 documents are
|
|
@@ -1214,10 +1228,13 @@ function upgradeDocument(raw, { pathRefs = true } = {}) {
|
|
|
1214
1228
|
const refs = createRefs(raw);
|
|
1215
1229
|
inlinePathRefs(raw, (ref) => refs.resolve(ref, { report: false }));
|
|
1216
1230
|
}
|
|
1231
|
+
const declared = raw && typeof raw === "object" ? raw.openapi ?? raw.swagger : void 0;
|
|
1232
|
+
const legacy = declared !== void 0 && /^(2|3\.0)(\.|$)/.test(String(declared));
|
|
1217
1233
|
try {
|
|
1218
|
-
|
|
1234
|
+
const document = upgrade(raw, "3.1");
|
|
1235
|
+
if (legacy) markLegacyDocument(document);
|
|
1236
|
+
return document;
|
|
1219
1237
|
} catch (error) {
|
|
1220
|
-
const declared = raw && typeof raw === "object" ? raw.openapi ?? raw.swagger : void 0;
|
|
1221
1238
|
throw new Diagnostics.Error({
|
|
1222
1239
|
code: Diagnostics.code.invalidDocument,
|
|
1223
1240
|
severity: "error",
|
|
@@ -3090,10 +3107,48 @@ function convertAllOf({ schema: original, name, nullable, defaultValue, parse, r
|
|
|
3090
3107
|
members: [...mergeAdjacentObjectsLazy(allOfMembers.slice(0, syntheticStart)), ...mergeAdjacentObjectsLazy(allOfMembers.slice(syntheticStart))]
|
|
3091
3108
|
});
|
|
3092
3109
|
}
|
|
3110
|
+
const scalarTypes = /* @__PURE__ */ new Set([
|
|
3111
|
+
"string",
|
|
3112
|
+
"number",
|
|
3113
|
+
"integer",
|
|
3114
|
+
"boolean"
|
|
3115
|
+
]);
|
|
3116
|
+
/**
|
|
3117
|
+
* Copies a scalar parent `type` and `format` onto inline members without a `type`. JSON Schema applies
|
|
3118
|
+
* sibling keywords to every member, so `type: 'integer', anyOf: [{ minimum: 10 }]` keeps each member an integer.
|
|
3119
|
+
*/
|
|
3120
|
+
function inheritScalarType(members, { schema, type }) {
|
|
3121
|
+
if (!type || !scalarTypes.has(type)) return members;
|
|
3122
|
+
if (Array.isArray(schema.type) && schema.type.filter((t) => t !== "null").length > 1) return members;
|
|
3123
|
+
return members.map((member) => {
|
|
3124
|
+
if (!member || typeof member !== "object" || isReference(member) || member.type !== void 0) return member;
|
|
3125
|
+
const obj = member;
|
|
3126
|
+
return {
|
|
3127
|
+
type,
|
|
3128
|
+
...schema.format !== void 0 && obj.format === void 0 && { format: schema.format },
|
|
3129
|
+
...obj
|
|
3130
|
+
};
|
|
3131
|
+
});
|
|
3132
|
+
}
|
|
3093
3133
|
/**
|
|
3094
3134
|
* Converts a `oneOf` / `anyOf` schema into a `UnionSchemaNode`.
|
|
3095
3135
|
*/
|
|
3096
3136
|
function convertUnion(context) {
|
|
3137
|
+
if (context.schema.enum?.length) {
|
|
3138
|
+
const { enum: values, ...union } = context.schema;
|
|
3139
|
+
const enumSchema = {
|
|
3140
|
+
type: union.type,
|
|
3141
|
+
enum: isLegacyDocument(context.document) ? [...values, null] : values
|
|
3142
|
+
};
|
|
3143
|
+
const members = [convertUnion({
|
|
3144
|
+
...context,
|
|
3145
|
+
schema: union
|
|
3146
|
+
}), context.parse({ schema: enumSchema })];
|
|
3147
|
+
return createNode(context, {
|
|
3148
|
+
type: ast.schema.types.intersection,
|
|
3149
|
+
members
|
|
3150
|
+
});
|
|
3151
|
+
}
|
|
3097
3152
|
const annotatedEnum = convertAnnotatedEnum(context);
|
|
3098
3153
|
if (annotatedEnum) return annotatedEnum;
|
|
3099
3154
|
const { schema, name, nullable, defaultValue, parse, refs } = context;
|
|
@@ -3106,7 +3161,7 @@ function convertUnion(context) {
|
|
|
3106
3161
|
const discriminator = isDiscriminator(schema) ? schema.discriminator : void 0;
|
|
3107
3162
|
const declaredMembers = [...schema.oneOf ?? [], ...schema.anyOf ?? []];
|
|
3108
3163
|
const defaultRef = getDefaultMappingRef(typeof schema.discriminator === "object" ? schema.discriminator : void 0);
|
|
3109
|
-
const unionMembers = resolveUnionMembers(defaultRef && !declaredMembers.some((member) => isReference(member) && member.$ref === defaultRef) ? [...declaredMembers, { $ref: defaultRef }] : declaredMembers, schema.properties ?? {});
|
|
3164
|
+
const unionMembers = resolveUnionMembers(inheritScalarType(defaultRef && !declaredMembers.some((member) => isReference(member) && member.$ref === defaultRef) ? [...declaredMembers, { $ref: defaultRef }] : declaredMembers, context), schema.properties ?? {});
|
|
3110
3165
|
const strategy = schema.oneOf ? "one" : "any";
|
|
3111
3166
|
const explicitDiscriminatorPropertyName = discriminator?.propertyName;
|
|
3112
3167
|
const { oneOf: _o, anyOf: _a, discriminator: _d, ...memberBaseSchema } = schema;
|
|
@@ -3170,12 +3225,11 @@ function convertUnion(context) {
|
|
|
3170
3225
|
* with nullability already folded in.
|
|
3171
3226
|
*/
|
|
3172
3227
|
function convertMultiType({ schema, name, nullable, defaultValue, parse }) {
|
|
3173
|
-
const
|
|
3174
|
-
const nonNullTypes = types.filter((t) => t !== "null");
|
|
3228
|
+
const nonNullTypes = schema.type.filter((t) => t !== "null");
|
|
3175
3229
|
return createNode({
|
|
3176
3230
|
schema,
|
|
3177
3231
|
name,
|
|
3178
|
-
nullable
|
|
3232
|
+
nullable,
|
|
3179
3233
|
defaultValue
|
|
3180
3234
|
}, {
|
|
3181
3235
|
type: ast.schema.types.union,
|
|
@@ -3481,12 +3535,12 @@ function nameEnums(node, options) {
|
|
|
3481
3535
|
/**
|
|
3482
3536
|
* Converts an object-like schema into an `ObjectSchemaNode`.
|
|
3483
3537
|
*/
|
|
3484
|
-
function convertObject({ schema, name, nullable, defaultValue, options, parse, refs }) {
|
|
3538
|
+
function convertObject({ schema, name, nullable, defaultValue, options, parse, refs, document }) {
|
|
3485
3539
|
const requiredNames = Array.isArray(schema.required) ? new Set(schema.required) : void 0;
|
|
3486
3540
|
const properties = schema.properties ? Object.entries(schema.properties).map(([propName, propSchema]) => {
|
|
3487
3541
|
const required = requiredNames ? requiredNames.has(propName) : !!schema.required;
|
|
3488
3542
|
const resolvedPropSchema = propSchema;
|
|
3489
|
-
const propNullable = isNullable(resolvedPropSchema);
|
|
3543
|
+
const propNullable = isNullable(resolvedPropSchema, document);
|
|
3490
3544
|
const schemaNode = nameEnums(parse({
|
|
3491
3545
|
schema: resolvedPropSchema,
|
|
3492
3546
|
name: childName(name, propName)
|
|
@@ -3776,7 +3830,7 @@ function createSchemaParser(ctx) {
|
|
|
3776
3830
|
name
|
|
3777
3831
|
});
|
|
3778
3832
|
}
|
|
3779
|
-
const nullable = isNullable(schema) || void 0;
|
|
3833
|
+
const nullable = isNullable(schema, document) || void 0;
|
|
3780
3834
|
const context = {
|
|
3781
3835
|
schema,
|
|
3782
3836
|
name,
|