@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
package/dist/cli/index.mjs
CHANGED
|
@@ -2353,6 +2353,10 @@ function extractRequestBody(body, op, inlineModels) {
|
|
|
2353
2353
|
return {};
|
|
2354
2354
|
}
|
|
2355
2355
|
const contextName = cleanSchemaName(op?.operationId ? toPascalCase(normalizeOperationIdForNaming(op.operationId)) + "Request" : "RequestBody");
|
|
2356
|
+
if (schema.oneOf && schema.discriminator) {
|
|
2357
|
+
const merged = flattenDiscriminatedUnionBody(schema);
|
|
2358
|
+
if (merged) schema = merged;
|
|
2359
|
+
}
|
|
2356
2360
|
if (schema.properties && (schema.type === "object" || !schema.type)) {
|
|
2357
2361
|
const requiredSet = new Set(schema.required ?? []);
|
|
2358
2362
|
const fields = [];
|
|
@@ -2418,6 +2422,67 @@ function extractRequestBody(body, op, inlineModels) {
|
|
|
2418
2422
|
encoding
|
|
2419
2423
|
};
|
|
2420
2424
|
}
|
|
2425
|
+
/**
|
|
2426
|
+
* Fold a discriminated-union request body into the equivalent single object so
|
|
2427
|
+
* its fields can be spread into method arguments instead of forcing callers to
|
|
2428
|
+
* construct an opaque union.
|
|
2429
|
+
*
|
|
2430
|
+
* The result is the union of every variant's properties: the discriminator is
|
|
2431
|
+
* collapsed to an enum of the pinned const values, and any field that isn't
|
|
2432
|
+
* present-and-required in *every* variant becomes optional (it varies by
|
|
2433
|
+
* branch, so it can't be unconditionally required). The discriminator itself is
|
|
2434
|
+
* always required. This mirrors what a spec author would write by hand to model
|
|
2435
|
+
* the same shape as a flat object.
|
|
2436
|
+
*
|
|
2437
|
+
* Returns null — leaving the union intact — unless the body is a clean
|
|
2438
|
+
* inline-object discriminated union: a variant that is a `$ref`, a non-object,
|
|
2439
|
+
* or that doesn't pin the discriminator to a string const can't be safely
|
|
2440
|
+
* merged. Gating on an *explicit* `discriminator` keeps undiscriminated `oneOf`
|
|
2441
|
+
* bodies untouched.
|
|
2442
|
+
*/
|
|
2443
|
+
function flattenDiscriminatedUnionBody(schema) {
|
|
2444
|
+
const discProp = schema.discriminator?.propertyName;
|
|
2445
|
+
if (!discProp || !Array.isArray(schema.oneOf) || schema.oneOf.length === 0) return null;
|
|
2446
|
+
const variants = schema.oneOf;
|
|
2447
|
+
const discValues = [];
|
|
2448
|
+
let discPropSchema;
|
|
2449
|
+
for (const variant of variants) {
|
|
2450
|
+
if (variant.$ref || !variant.properties || !(variant.type === "object" || variant.type === void 0)) return null;
|
|
2451
|
+
const dp = variant.properties[discProp];
|
|
2452
|
+
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;
|
|
2453
|
+
if (constVal === void 0) return null;
|
|
2454
|
+
if (!discValues.includes(constVal)) discValues.push(constVal);
|
|
2455
|
+
if (!discPropSchema) discPropSchema = dp;
|
|
2456
|
+
}
|
|
2457
|
+
const variantCount = variants.length;
|
|
2458
|
+
const mergedProps = {};
|
|
2459
|
+
const requiredCounts = {};
|
|
2460
|
+
const order = [discProp];
|
|
2461
|
+
for (const variant of variants) {
|
|
2462
|
+
const required = new Set(variant.required ?? []);
|
|
2463
|
+
for (const [name, propSchema] of Object.entries(variant.properties)) {
|
|
2464
|
+
if (name === discProp || !propSchema) continue;
|
|
2465
|
+
if (!(name in mergedProps)) {
|
|
2466
|
+
mergedProps[name] = propSchema;
|
|
2467
|
+
order.push(name);
|
|
2468
|
+
}
|
|
2469
|
+
if (required.has(name)) requiredCounts[name] = (requiredCounts[name] ?? 0) + 1;
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
mergedProps[discProp] = {
|
|
2473
|
+
type: "string",
|
|
2474
|
+
enum: discValues,
|
|
2475
|
+
...discPropSchema?.description ? { description: discPropSchema.description } : {}
|
|
2476
|
+
};
|
|
2477
|
+
const properties = {};
|
|
2478
|
+
for (const name of order) properties[name] = mergedProps[name];
|
|
2479
|
+
return {
|
|
2480
|
+
type: "object",
|
|
2481
|
+
properties,
|
|
2482
|
+
required: order.filter((name) => name === discProp || requiredCounts[name] === variantCount),
|
|
2483
|
+
...schema.description ? { description: schema.description } : {}
|
|
2484
|
+
};
|
|
2485
|
+
}
|
|
2421
2486
|
/** Derive a unique variant name for a oneOf inline model. */
|
|
2422
2487
|
function deriveOneOfVariantName(variant, baseName, existingModels) {
|
|
2423
2488
|
if (variant.properties) {
|