genoc 0.1.0 → 0.1.2
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
CHANGED
|
@@ -89,12 +89,12 @@ function buildClientMethodBody(op) {
|
|
|
89
89
|
if (op.queryParams.length > 0) {
|
|
90
90
|
opts.push('query');
|
|
91
91
|
}
|
|
92
|
-
if (op.headerParams.length > 0) {
|
|
93
|
-
opts.push('headers');
|
|
94
|
-
}
|
|
95
92
|
if (op.requestBody) {
|
|
96
93
|
opts.push('body');
|
|
97
94
|
}
|
|
95
|
+
if (op.headerParams.length > 0) {
|
|
96
|
+
opts.push('headers');
|
|
97
|
+
}
|
|
98
98
|
const lines = [];
|
|
99
99
|
if (op.requestBody?.isMultipart && op.requestBody.schema) {
|
|
100
100
|
const schema = op.requestBody.schema;
|
|
@@ -181,24 +181,22 @@ function buildClientFile(operations, version) {
|
|
|
181
181
|
lines.push('/* global FormData */');
|
|
182
182
|
}
|
|
183
183
|
lines.push('');
|
|
184
|
-
lines.push("const errorsSymbol = Symbol('errors');");
|
|
185
|
-
lines.push('');
|
|
186
184
|
lines.push('function decorateWithErrors<T, E>(');
|
|
187
185
|
lines.push(' item: T,');
|
|
188
186
|
lines.push(' runtimeErrors: unknown,');
|
|
189
|
-
lines.push('): T & {
|
|
190
|
-
lines.push(' Object.defineProperty(item,
|
|
187
|
+
lines.push('): T & { __definedErrors: E } {');
|
|
188
|
+
lines.push(' Object.defineProperty(item, "__definedErrors", {');
|
|
191
189
|
lines.push(' value: runtimeErrors,');
|
|
192
190
|
lines.push(' enumerable: false,');
|
|
193
191
|
lines.push(' configurable: true,');
|
|
194
192
|
lines.push(' writable: false,');
|
|
195
193
|
lines.push(' });');
|
|
196
|
-
lines.push(' return item as T & {
|
|
194
|
+
lines.push(' return item as T & { __definedErrors: E };');
|
|
197
195
|
lines.push('}');
|
|
198
196
|
lines.push('');
|
|
199
197
|
lines.push('export function isDefinedError<E extends ApiError<number, unknown>>(');
|
|
200
198
|
lines.push(' err: unknown,');
|
|
201
|
-
lines.push(' fn: {
|
|
199
|
+
lines.push(' fn: { __definedErrors: E },');
|
|
202
200
|
lines.push('): err is E {');
|
|
203
201
|
lines.push(' if (err instanceof UnspecifiedApiError) return false;');
|
|
204
202
|
lines.push(' if (!(err instanceof ApiError)) return false;');
|
|
@@ -442,16 +442,16 @@ export function generateContracts(doc, resolver) {
|
|
|
442
442
|
lines.push(' constructor(');
|
|
443
443
|
lines.push(' public readonly data: ReadableStream<Uint8Array>,');
|
|
444
444
|
lines.push(' public readonly filename?: string,');
|
|
445
|
-
lines.push(' public readonly headers:
|
|
445
|
+
lines.push(' public readonly headers: Record<string, string> = {},');
|
|
446
446
|
lines.push(' ) {}');
|
|
447
447
|
lines.push('}');
|
|
448
448
|
lines.push('');
|
|
449
449
|
lines.push(`export function streamResponse(
|
|
450
450
|
data: ReadableStream<Uint8Array>,
|
|
451
451
|
filename?: string,
|
|
452
|
-
headers?:
|
|
452
|
+
headers?: Record<string, string>,
|
|
453
453
|
): StreamResponse {
|
|
454
|
-
return new StreamResponse(data, filename, headers ??
|
|
454
|
+
return new StreamResponse(data, filename, headers ?? {});
|
|
455
455
|
}`);
|
|
456
456
|
// ErrorResponse class
|
|
457
457
|
lines.push('');
|
|
@@ -459,7 +459,7 @@ export function generateContracts(doc, resolver) {
|
|
|
459
459
|
constructor(
|
|
460
460
|
public readonly status: number,
|
|
461
461
|
public readonly data: unknown,
|
|
462
|
-
public readonly headers:
|
|
462
|
+
public readonly headers: Record<string, string>,
|
|
463
463
|
public readonly message?: string,
|
|
464
464
|
) {}
|
|
465
465
|
}`);
|
|
@@ -468,10 +468,10 @@ export function generateContracts(doc, resolver) {
|
|
|
468
468
|
lines.push(`export function errorResponse(
|
|
469
469
|
status: number,
|
|
470
470
|
data: unknown,
|
|
471
|
-
headers?:
|
|
471
|
+
headers?: Record<string, string>,
|
|
472
472
|
message?: string,
|
|
473
473
|
): ErrorResponse {
|
|
474
|
-
return new ErrorResponse(status, data, headers ??
|
|
474
|
+
return new ErrorResponse(status, data, headers ?? {}, message);
|
|
475
475
|
}`);
|
|
476
476
|
// RequesterFailError class
|
|
477
477
|
lines.push('');
|
|
@@ -7,7 +7,7 @@ function buildParameters(op) {
|
|
|
7
7
|
if (op.queryParams.length > 0) {
|
|
8
8
|
const prefix = getOperationTypePrefix(op);
|
|
9
9
|
const allOptional = op.queryParams.every((p) => !p.required);
|
|
10
|
-
const hasRequiredAfter = op.headerParams.some((p) => p.required)
|
|
10
|
+
const hasRequiredAfter = !!op.requestBody?.required || op.headerParams.some((p) => p.required);
|
|
11
11
|
if (allOptional && hasRequiredAfter) {
|
|
12
12
|
// All optional query params + required param after: use explicit undefined to avoid "required param cannot follow optional" error
|
|
13
13
|
params.push(`query: ${prefix}Query | undefined`);
|
|
@@ -18,22 +18,17 @@ function buildParameters(op) {
|
|
|
18
18
|
params.push(`query${optional}: ${prefix}Query`);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
if (op.headerParams.length > 0) {
|
|
22
|
-
const prefix = getOperationTypePrefix(op);
|
|
23
|
-
const allOptional = op.headerParams.every((p) => !p.required);
|
|
24
|
-
if (allOptional && op.requestBody?.required) {
|
|
25
|
-
params.push(`headers: ${prefix}Headers | undefined`);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
const optional = allOptional ? '?' : '';
|
|
29
|
-
params.push(`headers${optional}: ${prefix}Headers`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
21
|
if (op.requestBody) {
|
|
33
22
|
const prefix = getOperationTypePrefix(op);
|
|
34
23
|
const optional = op.requestBody.required ? '' : '?';
|
|
35
24
|
params.push(`body${optional}: ${prefix}Body`);
|
|
36
25
|
}
|
|
26
|
+
if (op.headerParams.length > 0) {
|
|
27
|
+
const prefix = getOperationTypePrefix(op);
|
|
28
|
+
const allOptional = op.headerParams.every((p) => !p.required);
|
|
29
|
+
const optional = allOptional ? '?' : '';
|
|
30
|
+
params.push(`headers${optional}: ${prefix}Headers`);
|
|
31
|
+
}
|
|
37
32
|
return params.join(', ');
|
|
38
33
|
}
|
|
39
34
|
function buildJsDoc(op) {
|
|
@@ -117,12 +112,12 @@ function buildImplementation(op) {
|
|
|
117
112
|
if (op.queryParams.length > 0) {
|
|
118
113
|
requesterOpts.push('query');
|
|
119
114
|
}
|
|
120
|
-
if (op.headerParams.length > 0) {
|
|
121
|
-
requesterOpts.push('headers');
|
|
122
|
-
}
|
|
123
115
|
if (op.requestBody) {
|
|
124
116
|
requesterOpts.push('body');
|
|
125
117
|
}
|
|
118
|
+
if (op.headerParams.length > 0) {
|
|
119
|
+
requesterOpts.push('headers');
|
|
120
|
+
}
|
|
126
121
|
// Error responses for status-specific checks
|
|
127
122
|
const errorResponses = op.responses.filter((r) => !r.isSuccess && r.statusCode !== 'default');
|
|
128
123
|
// Lines for inside `if (result instanceof ErrorResponse) { ... }`
|