@workos/oagen 0.23.0 → 0.24.0
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/cli/index.mjs +65 -0
- package/dist/cli/index.mjs.map +1 -1
- package/dist/index.mjs +65 -0
- package/dist/index.mjs.map +1 -1
- package/dist/scripts/smoke/baseline.mjs +65 -0
- package/dist/scripts/smoke/baseline.mjs.map +1 -1
- package/dist/smoke.mjs +65 -0
- package/dist/smoke.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -2302,6 +2302,10 @@ function extractRequestBody(body, op, inlineModels) {
|
|
|
2302
2302
|
return {};
|
|
2303
2303
|
}
|
|
2304
2304
|
const contextName = cleanSchemaName(op?.operationId ? toPascalCase(normalizeOperationIdForNaming(op.operationId)) + "Request" : "RequestBody");
|
|
2305
|
+
if (schema.oneOf && schema.discriminator) {
|
|
2306
|
+
const merged = flattenDiscriminatedUnionBody(schema);
|
|
2307
|
+
if (merged) schema = merged;
|
|
2308
|
+
}
|
|
2305
2309
|
if (schema.properties && (schema.type === "object" || !schema.type)) {
|
|
2306
2310
|
const requiredSet = new Set(schema.required ?? []);
|
|
2307
2311
|
const fields = [];
|
|
@@ -2367,6 +2371,67 @@ function extractRequestBody(body, op, inlineModels) {
|
|
|
2367
2371
|
encoding
|
|
2368
2372
|
};
|
|
2369
2373
|
}
|
|
2374
|
+
/**
|
|
2375
|
+
* Fold a discriminated-union request body into the equivalent single object so
|
|
2376
|
+
* its fields can be spread into method arguments instead of forcing callers to
|
|
2377
|
+
* construct an opaque union.
|
|
2378
|
+
*
|
|
2379
|
+
* The result is the union of every variant's properties: the discriminator is
|
|
2380
|
+
* collapsed to an enum of the pinned const values, and any field that isn't
|
|
2381
|
+
* present-and-required in *every* variant becomes optional (it varies by
|
|
2382
|
+
* branch, so it can't be unconditionally required). The discriminator itself is
|
|
2383
|
+
* always required. This mirrors what a spec author would write by hand to model
|
|
2384
|
+
* the same shape as a flat object.
|
|
2385
|
+
*
|
|
2386
|
+
* Returns null — leaving the union intact — unless the body is a clean
|
|
2387
|
+
* inline-object discriminated union: a variant that is a `$ref`, a non-object,
|
|
2388
|
+
* or that doesn't pin the discriminator to a string const can't be safely
|
|
2389
|
+
* merged. Gating on an *explicit* `discriminator` keeps undiscriminated `oneOf`
|
|
2390
|
+
* bodies untouched.
|
|
2391
|
+
*/
|
|
2392
|
+
function flattenDiscriminatedUnionBody(schema) {
|
|
2393
|
+
const discProp = schema.discriminator?.propertyName;
|
|
2394
|
+
if (!discProp || !Array.isArray(schema.oneOf) || schema.oneOf.length === 0) return null;
|
|
2395
|
+
const variants = schema.oneOf;
|
|
2396
|
+
const discValues = [];
|
|
2397
|
+
let discPropSchema;
|
|
2398
|
+
for (const variant of variants) {
|
|
2399
|
+
if (variant.$ref || !variant.properties || !(variant.type === "object" || variant.type === void 0)) return null;
|
|
2400
|
+
const dp = variant.properties[discProp];
|
|
2401
|
+
const constVal = typeof dp?.const === "string" ? dp.const : Array.isArray(dp?.enum) && dp.enum.length === 1 && typeof dp.enum[0] === "string" ? dp.enum[0] : void 0;
|
|
2402
|
+
if (constVal === void 0) return null;
|
|
2403
|
+
if (!discValues.includes(constVal)) discValues.push(constVal);
|
|
2404
|
+
if (!discPropSchema) discPropSchema = dp;
|
|
2405
|
+
}
|
|
2406
|
+
const variantCount = variants.length;
|
|
2407
|
+
const mergedProps = {};
|
|
2408
|
+
const requiredCounts = {};
|
|
2409
|
+
const order = [discProp];
|
|
2410
|
+
for (const variant of variants) {
|
|
2411
|
+
const required = new Set(variant.required ?? []);
|
|
2412
|
+
for (const [name, propSchema] of Object.entries(variant.properties)) {
|
|
2413
|
+
if (name === discProp || !propSchema) continue;
|
|
2414
|
+
if (!(name in mergedProps)) {
|
|
2415
|
+
mergedProps[name] = propSchema;
|
|
2416
|
+
order.push(name);
|
|
2417
|
+
}
|
|
2418
|
+
if (required.has(name)) requiredCounts[name] = (requiredCounts[name] ?? 0) + 1;
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2421
|
+
mergedProps[discProp] = {
|
|
2422
|
+
type: "string",
|
|
2423
|
+
enum: discValues,
|
|
2424
|
+
...discPropSchema?.description ? { description: discPropSchema.description } : {}
|
|
2425
|
+
};
|
|
2426
|
+
const properties = {};
|
|
2427
|
+
for (const name of order) properties[name] = mergedProps[name];
|
|
2428
|
+
return {
|
|
2429
|
+
type: "object",
|
|
2430
|
+
properties,
|
|
2431
|
+
required: order.filter((name) => name === discProp || requiredCounts[name] === variantCount),
|
|
2432
|
+
...schema.description ? { description: schema.description } : {}
|
|
2433
|
+
};
|
|
2434
|
+
}
|
|
2370
2435
|
/** Derive a unique variant name for a oneOf inline model. */
|
|
2371
2436
|
function deriveOneOfVariantName(variant, baseName, existingModels) {
|
|
2372
2437
|
if (variant.properties) {
|