@workos/oagen 0.4.0 → 0.6.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/README.md +0 -1
- package/dist/cli/index.mjs +471 -49
- package/dist/cli/index.mjs.map +1 -1
- package/dist/compat/index.d.mts +1 -1
- package/dist/compat/index.mjs +10 -1
- package/dist/compat/index.mjs.map +1 -1
- package/dist/{diff-DcY93sii.mjs → diff-CltJMcwG.mjs} +376 -42
- package/dist/diff-CltJMcwG.mjs.map +1 -0
- package/dist/index.d.mts +45 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +95 -3
- package/dist/index.mjs.map +1 -1
- package/dist/scripts/smoke/baseline.mjs +93 -2
- package/dist/scripts/smoke/baseline.mjs.map +1 -1
- package/dist/smoke.d.mts +2 -0
- package/dist/smoke.d.mts.map +1 -1
- package/dist/smoke.mjs +93 -2
- package/dist/smoke.mjs.map +1 -1
- package/dist/tree-sitter-C53w_0WE.mjs.map +1 -1
- package/dist/{types-D1tMqLVB.d.mts → types-C7g5sLuX.d.mts} +8 -1
- package/dist/types-C7g5sLuX.d.mts.map +1 -0
- package/dist/verify/index.d.mts +1 -1
- package/dist/verify/index.mjs +1 -1
- package/docs/agents/architecture.md +1 -1
- package/docs/architecture/emitter-contract.md +1 -2
- package/docs/architecture/pipeline.md +0 -1
- package/docs/core/minimal-emitter.md +0 -4
- package/docs/core/quickstart.md +0 -1
- package/examples/reference-emitter/README.md +0 -1
- package/examples/reference-emitter/src/emitter.ts +0 -5
- package/package.json +1 -1
- package/dist/diff-DcY93sii.mjs.map +0 -1
- package/dist/types-D1tMqLVB.d.mts.map +0 -1
- package/examples/reference-emitter/src/generators/config.ts +0 -19
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as collectModelRefs, B as LoggingPolicy, C as TypeParam, D as assignModelsToServices, E as assertNever, F as BackoffStrategy, G as TelemetryPolicy, H as RequestGuardPolicy, I as DeepPartial, J as defaultSdkBehavior, K as TimeoutPolicy, L as ErrorPolicy, M as mapTypeRef, N as walkTypeRef, O as collectEnumRefs, P as AiAgentEnvVar, R as IdempotencyPolicy, S as SuccessResponse, T as UnionType, U as RetryPolicy, V as PaginationPolicy, W as SdkBehavior, Y as mergeSdkBehavior, _ as Parameter, a as EnumRef, b as ServerEntry, c as Field, d as MapType, f as Model, g as PaginationMeta, h as Operation, i as Enum, it as ApiSurface, j as collectRequestBodyModels, k as collectFieldDependencies, l as HttpMethod, m as NullableType, n as ArrayType, o as EnumValue, p as ModelRef, q as UserAgentPolicy, r as AuthScheme, s as ErrorResponse, st as Extractor, t as ApiSpec, u as LiteralType, ut as OverlayLookup, v as PrimitiveType, w as TypeRef, x as Service, y as SecurityRequirement, z as LogEvent } from "./types-
|
|
1
|
+
import { A as collectModelRefs, B as LoggingPolicy, C as TypeParam, D as assignModelsToServices, E as assertNever, F as BackoffStrategy, G as TelemetryPolicy, H as RequestGuardPolicy, I as DeepPartial, J as defaultSdkBehavior, K as TimeoutPolicy, L as ErrorPolicy, M as mapTypeRef, N as walkTypeRef, O as collectEnumRefs, P as AiAgentEnvVar, R as IdempotencyPolicy, S as SuccessResponse, T as UnionType, U as RetryPolicy, V as PaginationPolicy, W as SdkBehavior, Y as mergeSdkBehavior, _ as Parameter, a as EnumRef, b as ServerEntry, c as Field, d as MapType, f as Model, g as PaginationMeta, h as Operation, i as Enum, it as ApiSurface, j as collectRequestBodyModels, k as collectFieldDependencies, l as HttpMethod, m as NullableType, n as ArrayType, o as EnumValue, p as ModelRef, q as UserAgentPolicy, r as AuthScheme, s as ErrorResponse, st as Extractor, t as ApiSpec, u as LiteralType, ut as OverlayLookup, v as PrimitiveType, w as TypeRef, x as Service, y as SecurityRequirement, z as LogEvent } from "./types-C7g5sLuX.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/ir/operation-hints.d.ts
|
|
4
4
|
/** Per-operation override keyed by "METHOD /path" (e.g. "POST /sso/token"). */
|
|
@@ -13,6 +13,13 @@ interface OperationHint {
|
|
|
13
13
|
defaults?: Record<string, string | number | boolean>;
|
|
14
14
|
/** Fields the SDK reads from client config at runtime (e.g. ['client_id']). */
|
|
15
15
|
inferFromClient?: string[];
|
|
16
|
+
/**
|
|
17
|
+
* Marks this operation as a URL builder rather than a real HTTP call. Emitters
|
|
18
|
+
* should generate a method that returns the constructed URL (typically as a
|
|
19
|
+
* string) without performing any I/O. Used for OAuth-style redirect endpoints
|
|
20
|
+
* such as /sso/authorize and /user_management/sessions/logout.
|
|
21
|
+
*/
|
|
22
|
+
urlBuilder?: boolean;
|
|
16
23
|
}
|
|
17
24
|
interface SplitHint {
|
|
18
25
|
/** Wrapper method name (snake_case). */
|
|
@@ -25,6 +32,12 @@ interface SplitHint {
|
|
|
25
32
|
inferFromClient?: string[];
|
|
26
33
|
/** Only these body fields are exposed as method params. If omitted, all non-default/non-inferred fields are exposed. */
|
|
27
34
|
exposedParams?: string[];
|
|
35
|
+
/**
|
|
36
|
+
* Subset of exposedParams that should be emitted as optional even when the
|
|
37
|
+
* variant model would otherwise mark them required (or when the variant has
|
|
38
|
+
* no addressable model, as happens for inline oneOf branches).
|
|
39
|
+
*/
|
|
40
|
+
optionalParams?: string[];
|
|
28
41
|
}
|
|
29
42
|
interface ResolvedOperation {
|
|
30
43
|
/** The original IR operation (preserves description, params, types, etc.). */
|
|
@@ -37,6 +50,12 @@ interface ResolvedOperation {
|
|
|
37
50
|
mountOn: string;
|
|
38
51
|
/** For split operations: one wrapper per union variant. */
|
|
39
52
|
wrappers?: ResolvedWrapper[];
|
|
53
|
+
/** Constant defaults injected into query/body at runtime (from operation-level hint). */
|
|
54
|
+
defaults: Record<string, string | number | boolean>;
|
|
55
|
+
/** Fields the SDK reads from client config at runtime (from operation-level hint). */
|
|
56
|
+
inferFromClient: string[];
|
|
57
|
+
/** Marks this operation as a URL builder; emitters should not generate an HTTP call. */
|
|
58
|
+
urlBuilder: boolean;
|
|
40
59
|
}
|
|
41
60
|
interface ResolvedWrapper {
|
|
42
61
|
/** Wrapper method name (snake_case). */
|
|
@@ -142,6 +161,16 @@ interface EmitterContext {
|
|
|
142
161
|
overlayLookup?: OverlayLookup;
|
|
143
162
|
/** Resolved operations from the hint-aware resolver. Populated by buildEmitterContext(). */
|
|
144
163
|
resolvedOperations?: ResolvedOperation[];
|
|
164
|
+
/** Absolute path to the integration target directory (when --target is used). */
|
|
165
|
+
targetDir?: string;
|
|
166
|
+
/**
|
|
167
|
+
* Paths (relative to the target dir) that the previous run wrote into
|
|
168
|
+
* `--target`, loaded from that directory's `.oagen-manifest.json`. Emitters
|
|
169
|
+
* can use this to distinguish "file exists because oagen wrote it last time"
|
|
170
|
+
* from "file exists because a human wrote it" — the former is safe to
|
|
171
|
+
* overwrite, the latter should be merged.
|
|
172
|
+
*/
|
|
173
|
+
priorTargetManifestPaths?: Set<string>;
|
|
145
174
|
}
|
|
146
175
|
interface FormatCommand {
|
|
147
176
|
/** The executable to run (e.g., "npx", "gofmt", "bundle"). */
|
|
@@ -158,7 +187,6 @@ interface Emitter {
|
|
|
158
187
|
generateResources(services: Service[], ctx: EmitterContext): GeneratedFile[];
|
|
159
188
|
generateClient(spec: ApiSpec, ctx: EmitterContext): GeneratedFile[];
|
|
160
189
|
generateErrors(ctx: EmitterContext): GeneratedFile[];
|
|
161
|
-
generateConfig(ctx: EmitterContext): GeneratedFile[];
|
|
162
190
|
generateTypeSignatures?(spec: ApiSpec, ctx: EmitterContext): GeneratedFile[];
|
|
163
191
|
generateTests(spec: ApiSpec, ctx: EmitterContext): GeneratedFile[];
|
|
164
192
|
/** Optional: generate a smoke-manifest.json mapping operationIds to SDK methods */
|
|
@@ -289,7 +317,8 @@ declare function generate(spec: ApiSpec, emitter: Emitter, options: {
|
|
|
289
317
|
apiSurface?: ApiSurface;
|
|
290
318
|
overlayLookup?: OverlayLookup;
|
|
291
319
|
operationHints?: Record<string, OperationHint>;
|
|
292
|
-
mountRules?: Record<string, string>;
|
|
320
|
+
mountRules?: Record<string, string>; /** When true, skip deletion of files recorded in the previous manifest but not in the current emission. */
|
|
321
|
+
noPrune?: boolean;
|
|
293
322
|
}): Promise<GeneratedFile[]>;
|
|
294
323
|
//#endregion
|
|
295
324
|
//#region src/engine/generate-files.d.ts
|
|
@@ -300,6 +329,8 @@ declare function buildEmitterContext(spec: ApiSpec, options: {
|
|
|
300
329
|
overlayLookup?: OverlayLookup;
|
|
301
330
|
operationHints?: Record<string, OperationHint>;
|
|
302
331
|
mountRules?: Record<string, string>;
|
|
332
|
+
target?: string;
|
|
333
|
+
priorTargetManifestPaths?: Set<string>;
|
|
303
334
|
}): EmitterContext;
|
|
304
335
|
/**
|
|
305
336
|
* Collect model and enum names transitively referenced by service operations.
|
|
@@ -321,6 +352,8 @@ declare function generateFiles(spec: ApiSpec, emitter: Emitter, options: {
|
|
|
321
352
|
overlayLookup?: OverlayLookup;
|
|
322
353
|
operationHints?: Record<string, OperationHint>;
|
|
323
354
|
mountRules?: Record<string, string>;
|
|
355
|
+
target?: string;
|
|
356
|
+
priorTargetManifestPaths?: Set<string>;
|
|
324
357
|
}): {
|
|
325
358
|
files: GeneratedFile[];
|
|
326
359
|
ctx: EmitterContext;
|
|
@@ -343,12 +376,16 @@ interface WriteResult {
|
|
|
343
376
|
*/
|
|
344
377
|
declare function treeShakeFiles(files: GeneratedFile[], language: string): Promise<GeneratedFile[]>;
|
|
345
378
|
declare function mapFilesForTargetIntegration(files: GeneratedFile[], language: string): GeneratedFile[];
|
|
379
|
+
interface IntegrateResult extends WriteResult {
|
|
380
|
+
/** Final set of paths this run claims ownership of in the target (post tree-shake + conflict resolution). */
|
|
381
|
+
emittedPaths: string[];
|
|
382
|
+
}
|
|
346
383
|
declare function integrateGeneratedFiles(opts: {
|
|
347
384
|
files: GeneratedFile[];
|
|
348
385
|
language: string;
|
|
349
386
|
targetDir: string;
|
|
350
387
|
header: string;
|
|
351
|
-
}): Promise<
|
|
388
|
+
}): Promise<IntegrateResult>;
|
|
352
389
|
//#endregion
|
|
353
390
|
//#region src/engine/registry.d.ts
|
|
354
391
|
declare function registerEmitter(emitter: Emitter): void;
|
|
@@ -380,6 +417,10 @@ interface OperationPlan {
|
|
|
380
417
|
* (unwrapped from the list wrapper). Null for non-paginated. */
|
|
381
418
|
paginatedItemModelName: string | null;
|
|
382
419
|
isModelResponse: boolean;
|
|
420
|
+
/** True when the response is an unpaginated `type: array` of models.
|
|
421
|
+
* Emitters should use this to return `Model[]` (or the language's list
|
|
422
|
+
* equivalent) and map the deserializer over each element. */
|
|
423
|
+
isArrayResponse: boolean;
|
|
383
424
|
hasQueryParams: boolean;
|
|
384
425
|
isAsync: boolean;
|
|
385
426
|
}
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/ir/operation-hints.ts","../src/errors.ts","../src/engine/types.ts","../src/differ/types.ts","../src/parser/parse.ts","../src/engine/orchestrator.ts","../src/engine/generate-files.ts","../src/engine/writer.ts","../src/engine/integrate.ts","../src/engine/registry.ts","../src/differ/diff.ts","../src/utils/naming.ts","../src/engine/operation-plan.ts","../src/cli/config-loader.ts"],"mappings":";;;;UAeiB,aAAA;EAAA;EAEf,IAAA;;EAEA,OAAA;EAFA;EAIA,KAAA,GAAQ,SAAA;EAAR;EAEA,QAAA,GAAW,MAAA;EAAX;EAEA,eAAA;AAAA;AAAA,UAGe,SAAA;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/ir/operation-hints.ts","../src/errors.ts","../src/engine/types.ts","../src/differ/types.ts","../src/parser/parse.ts","../src/engine/orchestrator.ts","../src/engine/generate-files.ts","../src/engine/writer.ts","../src/engine/integrate.ts","../src/engine/registry.ts","../src/differ/diff.ts","../src/utils/naming.ts","../src/engine/operation-plan.ts","../src/cli/config-loader.ts"],"mappings":";;;;UAeiB,aAAA;EAAA;EAEf,IAAA;;EAEA,OAAA;EAFA;EAIA,KAAA,GAAQ,SA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,cAAA;EACA,OAAA;AAAA;AAAA,iBAGc,aAAA,CAAc,EAAA,EAAI,SAAA,GAAY,aAAA;;;UCf7B,WAAA;EACf,QAAA,GAAW,OAAA;EACX,UAAA,GAAa,SAAA;EbaI;EaXjB,cAAA;EbOA;EaLA,YAAA,GAAe,MAAA;EbOP;;;;;;EaAR,oBAAA,IAAwB,EAAA;EbcT;;;;;;EaPf,mBAAA,IAAuB,IAAA;EbaZ;;EaVX,MAAA;EboBA;;;AAOF;;EarBE,cAAA,GAAiB,MAAA,SAAe,aAAA;EbuBrB;;;;;;EahBX,UAAA,GAAa,MAAA;AAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { A as walkTypeRef, C as assertNever, D as collectModelRefs, E as collectFieldDependencies, O as collectRequestBodyModels, S as SpecParseError, T as collectEnumRefs, _ as ConfigVersionMismatchError, a as singularize, b as OagenError, c as stripListItemMarkers, d as toPascalCase, f as toSnakeCase, g as ConfigLoadError, h as ConfigError, k as mapTypeRef, l as toCamelCase, m as CommandError, n as ACRONYM_SET, p as toUpperSnakeCase, r as cleanSchemaName, s as stripBackendPrefixes, u as toKebabCase, v as ExtractorError, w as assignModelsToServices, x as RegistryError, y as InternalError } from "./tree-sitter-C53w_0WE.mjs";
|
|
2
|
-
import { a as integrateGeneratedFiles, c as applyFileHeaders, d as generateAllFiles, f as generateFiles, i as generate, l as buildEmitterContext, m as resolveOperations, n as getEmitter, o as mapFilesForTargetIntegration, p as deriveMethodName, r as registerEmitter, s as treeShakeFiles, t as diffSpecs, u as collectReferencedNames } from "./diff-
|
|
2
|
+
import { a as integrateGeneratedFiles, c as applyFileHeaders, d as generateAllFiles, f as generateFiles, i as generate, l as buildEmitterContext, m as resolveOperations, n as getEmitter, o as mapFilesForTargetIntegration, p as deriveMethodName, r as registerEmitter, s as treeShakeFiles, t as diffSpecs, u as collectReferencedNames } from "./diff-CltJMcwG.mjs";
|
|
3
3
|
import { readFile } from "node:fs/promises";
|
|
4
4
|
import { resolve } from "node:path";
|
|
5
5
|
import { pathToFileURL } from "node:url";
|
|
@@ -432,6 +432,86 @@ function buildFieldFromSchema(fieldName, fieldSchema, contextName, requiredSet)
|
|
|
432
432
|
example: fieldSchema.example
|
|
433
433
|
};
|
|
434
434
|
}
|
|
435
|
+
/**
|
|
436
|
+
* If every non-null oneOf/anyOf variant is a string-valued const, return the
|
|
437
|
+
* list of those const values so the union can collapse into a single enum.
|
|
438
|
+
* Returns null when any variant isn't a pure string-const (model ref,
|
|
439
|
+
* number const, nullable, etc.).
|
|
440
|
+
*/
|
|
441
|
+
function collectLiteralStringConsts(variants) {
|
|
442
|
+
if (variants.length === 0) return null;
|
|
443
|
+
const values = [];
|
|
444
|
+
for (const v of variants) {
|
|
445
|
+
if (typeof v.const === "string") {
|
|
446
|
+
values.push(v.const);
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
if (Array.isArray(v.enum) && v.enum.length === 1 && typeof v.enum[0] === "string") {
|
|
450
|
+
values.push(v.enum[0]);
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
return null;
|
|
454
|
+
}
|
|
455
|
+
return values;
|
|
456
|
+
}
|
|
457
|
+
/** Build an EnumRef the same way the regular enum path does for naming. */
|
|
458
|
+
function buildSyntheticEnumRef(values, contextName, parentModelName) {
|
|
459
|
+
const baseName = toPascalCase(contextName ?? "UnknownEnum");
|
|
460
|
+
const cleanParent = parentModelName ? stripListItemMarkers(parentModelName) : void 0;
|
|
461
|
+
return {
|
|
462
|
+
kind: "enum",
|
|
463
|
+
name: cleanParent && !baseName.startsWith(cleanParent) ? `${cleanParent}${baseName}` : baseName,
|
|
464
|
+
values
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Detect an implicit discriminator on an oneOf where every variant is an
|
|
469
|
+
* object schema that pins the same property to a const value. Returns
|
|
470
|
+
* { property, mapping } so the IR can represent the union as discriminated
|
|
471
|
+
* without needing an explicit `discriminator:` key in the spec.
|
|
472
|
+
*
|
|
473
|
+
* Both shapes are supported:
|
|
474
|
+
* { properties: { event: { const: "x" } }, required: ["event"] }
|
|
475
|
+
* { properties: { event: { type: "string", enum: ["x"] } } }
|
|
476
|
+
*
|
|
477
|
+
* Returns null when any variant doesn't fit the pattern or when variants
|
|
478
|
+
* disagree on which property carries the discriminator.
|
|
479
|
+
*/
|
|
480
|
+
function detectConstPropertyDiscriminator(variants) {
|
|
481
|
+
if (variants.length < 2) return null;
|
|
482
|
+
let candidateProperty = null;
|
|
483
|
+
const candidates = Object.keys(variants[0]?.properties ?? {});
|
|
484
|
+
for (const propName of candidates) if (variants.every((v) => getConstPropertyValue(v, propName) !== null)) {
|
|
485
|
+
candidateProperty = propName;
|
|
486
|
+
break;
|
|
487
|
+
}
|
|
488
|
+
if (!candidateProperty) return null;
|
|
489
|
+
const mapping = {};
|
|
490
|
+
for (const v of variants) {
|
|
491
|
+
const value = getConstPropertyValue(v, candidateProperty);
|
|
492
|
+
if (value === null) return null;
|
|
493
|
+
const variantName = resolveVariantModelName(v);
|
|
494
|
+
if (!variantName) return null;
|
|
495
|
+
mapping[value] = variantName;
|
|
496
|
+
}
|
|
497
|
+
return {
|
|
498
|
+
property: candidateProperty,
|
|
499
|
+
mapping
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
function getConstPropertyValue(schema, property) {
|
|
503
|
+
const prop = schema.properties?.[property];
|
|
504
|
+
if (!prop) return null;
|
|
505
|
+
if (typeof prop.const === "string") return prop.const;
|
|
506
|
+
if (Array.isArray(prop.enum) && prop.enum.length === 1 && typeof prop.enum[0] === "string") return prop.enum[0];
|
|
507
|
+
return null;
|
|
508
|
+
}
|
|
509
|
+
function resolveVariantModelName(schema) {
|
|
510
|
+
if (schema.$ref) return resolveSchemaName(schema.$ref.replace(/^#\/components\/schemas\//, ""));
|
|
511
|
+
const title = typeof schema["title"] === "string" ? schema["title"] : null;
|
|
512
|
+
if (title) return resolveSchemaName(title);
|
|
513
|
+
return null;
|
|
514
|
+
}
|
|
435
515
|
function extractEnum(name, schema) {
|
|
436
516
|
return {
|
|
437
517
|
name,
|
|
@@ -655,6 +735,15 @@ function schemaToTypeRef(schema, contextName, parentModelName) {
|
|
|
655
735
|
kind: "nullable",
|
|
656
736
|
inner: schemaToTypeRef(nonNullVariants[0], contextName, parentModelName)
|
|
657
737
|
};
|
|
738
|
+
const literalStrings = collectLiteralStringConsts(nonNullVariants);
|
|
739
|
+
if (literalStrings !== null && literalStrings.length >= 2) {
|
|
740
|
+
const enumRef = buildSyntheticEnumRef(literalStrings, contextName, parentModelName);
|
|
741
|
+
return nullVariant ? {
|
|
742
|
+
kind: "nullable",
|
|
743
|
+
inner: enumRef
|
|
744
|
+
} : enumRef;
|
|
745
|
+
}
|
|
746
|
+
const syntheticDiscriminator = !schema.discriminator && compositionKind === "oneOf" ? detectConstPropertyDiscriminator(nonNullVariants) : null;
|
|
658
747
|
const variants = rawVariants.filter((v) => v.type !== "null").map((v) => schemaToTypeRef(v, contextName, parentModelName));
|
|
659
748
|
const hasNull = !!nullVariant;
|
|
660
749
|
const union = {
|
|
@@ -664,7 +753,7 @@ function schemaToTypeRef(schema, contextName, parentModelName) {
|
|
|
664
753
|
...schema.discriminator ? { discriminator: {
|
|
665
754
|
property: schema.discriminator.propertyName,
|
|
666
755
|
mapping: Object.fromEntries(Object.entries(schema.discriminator.mapping ?? {}).map(([k, v]) => [k, v.replace(/^#\/components\/schemas\//, "")]))
|
|
667
|
-
} } : {}
|
|
756
|
+
} } : syntheticDiscriminator ? { discriminator: syntheticDiscriminator } : {}
|
|
668
757
|
};
|
|
669
758
|
return hasNull ? {
|
|
670
759
|
kind: "nullable",
|
|
@@ -1415,7 +1504,9 @@ function extractParams(params, location, operationContext) {
|
|
|
1415
1504
|
description: p.description,
|
|
1416
1505
|
deprecated: p.deprecated || p.schema?.deprecated || void 0,
|
|
1417
1506
|
default: p.schema?.default,
|
|
1418
|
-
example: p.example ?? p.schema?.example
|
|
1507
|
+
example: p.example ?? p.schema?.example,
|
|
1508
|
+
style: p.style,
|
|
1509
|
+
explode: p.explode
|
|
1419
1510
|
}));
|
|
1420
1511
|
}
|
|
1421
1512
|
function extractRequestBody(body, op, inlineModels) {
|
|
@@ -1831,6 +1922,7 @@ function planOperation(op) {
|
|
|
1831
1922
|
responseModelName,
|
|
1832
1923
|
paginatedItemModelName: isPaginated && op.pagination?.itemType.kind === "model" ? op.pagination.itemType.name : null,
|
|
1833
1924
|
isModelResponse: responseModelName !== null,
|
|
1925
|
+
isArrayResponse: !isPaginated && op.response.kind === "array" && op.response.items.kind === "model",
|
|
1834
1926
|
hasQueryParams,
|
|
1835
1927
|
isAsync: op.async ?? true
|
|
1836
1928
|
};
|