@workos/oagen 0.17.0 → 0.17.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/cli/index.mjs +34 -5
- package/dist/cli/index.mjs.map +1 -1
- package/dist/index.mjs +34 -5
- package/dist/index.mjs.map +1 -1
- package/dist/scripts/smoke/baseline.mjs +34 -5
- package/dist/scripts/smoke/baseline.mjs.map +1 -1
- package/dist/smoke.mjs +34 -5
- package/dist/smoke.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
|
@@ -534,6 +534,14 @@ function buildInlineModel(name, schema) {
|
|
|
534
534
|
* to apply the same name transform to $ref model/enum references.
|
|
535
535
|
*/
|
|
536
536
|
let activeSchemaNameTransform = null;
|
|
537
|
+
/**
|
|
538
|
+
* Module-level set of resolved schema names whose components/schemas entry is
|
|
539
|
+
* an enum (i.e. has `enum:`). Populated by extractSchemas() so schemaToTypeRef()
|
|
540
|
+
* can classify a `$ref` to a top-level enum schema as `kind: 'enum'` instead of
|
|
541
|
+
* `kind: 'model'`. Without this, every `$ref` was naively returned as a model
|
|
542
|
+
* ref, even when the target was a shared enum like `PaginationOrder`.
|
|
543
|
+
*/
|
|
544
|
+
let activeEnumSchemaNames = /* @__PURE__ */ new Set();
|
|
537
545
|
/** Apply cleanSchemaName + the active transform (if any) to a raw schema name. */
|
|
538
546
|
function resolveSchemaName(rawName) {
|
|
539
547
|
let name = cleanSchemaName(toPascalCase(rawName));
|
|
@@ -559,6 +567,8 @@ function extractSchemas(schemas, options) {
|
|
|
559
567
|
for (const [, originals] of transformedToOriginals) if (originals.length > 1) for (const n of originals) unsafeToTransform.add(n);
|
|
560
568
|
activeSchemaNameTransform = (name) => unsafeToTransform.has(name) ? name : transform(name);
|
|
561
569
|
} else activeSchemaNameTransform = null;
|
|
570
|
+
activeEnumSchemaNames = /* @__PURE__ */ new Set();
|
|
571
|
+
for (const [name, schema] of Object.entries(schemas)) if (schema.enum) activeEnumSchemaNames.add(resolveSchemaName(name));
|
|
562
572
|
const modelsByCleanName = /* @__PURE__ */ new Map();
|
|
563
573
|
for (const [name, schema] of Object.entries(schemas)) {
|
|
564
574
|
const pascalName = resolveSchemaName(name);
|
|
@@ -593,6 +603,7 @@ function extractSchemas(schemas, options) {
|
|
|
593
603
|
/** Clear the module-level schemaNameTransform. Called by parseSpec() after all extraction phases. */
|
|
594
604
|
function clearSchemaNameTransform() {
|
|
595
605
|
activeSchemaNameTransform = null;
|
|
606
|
+
activeEnumSchemaNames = /* @__PURE__ */ new Set();
|
|
596
607
|
}
|
|
597
608
|
/**
|
|
598
609
|
* Walk a single TypeRef and extract inline enum refs as top-level enum definitions.
|
|
@@ -1157,9 +1168,14 @@ function schemaToTypeRef(schema, contextName, parentModelName) {
|
|
|
1157
1168
|
if (schema.$ref) {
|
|
1158
1169
|
const segments = schema.$ref.split("/");
|
|
1159
1170
|
const rawName = segments[segments.length - 1];
|
|
1171
|
+
const resolved = resolveSchemaName(rawName);
|
|
1172
|
+
if (activeEnumSchemaNames.has(resolved)) return {
|
|
1173
|
+
kind: "enum",
|
|
1174
|
+
name: resolved
|
|
1175
|
+
};
|
|
1160
1176
|
return {
|
|
1161
1177
|
kind: "model",
|
|
1162
|
-
name:
|
|
1178
|
+
name: resolved
|
|
1163
1179
|
};
|
|
1164
1180
|
}
|
|
1165
1181
|
if (Array.isArray(schema.type)) {
|
|
@@ -1847,10 +1863,23 @@ function inferServiceName(path, tag) {
|
|
|
1847
1863
|
if (first.startsWith("{")) return "Default";
|
|
1848
1864
|
return toPascalCase(first);
|
|
1849
1865
|
}
|
|
1866
|
+
/**
|
|
1867
|
+
* Strip overload indices (e.g. NestJS emits `Foo_bar[0]` when a controller
|
|
1868
|
+
* method handles multiple routes) from an operationId so derived names never
|
|
1869
|
+
* leak the bracketed digit. Without this, `authenticate[0]` would surface as
|
|
1870
|
+
* `authenticate0` in method names and `Authenticate0Request` in body model
|
|
1871
|
+
* names. Brackets at the end (or with trailing whitespace) are common in
|
|
1872
|
+
* NestJS-style backends; this regex is intentionally narrow to avoid eating
|
|
1873
|
+
* legitimate digits like `oauth2`.
|
|
1874
|
+
*/
|
|
1875
|
+
function normalizeOperationIdForNaming(operationId) {
|
|
1876
|
+
return operationId.replace(/\[\d+\]\s*$/, "");
|
|
1877
|
+
}
|
|
1850
1878
|
function inferOperationName(method, path, operationId, operationIdTransform) {
|
|
1851
1879
|
if (operationId) {
|
|
1852
|
-
|
|
1853
|
-
return
|
|
1880
|
+
const normalized = normalizeOperationIdForNaming(operationId);
|
|
1881
|
+
if (operationIdTransform) return operationIdTransform(normalized);
|
|
1882
|
+
return toCamelCase(normalized);
|
|
1854
1883
|
}
|
|
1855
1884
|
const verb = inferVerb(method, path);
|
|
1856
1885
|
const resource = inferResourceFromPath(path);
|
|
@@ -2168,7 +2197,7 @@ function extractRequestBody(body, op, inlineModels) {
|
|
|
2168
2197
|
};
|
|
2169
2198
|
return {};
|
|
2170
2199
|
}
|
|
2171
|
-
const contextName = cleanSchemaName(op?.operationId ? toPascalCase(op.operationId) + "Request" : "RequestBody");
|
|
2200
|
+
const contextName = cleanSchemaName(op?.operationId ? toPascalCase(normalizeOperationIdForNaming(op.operationId)) + "Request" : "RequestBody");
|
|
2172
2201
|
if (schema.properties && (schema.type === "object" || !schema.type)) {
|
|
2173
2202
|
const requiredSet = new Set(schema.required ?? []);
|
|
2174
2203
|
const fields = [];
|
|
@@ -2249,7 +2278,7 @@ function deriveOneOfVariantName(variant, baseName, existingModels) {
|
|
|
2249
2278
|
return name;
|
|
2250
2279
|
}
|
|
2251
2280
|
function deriveResponseName(op, path, method) {
|
|
2252
|
-
if (op?.operationId) return cleanSchemaName(toPascalCase(op.operationId) + "Response");
|
|
2281
|
+
if (op?.operationId) return cleanSchemaName(toPascalCase(normalizeOperationIdForNaming(op.operationId)) + "Response");
|
|
2253
2282
|
return toPascalCase(path.split("/").filter(Boolean)[0] ?? "Unknown") + toPascalCase(method) + "Response";
|
|
2254
2283
|
}
|
|
2255
2284
|
function extractResponses(responses, op, path, method) {
|