@redocly/client-generator 0.0.0-snapshot.1784554531 → 0.0.0-snapshot.manual
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/lib/emitters/client.d.ts +71 -0
- package/lib/emitters/client.d.ts.map +1 -0
- package/lib/emitters/client.js +28 -0
- package/lib/emitters/client.js.map +1 -0
- package/lib/emitters/package-client.d.ts +15 -0
- package/lib/emitters/package-client.d.ts.map +1 -0
- package/lib/emitters/package-client.js +300 -0
- package/lib/emitters/package-client.js.map +1 -0
- package/lib/writers/index.d.ts +5 -0
- package/lib/writers/index.d.ts.map +1 -0
- package/lib/writers/index.js +11 -0
- package/lib/writers/index.js.map +1 -0
- package/lib/writers/single-file-writer.d.ts +8 -0
- package/lib/writers/single-file-writer.d.ts.map +1 -0
- package/lib/writers/single-file-writer.js +10 -0
- package/lib/writers/single-file-writer.js.map +1 -0
- package/lib/writers/split-writer.d.ts +14 -0
- package/lib/writers/split-writer.d.ts.map +1 -0
- package/lib/writers/split-writer.js +23 -0
- package/lib/writers/split-writer.js.map +1 -0
- package/lib/writers/types.d.ts +31 -0
- package/lib/writers/types.d.ts.map +1 -0
- package/lib/writers/types.js +2 -0
- package/lib/writers/types.js.map +1 -0
- package/lib/writers/util.d.ts +14 -0
- package/lib/writers/util.d.ts.map +1 -0
- package/lib/writers/util.js +14 -0
- package/lib/writers/util.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { ApiModel } from '../intermediate-representation/model.js';
|
|
2
|
+
import type { ArgsStyle } from './operations.js';
|
|
3
|
+
import type { PaginationConfig } from './pagination.js';
|
|
4
|
+
import type { DateType, EnumStyle } from './types.js';
|
|
5
|
+
export type { ArgsStyle } from './operations.js';
|
|
6
|
+
/** The generated-by banner prepended to every emitted module. */
|
|
7
|
+
export declare const HEADER = "// Generated by @redocly/client-generator \u2014 do not edit by hand.\n// Source: OpenAPI document. Re-run `redocly generate-client` to update.";
|
|
8
|
+
export type EmitOptions = {
|
|
9
|
+
/**
|
|
10
|
+
* Override the server URL baked into the generated client config. When omitted,
|
|
11
|
+
* the value is derived from `servers[0].url` in the source OpenAPI document.
|
|
12
|
+
*/
|
|
13
|
+
serverUrl?: string;
|
|
14
|
+
/**
|
|
15
|
+
* How named string enums are emitted:
|
|
16
|
+
* - `'union'`: only the string-literal union type (`type X = "a" | "b"`).
|
|
17
|
+
* - `'const-object'` (default): the union type *and* a sibling
|
|
18
|
+
* `export const X = { a: "a", b: "b" } as const;` so callers can reference
|
|
19
|
+
* the values at runtime (`X.a`).
|
|
20
|
+
*/
|
|
21
|
+
enumStyle?: EnumStyle;
|
|
22
|
+
/**
|
|
23
|
+
* How operation inputs are passed to each call. Defaults to `'flat'`;
|
|
24
|
+
* `'grouped'` bundles inputs into a single `args` object.
|
|
25
|
+
*/
|
|
26
|
+
argsStyle?: ArgsStyle;
|
|
27
|
+
/** Error-handling shape of the generated client. Defaults to `'throw'`. */
|
|
28
|
+
errorMode?: 'throw' | 'result';
|
|
29
|
+
/**
|
|
30
|
+
* How `format: date-time`/`date` string fields are typed. `'string'` (default)
|
|
31
|
+
* keeps the ISO wire shape; `'Date'` emits a `Date` reference. Opt-in — pair with
|
|
32
|
+
* the `transformers` generator so the runtime value matches the type.
|
|
33
|
+
*/
|
|
34
|
+
dateType?: DateType;
|
|
35
|
+
/**
|
|
36
|
+
* TanStack Query adapter the generated module imports from
|
|
37
|
+
* (`@tanstack/${queryFramework}-query`). Defaults to `'react'`; the emitted body
|
|
38
|
+
* is byte-identical across frameworks — only the import specifier changes.
|
|
39
|
+
*/
|
|
40
|
+
queryFramework?: 'react' | 'vue' | 'svelte' | 'solid';
|
|
41
|
+
/**
|
|
42
|
+
* How the `mock` generator produces data. `'baked'` (default) inlines deterministic
|
|
43
|
+
* literals (zero-dep, contract-faithful); `'faker'` emits `@faker-js/faker` calls for
|
|
44
|
+
* realistic data — reproducible when `mockSeed` is set. Only the mock module is affected.
|
|
45
|
+
*/
|
|
46
|
+
mockData?: 'baked' | 'faker';
|
|
47
|
+
/** Seed for faker-mode mocks: emits a top-level `faker.seed(<n>)` so runs reproduce. */
|
|
48
|
+
mockSeed?: number;
|
|
49
|
+
/**
|
|
50
|
+
* A pre-baked publisher setup block (from `bakeSetup`) merged into the client's config
|
|
51
|
+
* via `mergeSetup`. Absent when no `--setup` is given.
|
|
52
|
+
*/
|
|
53
|
+
setup?: string;
|
|
54
|
+
/** Runtime distribution: 'inline' (default, self-contained) | 'package' (imports @redocly/client-generator). */
|
|
55
|
+
runtime?: 'inline' | 'package';
|
|
56
|
+
/**
|
|
57
|
+
* Auto-pagination rules (a convention rule + per-operation overrides + `exclude`),
|
|
58
|
+
* resolved together with each operation's `x-pagination` extension. Verified
|
|
59
|
+
* statically: an explicit rule that doesn't fit its operation fails generation.
|
|
60
|
+
*/
|
|
61
|
+
pagination?: PaginationConfig;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Assemble file content from a header banner and a printed body: the leading
|
|
65
|
+
* `// Generated by …` comment and the `/** title */` block are structural
|
|
66
|
+
* banners (not part of the printed AST), prepended with blank-line separation.
|
|
67
|
+
* Trailing newline mirrors a hand-authored file.
|
|
68
|
+
*/
|
|
69
|
+
export declare function banner(sections: string[]): string;
|
|
70
|
+
export declare function renderTitleComment(model: ApiModel): string;
|
|
71
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/emitters/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yCAAyC,CAAC;AACxE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAGxD,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAItD,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,iEAAiE;AACjE,eAAO,MAAM,MAAM,oJACwD,CAAC;AAE5E,MAAM,MAAM,WAAW,GAAG;IACxB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,2EAA2E;IAC3E,SAAS,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;IACtD;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;IAC7B,wFAAwF;IACxF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gHAAgH;IAChH,OAAO,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC/B;;;;OAIG;IACH,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC/B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,CAEjD;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAY1D"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { splitLines } from './support.js';
|
|
2
|
+
import { escapeJsDoc } from './ts.js';
|
|
3
|
+
/** The generated-by banner prepended to every emitted module. */
|
|
4
|
+
export const HEADER = `// Generated by @redocly/client-generator — do not edit by hand.
|
|
5
|
+
// Source: OpenAPI document. Re-run \`redocly generate-client\` to update.`;
|
|
6
|
+
/**
|
|
7
|
+
* Assemble file content from a header banner and a printed body: the leading
|
|
8
|
+
* `// Generated by …` comment and the `/** title */` block are structural
|
|
9
|
+
* banners (not part of the printed AST), prepended with blank-line separation.
|
|
10
|
+
* Trailing newline mirrors a hand-authored file.
|
|
11
|
+
*/
|
|
12
|
+
export function banner(sections) {
|
|
13
|
+
return sections.filter((s) => s.length > 0).join('\n\n') + '\n';
|
|
14
|
+
}
|
|
15
|
+
export function renderTitleComment(model) {
|
|
16
|
+
// This banner is a raw string (it does not flow through `jsdoc()`), so escape
|
|
17
|
+
// `*/` here too — `info.title`/`info.description` are attacker-controllable and
|
|
18
|
+
// would otherwise close the comment and inject code at the top of every file.
|
|
19
|
+
const lines = [`/**`, ` * ${escapeJsDoc(`${model.title} (v${model.version})`)}`];
|
|
20
|
+
if (model.description) {
|
|
21
|
+
for (const line of splitLines(escapeJsDoc(model.description))) {
|
|
22
|
+
lines.push(` * ${line}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
lines.push(' */');
|
|
26
|
+
return lines.join('\n');
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/emitters/client.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAOtC,iEAAiE;AACjE,MAAM,CAAC,MAAM,MAAM,GAAG;2EACqD,CAAC;AA0D5E;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,QAAkB;IACvC,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,KAAe;IAChD,8EAA8E;IAC9E,gFAAgF;IAChF,8EAA8E;IAC9E,MAAM,KAAK,GAAG,CAAC,KAAK,EAAE,MAAM,WAAW,CAAC,GAAG,KAAK,CAAC,KAAK,MAAM,KAAK,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC,CAAC;IACjF,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;QACtB,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC;YAC9D,KAAK,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ApiModel } from '../intermediate-representation/model.js';
|
|
2
|
+
import { type EmitOptions } from './client.js';
|
|
3
|
+
export declare function emitClientSingleFile(model: ApiModel, options?: EmitOptions): string;
|
|
4
|
+
/**
|
|
5
|
+
* `split` mode: the same client with the schema types + type guards carved out into a
|
|
6
|
+
* sibling `<stem>.schemas.ts`. The entry file re-exports the schemas module
|
|
7
|
+
* (`export *`) and type-imports exactly the schema names its own code references, so
|
|
8
|
+
* both files hold under `noUnusedLocals`. `schemas` is absent when the document
|
|
9
|
+
* declares no schema statements (the entry is then self-contained).
|
|
10
|
+
*/
|
|
11
|
+
export declare function emitClientSplit(model: ApiModel, options: EmitOptions, stem: string): {
|
|
12
|
+
entry: string;
|
|
13
|
+
schemas?: string;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=package-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-client.d.ts","sourceRoot":"","sources":["../../src/emitters/package-client.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EACV,QAAQ,EAGT,MAAM,yCAAyC,CAAC;AAGjD,OAAO,EAAU,KAAK,WAAW,EAA8B,MAAM,aAAa,CAAC;AAqCnF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,GAAE,WAAgB,GAAG,MAAM,CAEvF;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,WAAW,EACpB,IAAI,EAAE,MAAM,GACX;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAErC"}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
// Client assembly, shared by both runtime distributions and both output modes. The
|
|
2
|
+
// wiring (descriptor map + `Ops` interface, emitters/descriptor.ts) is identical; only
|
|
3
|
+
// the runtime block differs — `runtime: 'package'` imports `createClient` from
|
|
4
|
+
// `@redocly/client-generator`, everything else (inline, the default) embeds the
|
|
5
|
+
// assembled runtime sources in its place (emitters/inline-runtime.ts). Single-file
|
|
6
|
+
// layout: runtime (import line | embedded block) → schema types → type guards →
|
|
7
|
+
// `<Op>*` aliases → Ops → OPERATIONS → (baked setup) → client instance → sugar →
|
|
8
|
+
// (package mode only) type re-exports — the embedded types are already exported in
|
|
9
|
+
// place, so the embed arm needs none. Split mode moves the schema types + guards into
|
|
10
|
+
// a sibling `<stem>.schemas.ts` the entry re-exports (`emitClientSplit`).
|
|
11
|
+
import { allOperations } from '../writers/util.js';
|
|
12
|
+
import { apiKeySetterName } from './auth.js';
|
|
13
|
+
import { banner, HEADER, renderTitleComment } from './client.js';
|
|
14
|
+
import { descriptorStatements, opsInterfaceStatements, packageIdents } from './descriptor.js';
|
|
15
|
+
import { isIdentifier } from './identifier.js';
|
|
16
|
+
import { assembleInlineRuntime } from './inline-runtime.js';
|
|
17
|
+
import { renderOperationAliases, sseAliases } from './operation-aliases.js';
|
|
18
|
+
import { operationSignature } from './operation-signature.js';
|
|
19
|
+
import { computeResponse, errorTypeNodes, isTypedMultipart } from './operation-types.js';
|
|
20
|
+
import { renderArgList } from './operations.js';
|
|
21
|
+
import { resolveModelPagination } from './pagination.js';
|
|
22
|
+
import { isSseOp } from './sse.js';
|
|
23
|
+
import { pascalCase } from './support.js';
|
|
24
|
+
import { arrow, exportConstStatement, parseStatements, printNodes, printStatements, ts, } from './ts.js';
|
|
25
|
+
import { typeGuardStatements } from './type-guards.js';
|
|
26
|
+
import { typesStatements } from './types.js';
|
|
27
|
+
const { factory } = ts;
|
|
28
|
+
const PACKAGE_SPECIFIER = '@redocly/client-generator';
|
|
29
|
+
/**
|
|
30
|
+
* A double-quoted TS string literal for generated code. `JSON.stringify` alone leaves
|
|
31
|
+
* U+2028/U+2029 raw (legal JSON, line terminators in code contexts) — escape them so a
|
|
32
|
+
* hostile spec value can never alter the shape of the emitted statement.
|
|
33
|
+
*/
|
|
34
|
+
function codeString(value) {
|
|
35
|
+
return JSON.stringify(value)
|
|
36
|
+
.replace(/\u2028/g, '\\u2028')
|
|
37
|
+
.replace(/\u2029/g, '\\u2029');
|
|
38
|
+
}
|
|
39
|
+
export function emitClientSingleFile(model, options = {}) {
|
|
40
|
+
return emitClient(model, options).entry;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* `split` mode: the same client with the schema types + type guards carved out into a
|
|
44
|
+
* sibling `<stem>.schemas.ts`. The entry file re-exports the schemas module
|
|
45
|
+
* (`export *`) and type-imports exactly the schema names its own code references, so
|
|
46
|
+
* both files hold under `noUnusedLocals`. `schemas` is absent when the document
|
|
47
|
+
* declares no schema statements (the entry is then self-contained).
|
|
48
|
+
*/
|
|
49
|
+
export function emitClientSplit(model, options, stem) {
|
|
50
|
+
return emitClient(model, options, stem);
|
|
51
|
+
}
|
|
52
|
+
/** The shared assembly; `splitStem` (when given) selects the two-file split layout. */
|
|
53
|
+
function emitClient(model, options, splitStem) {
|
|
54
|
+
const embed = options.runtime !== 'package';
|
|
55
|
+
const ops = allOperations(model.services);
|
|
56
|
+
const idents = packageIdents(model);
|
|
57
|
+
// Resolved (and VERIFIED) up front: an explicit rule that doesn't fit throws here,
|
|
58
|
+
// before any statement is built — one aggregated error for the whole model.
|
|
59
|
+
const pagination = resolveModelPagination(model, options.pagination);
|
|
60
|
+
const ctx = {
|
|
61
|
+
argsStyle: options.argsStyle ?? 'flat',
|
|
62
|
+
errorMode: options.errorMode ?? 'throw',
|
|
63
|
+
dateType: options.dateType ?? 'string',
|
|
64
|
+
queryAuthKeys: new Set(model.securitySchemes.filter((s) => s.kind === 'apiKeyQuery').map((s) => s.key)),
|
|
65
|
+
schemaNames: new Set(model.schemas.map((s) => s.name)),
|
|
66
|
+
pagination,
|
|
67
|
+
};
|
|
68
|
+
const flat = ctx.argsStyle === 'flat';
|
|
69
|
+
const hasSse = ops.some(isSseOp);
|
|
70
|
+
const hasRegular = ops.some((op) => !isSseOp(op));
|
|
71
|
+
const apiKeySchemes = model.securitySchemes.filter((s) => s.kind === 'apiKeyHeader' || s.kind === 'apiKeyQuery' || s.kind === 'apiKeyCookie');
|
|
72
|
+
const wiring = ops.length > 0
|
|
73
|
+
? [
|
|
74
|
+
...opsInterfaceStatements(model, idents, ctx),
|
|
75
|
+
...descriptorStatements(model, idents, ctx.dateType, pagination),
|
|
76
|
+
]
|
|
77
|
+
: // A spec with no operations still gets the uniform wiring shape.
|
|
78
|
+
parseStatements('export type Ops = Record<string, never>;\n' +
|
|
79
|
+
'export const OPERATIONS = {} as const satisfies Record<string, OperationDescriptor>;');
|
|
80
|
+
const runtimeSection = embed
|
|
81
|
+
? assembleInlineRuntime({
|
|
82
|
+
multipart: ops.some((op) => op.requestBody && isTypedMultipart(op.requestBody)),
|
|
83
|
+
// Auth sugar needs schemes; `resolveAuth` fires when a descriptor carries
|
|
84
|
+
// `security` — a valid spec implies the former, but embed on either.
|
|
85
|
+
auth: model.securitySchemes.length > 0 || ops.some((op) => op.security.length > 0),
|
|
86
|
+
sse: hasSse,
|
|
87
|
+
setup: !!options.setup,
|
|
88
|
+
paginate: pagination.size > 0,
|
|
89
|
+
})
|
|
90
|
+
: importLine(options, ctx, {
|
|
91
|
+
hasFlatSse: hasSse && flat,
|
|
92
|
+
hasFlatRegular: hasRegular && flat,
|
|
93
|
+
hasRegular,
|
|
94
|
+
hasApiKey: apiKeySchemes.length > 0,
|
|
95
|
+
});
|
|
96
|
+
const schemaStatements = [
|
|
97
|
+
...typesStatements(model.schemas, options.enumStyle ?? 'const-object', ctx.dateType),
|
|
98
|
+
...typeGuardStatements(model.schemas),
|
|
99
|
+
];
|
|
100
|
+
const bodyStatements = [...ops.flatMap((op) => aliasStatements(op, ctx)), ...wiring];
|
|
101
|
+
const sugar = printNodes(sugarStatements(ops, idents, ctx, model.securitySchemes, apiKeySchemes));
|
|
102
|
+
// Embed mode exports its whole public surface in place; only the package arm re-exports.
|
|
103
|
+
const reexports = embed ? '' : reexportLines(ctx, hasSse);
|
|
104
|
+
// Layout puts the reader's OWN API first (types → aliases → Ops → OPERATIONS) and the
|
|
105
|
+
// machinery after it. In embed mode the runtime block sits between the descriptors and
|
|
106
|
+
// the `client` initializer — after it for readability, before `client` so every
|
|
107
|
+
// declaration the module-init call chain touches (hoisted functions AND any future
|
|
108
|
+
// top-level const) is already evaluated; in package mode the import line leads.
|
|
109
|
+
if (splitStem === undefined) {
|
|
110
|
+
return {
|
|
111
|
+
entry: banner([
|
|
112
|
+
HEADER,
|
|
113
|
+
renderTitleComment(model),
|
|
114
|
+
...(embed ? [] : [runtimeSection]),
|
|
115
|
+
printStatements([...schemaStatements, ...bodyStatements]),
|
|
116
|
+
...(embed ? [runtimeSection] : []),
|
|
117
|
+
clientSection(options, ctx, model),
|
|
118
|
+
sugar,
|
|
119
|
+
reexports,
|
|
120
|
+
]),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const body = printStatements(bodyStatements);
|
|
124
|
+
const hasSchemas = schemaStatements.length > 0;
|
|
125
|
+
return {
|
|
126
|
+
entry: banner([
|
|
127
|
+
HEADER,
|
|
128
|
+
renderTitleComment(model),
|
|
129
|
+
hasSchemas
|
|
130
|
+
? schemaLinks(body + '\n' + sugar, ctx.schemaNames, `./${splitStem}.schemas.js`)
|
|
131
|
+
: '',
|
|
132
|
+
...(embed ? [] : [runtimeSection]),
|
|
133
|
+
body,
|
|
134
|
+
...(embed ? [runtimeSection] : []),
|
|
135
|
+
clientSection(options, ctx, model),
|
|
136
|
+
sugar,
|
|
137
|
+
reexports,
|
|
138
|
+
]),
|
|
139
|
+
schemas: hasSchemas
|
|
140
|
+
? banner([HEADER, renderTitleComment(model), printStatements(schemaStatements)])
|
|
141
|
+
: undefined,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The entry ⇄ schemas linkage of the split layout: a type-only import of exactly the
|
|
146
|
+
* schema names the entry's own code references, plus the public `export *` re-export.
|
|
147
|
+
* Referenced names are found by walking the printed entry code's identifiers (an AST
|
|
148
|
+
* pass over the emitted text, not a substring search — operation JSDoc may mention a
|
|
149
|
+
* schema name, and importing an unreferenced type would trip `noUnusedLocals`).
|
|
150
|
+
*/
|
|
151
|
+
function schemaLinks(entryCode, schemaNames, specifier) {
|
|
152
|
+
const referenced = new Set();
|
|
153
|
+
const visit = (node) => {
|
|
154
|
+
if (ts.isIdentifier(node) && schemaNames.has(node.text))
|
|
155
|
+
referenced.add(node.text);
|
|
156
|
+
node.forEachChild(visit);
|
|
157
|
+
};
|
|
158
|
+
for (const statement of parseStatements(entryCode))
|
|
159
|
+
visit(statement);
|
|
160
|
+
const names = [...referenced].sort();
|
|
161
|
+
const importLine = names.length > 0 ? `import type { ${names.join(', ')} } from '${specifier}';\n` : '';
|
|
162
|
+
return `${importLine}export * from '${specifier}';`;
|
|
163
|
+
}
|
|
164
|
+
/** The single import from the runtime package — only names the file actually references. */
|
|
165
|
+
function importLine(options, ctx, refs) {
|
|
166
|
+
const values = ['createClient', ...(options.setup ? ['mergeSetup'] : [])];
|
|
167
|
+
const types = [
|
|
168
|
+
...(options.setup ? ['ClientConfig', 'Middleware'] : []),
|
|
169
|
+
'OperationDescriptor',
|
|
170
|
+
// Flat sugar signatures reference the per-call option types.
|
|
171
|
+
...(refs.hasFlatRegular ? ['RequestOptions'] : []),
|
|
172
|
+
// `Ops` wraps results in `Result` in result mode — but only NON-SSE members
|
|
173
|
+
// (an SSE-only spec would otherwise import it unused and fail noUnusedLocals).
|
|
174
|
+
...(ctx.errorMode === 'result' && refs.hasRegular ? ['Result'] : []),
|
|
175
|
+
...(refs.hasFlatSse ? ['SseOptions'] : []),
|
|
176
|
+
// The apiKey sugar closures take a `TokenProvider`.
|
|
177
|
+
...(refs.hasApiKey ? ['TokenProvider'] : []),
|
|
178
|
+
].sort();
|
|
179
|
+
const names = [...values, ...types.map((t) => `type ${t}`)].join(', ');
|
|
180
|
+
return `import { ${names} } from '${PACKAGE_SPECIFIER}';`;
|
|
181
|
+
}
|
|
182
|
+
/** One operation's `<Op>*` aliases — the same emitters and suppression rules as inline mode. */
|
|
183
|
+
function aliasStatements(op, ctx) {
|
|
184
|
+
const { pathParams } = operationSignature(op);
|
|
185
|
+
const ordered = pathParams.map((p) => p.param);
|
|
186
|
+
const identMap = new Map(pathParams.map((p) => [p.param.name, p.ident]));
|
|
187
|
+
if (isSseOp(op))
|
|
188
|
+
return sseAliases(op, ordered, identMap, ctx, 'wire');
|
|
189
|
+
const { responseType } = computeResponse(op.successResponses, ctx.dateType);
|
|
190
|
+
const errorMembers = ctx.errorMode === 'result' ? errorTypeNodes(op.errorResponses, ctx.dateType) : [];
|
|
191
|
+
const errorAlias = errorMembers.length > 0 ? `${pascalCase(op.name)}Error` : '';
|
|
192
|
+
return renderOperationAliases(op, responseType, ordered, identMap, errorAlias, errorMembers, ctx, true, 'wire');
|
|
193
|
+
}
|
|
194
|
+
/** The (optional) baked setup + the default `client` instance. */
|
|
195
|
+
function clientSection(options, ctx, model) {
|
|
196
|
+
const serverUrl = options.serverUrl ?? model.serverUrl;
|
|
197
|
+
const fields = [
|
|
198
|
+
// Always baked when the document declares one: the runtime's fallback is a
|
|
199
|
+
// relative URL, which Node's fetch rejects.
|
|
200
|
+
...(serverUrl !== undefined ? [`serverUrl: ${codeString(serverUrl)}`] : []),
|
|
201
|
+
...(ctx.errorMode === 'result' ? ['errorMode: "result"'] : []),
|
|
202
|
+
];
|
|
203
|
+
const config = fields.length > 0 ? `{ ${fields.join(', ')} }` : '{}';
|
|
204
|
+
// Precedence, lowest → highest: spec defaults → baked publisher setup → app `configure()`.
|
|
205
|
+
// The inner merge flattens the setup into a ClientConfig; the outer layers it OVER the
|
|
206
|
+
// spec defaults (mergeSetup's second argument wins per-field; middleware composes).
|
|
207
|
+
const configArg = options.setup
|
|
208
|
+
? `mergeSetup({ config: ${config} }, mergeSetup(__redoclySetup, {}))`
|
|
209
|
+
: config;
|
|
210
|
+
// The trailing type args narrow `ctx.operation` to the spec's literal unions.
|
|
211
|
+
// `OperationTag` mirrors descriptorStatements' gate: derived only when some
|
|
212
|
+
// operation is tagged (it would otherwise be `never`); zero-ops specs have no
|
|
213
|
+
// derived unions at all, so they keep the string defaults.
|
|
214
|
+
const ops = allOperations(model.services);
|
|
215
|
+
const hasTags = ops.some((op) => op.tags.length > 0);
|
|
216
|
+
const typeArgs = ops.length > 0
|
|
217
|
+
? `<Ops, OperationId, OperationPath, ${hasTags ? 'OperationTag' : 'string'}>`
|
|
218
|
+
: '<Ops>';
|
|
219
|
+
const client = `export const client = createClient${typeArgs}(OPERATIONS, ${configArg});`;
|
|
220
|
+
if (!options.setup)
|
|
221
|
+
return client;
|
|
222
|
+
return ('// ─── Baked-in setup (--setup) ───\n' +
|
|
223
|
+
`const __redoclySetup: { config?: ClientConfig; middleware?: Middleware[] } = ${options.setup};\n` +
|
|
224
|
+
client);
|
|
225
|
+
}
|
|
226
|
+
/** Core destructure + per-scheme auth setters + per-operation call sugar. */
|
|
227
|
+
function sugarStatements(ops, idents, ctx, schemes, apiKeySchemes) {
|
|
228
|
+
const statements = [...parseStatements('export const { configure, use } = client;')];
|
|
229
|
+
// Auth sugar in `authSetterNames` order: bearer, basic, then each apiKey scheme.
|
|
230
|
+
// The runtime's auth members close over the instance config (no `this`), so
|
|
231
|
+
// direct bindings are safe.
|
|
232
|
+
if (schemes.some((s) => s.kind === 'bearer')) {
|
|
233
|
+
statements.push(...parseStatements('export const setBearer = client.auth.bearer;'));
|
|
234
|
+
}
|
|
235
|
+
if (schemes.some((s) => s.kind === 'basic')) {
|
|
236
|
+
statements.push(...parseStatements('export const setBasicAuth = client.auth.basic;'));
|
|
237
|
+
}
|
|
238
|
+
for (const scheme of apiKeySchemes) {
|
|
239
|
+
const name = apiKeySetterName(scheme.key, apiKeySchemes.length === 1);
|
|
240
|
+
statements.push(...parseStatements(`export const ${name} = (value: TokenProvider) => client.auth.apiKey(${codeString(scheme.key)}, value);`));
|
|
241
|
+
}
|
|
242
|
+
if (ops.length === 0)
|
|
243
|
+
return statements;
|
|
244
|
+
if (ctx.argsStyle === 'grouped') {
|
|
245
|
+
// Grouped style: the client methods already take the grouped args shape.
|
|
246
|
+
const names = ops.map((op) => idents.get(op.name)).join(', ');
|
|
247
|
+
statements.push(...parseStatements(`export const { ${names} } = client;`));
|
|
248
|
+
return statements;
|
|
249
|
+
}
|
|
250
|
+
for (const op of ops)
|
|
251
|
+
statements.push(flatSugarStatement(op, idents.get(op.name), ctx));
|
|
252
|
+
return statements;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* One flat one-liner: today's positional signature forwarding to the grouped client
|
|
256
|
+
* method. Path values are keyed by the WIRE name (the runtime routes
|
|
257
|
+
* `args[param.name]`); a path param literally named `params`/`body`/`headers` would
|
|
258
|
+
* collide with the slot keys — a spec-acknowledged runtime-contract limitation.
|
|
259
|
+
* A paginated operation's arrow is wrapped in `Object.assign(…, { pages, items })`
|
|
260
|
+
* so the flat sugar preserves the method-attached iterators.
|
|
261
|
+
*/
|
|
262
|
+
function flatSugarStatement(op, ident, ctx) {
|
|
263
|
+
const { pathParams } = operationSignature(op);
|
|
264
|
+
const params = renderArgList(op, pathParams.map((p) => p.param), new Map(pathParams.map((p) => [p.param.name, p.ident])), ctx);
|
|
265
|
+
const props = pathParams.map(({ param, ident: paramIdent }) => param.name === paramIdent
|
|
266
|
+
? factory.createShorthandPropertyAssignment(paramIdent)
|
|
267
|
+
: factory.createPropertyAssignment(isIdentifier(param.name) ? param.name : factory.createStringLiteral(param.name), factory.createIdentifier(paramIdent)));
|
|
268
|
+
if (op.queryParams.length > 0)
|
|
269
|
+
props.push(factory.createShorthandPropertyAssignment('params'));
|
|
270
|
+
if (op.requestBody)
|
|
271
|
+
props.push(factory.createShorthandPropertyAssignment('body'));
|
|
272
|
+
if (op.headerParams.length > 0) {
|
|
273
|
+
props.push(factory.createShorthandPropertyAssignment('headers'));
|
|
274
|
+
}
|
|
275
|
+
const call = factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier('client'), ident), undefined, [factory.createObjectLiteralExpression(props, false), factory.createIdentifier('init')]);
|
|
276
|
+
const fn = arrow(params, call);
|
|
277
|
+
if (!ctx.pagination?.has(op.name))
|
|
278
|
+
return exportConstStatement(ident, fn);
|
|
279
|
+
const methodMember = (name) => factory.createPropertyAssignment(name, factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createIdentifier('client'), ident), name));
|
|
280
|
+
return exportConstStatement(ident, factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier('Object'), 'assign'), undefined, [
|
|
281
|
+
fn,
|
|
282
|
+
factory.createObjectLiteralExpression([methodMember('pages'), methodMember('items')], false),
|
|
283
|
+
]));
|
|
284
|
+
}
|
|
285
|
+
/** Public type surface re-exported for single-import DX (plus the `ApiError` class). */
|
|
286
|
+
function reexportLines(ctx, hasSse) {
|
|
287
|
+
const types = [
|
|
288
|
+
'ClientConfig',
|
|
289
|
+
'Middleware',
|
|
290
|
+
'RequestOptions',
|
|
291
|
+
...(ctx.errorMode === 'result' ? ['Result'] : []),
|
|
292
|
+
...(hasSse ? ['ServerSentEvent', 'SseOptions'] : []),
|
|
293
|
+
].sort();
|
|
294
|
+
return (
|
|
295
|
+
// `createClient` is re-exported so package-mode consumers can build additional
|
|
296
|
+
// instances from the generated module alone — symmetric with inline output.
|
|
297
|
+
`export { ApiError, createClient } from '${PACKAGE_SPECIFIER}';\n` +
|
|
298
|
+
`export type { ${types.join(', ')} } from '${PACKAGE_SPECIFIER}';`);
|
|
299
|
+
}
|
|
300
|
+
//# sourceMappingURL=package-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-client.js","sourceRoot":"","sources":["../../src/emitters/package-client.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,uFAAuF;AACvF,+EAA+E;AAC/E,gFAAgF;AAChF,mFAAmF;AACnF,gFAAgF;AAChF,iFAAiF;AACjF,mFAAmF;AACnF,sFAAsF;AACtF,0EAA0E;AAO1E,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAoB,MAAM,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC9F,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACzF,OAAO,EAAoB,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,M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AO,CAAC,CAAC,EAC9C,KAAK,CACN;KACF,CACF,CACF,CAAC;AACJ,CAAC;AAED,wFAAwF;AACxF,SAAS,aAAa,CAAC,GAAgB,EAAE,MAAe;IACtD,MAAM,KAAK,GAAG;QACZ,cAAc;QACd,YAAY;QACZ,gBAAgB;QAChB,GAAG,CAAC,GAAG,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACjD,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;KACrD,CAAC,IAAI,EAAE,CAAC;IACT,OAAO;IACL,+EAA+E;IAC/E,4EAA4E;IAC5E,2CAA2C,iBAAiB,MAAM;QAClE,iBAAiB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,iBAAiB,IAAI,CACnE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { OutputMode, Writer } from './types.js';
|
|
2
|
+
export type { GeneratedFile, OutputMode, Writer, WriterInput } from './types.js';
|
|
3
|
+
/** Select the writer for an output mode. */
|
|
4
|
+
export declare function getWriter(mode: OutputMode): Writer;
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/writers/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAErD,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAOjF,4CAA4C;AAC5C,wBAAgB,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAElD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { singleFileWriter } from './single-file-writer.js';
|
|
2
|
+
import { splitWriter } from './split-writer.js';
|
|
3
|
+
const WRITERS = {
|
|
4
|
+
single: singleFileWriter,
|
|
5
|
+
split: splitWriter,
|
|
6
|
+
};
|
|
7
|
+
/** Select the writer for an output mode. */
|
|
8
|
+
export function getWriter(mode) {
|
|
9
|
+
return WRITERS[mode];
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/writers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAKhD,MAAM,OAAO,GAA+B;IAC1C,MAAM,EAAE,gBAAgB;IACxB,KAAK,EAAE,WAAW;CACnB,CAAC;AAEF,4CAA4C;AAC5C,MAAM,UAAU,SAAS,CAAC,IAAgB;IACxC,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Writer } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The default writer: the whole client in one file at the `--output` path. The shared
|
|
4
|
+
* emitter branches on `emit.runtime` internally — `inline` (the default) embeds the
|
|
5
|
+
* runtime sources, `package` imports them from `@redocly/client-generator`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const singleFileWriter: Writer;
|
|
8
|
+
//# sourceMappingURL=single-file-writer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"single-file-writer.d.ts","sourceRoot":"","sources":["../../src/writers/single-file-writer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,MAE9B,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { emitClientSingleFile } from '../emitters/package-client.js';
|
|
2
|
+
/**
|
|
3
|
+
* The default writer: the whole client in one file at the `--output` path. The shared
|
|
4
|
+
* emitter branches on `emit.runtime` internally — `inline` (the default) embeds the
|
|
5
|
+
* runtime sources, `package` imports them from `@redocly/client-generator`.
|
|
6
|
+
*/
|
|
7
|
+
export const singleFileWriter = ({ model, outputPath, emit }) => [
|
|
8
|
+
{ path: outputPath, content: emitClientSingleFile(model, emit) },
|
|
9
|
+
];
|
|
10
|
+
//# sourceMappingURL=single-file-writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"single-file-writer.js","sourceRoot":"","sources":["../../src/writers/single-file-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAGrE;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAW,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;IACvE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,oBAAoB,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE;CACjE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Writer } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* `split` mode: two sibling files derived from the `--output` anchor, for both
|
|
4
|
+
* runtime distributions.
|
|
5
|
+
*
|
|
6
|
+
* <stem>.schemas.ts model types, enums, const-objects, and type guards
|
|
7
|
+
* <stem>.ts everything else (runtime, wiring, client, sugar), which
|
|
8
|
+
* `export *`s the schemas module and type-imports exactly
|
|
9
|
+
* the schema names it references
|
|
10
|
+
*
|
|
11
|
+
* The schemas file is skipped entirely when the document declares no schemas.
|
|
12
|
+
*/
|
|
13
|
+
export declare const splitWriter: Writer;
|
|
14
|
+
//# sourceMappingURL=split-writer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"split-writer.d.ts","sourceRoot":"","sources":["../../src/writers/split-writer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAGzC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW,EAAE,MAOzB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { emitClientSplit } from '../emitters/package-client.js';
|
|
3
|
+
import { anchor } from './util.js';
|
|
4
|
+
/**
|
|
5
|
+
* `split` mode: two sibling files derived from the `--output` anchor, for both
|
|
6
|
+
* runtime distributions.
|
|
7
|
+
*
|
|
8
|
+
* <stem>.schemas.ts model types, enums, const-objects, and type guards
|
|
9
|
+
* <stem>.ts everything else (runtime, wiring, client, sugar), which
|
|
10
|
+
* `export *`s the schemas module and type-imports exactly
|
|
11
|
+
* the schema names it references
|
|
12
|
+
*
|
|
13
|
+
* The schemas file is skipped entirely when the document declares no schemas.
|
|
14
|
+
*/
|
|
15
|
+
export const splitWriter = ({ model, outputPath, emit }) => {
|
|
16
|
+
const { dir, stem } = anchor(outputPath);
|
|
17
|
+
const { entry, schemas } = emitClientSplit(model, emit, stem);
|
|
18
|
+
return [
|
|
19
|
+
...(schemas === undefined ? [] : [{ path: join(dir, `${stem}.schemas.ts`), content: schemas }]),
|
|
20
|
+
{ path: outputPath, content: entry },
|
|
21
|
+
];
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=split-writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"split-writer.js","sourceRoot":"","sources":["../../src/writers/split-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,WAAW,GAAW,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE;IACjE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;IACzC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,eAAe,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9D,OAAO;QACL,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,aAAa,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAC/F,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE;KACrC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { EmitOptions } from '../emitters/client.js';
|
|
2
|
+
import type { ApiModel } from '../intermediate-representation/model.js';
|
|
3
|
+
/**
|
|
4
|
+
* How the generated client is partitioned across files.
|
|
5
|
+
*
|
|
6
|
+
* - `single` (default): one self-contained file.
|
|
7
|
+
* - `split`: schema types + guards in a sibling `<stem>.schemas.ts`; everything
|
|
8
|
+
* else in the entry file, which re-exports the schemas module.
|
|
9
|
+
*/
|
|
10
|
+
export type OutputMode = 'single' | 'split';
|
|
11
|
+
/** A single file the generator will write to disk. */
|
|
12
|
+
export type GeneratedFile = {
|
|
13
|
+
path: string;
|
|
14
|
+
content: string;
|
|
15
|
+
};
|
|
16
|
+
export type WriterInput = {
|
|
17
|
+
model: ApiModel;
|
|
18
|
+
/**
|
|
19
|
+
* The `--output` anchor path (ends in `.ts`). Multi-file writers derive sibling
|
|
20
|
+
* and per-tag-folder paths from its directory and base name (stem).
|
|
21
|
+
*/
|
|
22
|
+
outputPath: string;
|
|
23
|
+
emit: EmitOptions;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* A Writer turns the IR + emit options into the set of files to write. This is
|
|
27
|
+
* the one seam output modes vary at; the emitter (which renders code) stays
|
|
28
|
+
* mode-agnostic.
|
|
29
|
+
*/
|
|
30
|
+
export type Writer = (input: WriterInput) => GeneratedFile[];
|
|
31
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/writers/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yCAAyC,CAAC;AAExE;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE5C,sDAAsD;AACtD,MAAM,MAAM,aAAa,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9D,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,QAAQ,CAAC;IAChB;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,WAAW,CAAC;CACnB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,MAAM,GAAG,CAAC,KAAK,EAAE,WAAW,KAAK,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/writers/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { OperationModel } from '../intermediate-representation/model.js';
|
|
2
|
+
/**
|
|
3
|
+
* Derive the directory and base name (stem, without `.ts`) from the `--output`
|
|
4
|
+
* anchor path. Multi-file writers build sibling/per-tag paths from these.
|
|
5
|
+
*/
|
|
6
|
+
export declare function anchor(outputPath: string): {
|
|
7
|
+
dir: string;
|
|
8
|
+
stem: string;
|
|
9
|
+
};
|
|
10
|
+
/** All operations across the model's services, flattened. */
|
|
11
|
+
export declare function allOperations(operationsByService: {
|
|
12
|
+
operations: OperationModel[];
|
|
13
|
+
}[]): OperationModel[];
|
|
14
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/writers/util.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAE9E;;;GAGG;AACH,wBAAgB,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAGxE;AAED,6DAA6D;AAC7D,wBAAgB,aAAa,CAC3B,mBAAmB,EAAE;IAAE,UAAU,EAAE,cAAc,EAAE,CAAA;CAAE,EAAE,GACtD,cAAc,EAAE,CAElB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { parse } from 'node:path';
|
|
2
|
+
/**
|
|
3
|
+
* Derive the directory and base name (stem, without `.ts`) from the `--output`
|
|
4
|
+
* anchor path. Multi-file writers build sibling/per-tag paths from these.
|
|
5
|
+
*/
|
|
6
|
+
export function anchor(outputPath) {
|
|
7
|
+
const { dir, name } = parse(outputPath);
|
|
8
|
+
return { dir, stem: name };
|
|
9
|
+
}
|
|
10
|
+
/** All operations across the model's services, flattened. */
|
|
11
|
+
export function allOperations(operationsByService) {
|
|
12
|
+
return operationsByService.flatMap((service) => service.operations);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/writers/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAIlC;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,UAAkB;IACvC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;IACxC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAC7B,CAAC;AAED,6DAA6D;AAC7D,MAAM,UAAU,aAAa,CAC3B,mBAAuD;IAEvD,OAAO,mBAAmB,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AACtE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redocly/client-generator",
|
|
3
|
-
"version": "0.0.0-snapshot.
|
|
3
|
+
"version": "0.0.0-snapshot.manual",
|
|
4
4
|
"description": "Generate typed, zero-dependency TypeScript clients (fetch, auth, retries, middleware, SSE) from OpenAPI descriptions.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"Roman Marshevskyi <roman.marshevskyy@redocly.com> (https://redocly.com/)"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@redocly/openapi-core": "
|
|
48
|
+
"@redocly/openapi-core": "2.39.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"typescript": ">=5.5.0"
|