genoc 0.4.0 → 0.4.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 +2 -2
- package/dist/analyzer/analyze.js +32 -73
- package/dist/analyzer/discriminator-registry.d.ts +108 -0
- package/dist/analyzer/discriminator-registry.js +209 -0
- package/dist/analyzer/schema-mapper.d.ts +66 -5
- package/dist/analyzer/schema-mapper.js +291 -36
- package/dist/analyzer/types.d.ts +8 -1
- package/dist/cli/impl.js +4 -1
- package/dist/generator/method-generator.js +33 -17
- package/dist/pipeline.d.ts +2 -0
- package/dist/pipeline.js +1 -0
- package/dist/utils/proxy.d.ts +2 -0
- package/dist/utils/proxy.js +16 -0
- package/dist/utils/string.d.ts +7 -0
- package/dist/utils/string.js +9 -0
- package/package.json +15 -7
package/dist/utils/proxy.js
CHANGED
|
@@ -48,6 +48,16 @@ export function hasProxyEnv() {
|
|
|
48
48
|
process.env.HTTPS_PROXY ||
|
|
49
49
|
process.env.https_proxy);
|
|
50
50
|
}
|
|
51
|
+
/** True when the dynamic `import('undici')` failed because undici is not installed (Node: ERR_MODULE_NOT_FOUND; Bun: "Cannot find package" message). */
|
|
52
|
+
export function isMissingUndiciError(err) {
|
|
53
|
+
if (!(err instanceof Error))
|
|
54
|
+
return false;
|
|
55
|
+
const code = err.code;
|
|
56
|
+
if (code === 'ERR_MODULE_NOT_FOUND')
|
|
57
|
+
return true;
|
|
58
|
+
return /Cannot find (?:module|package) ['"]?undici/.test(err.message);
|
|
59
|
+
}
|
|
60
|
+
const MISSING_UNDICI_MESSAGE = "Proxy support requires the 'undici' package. Install it: npm install undici";
|
|
51
61
|
export async function fetchSpec(url, opts) {
|
|
52
62
|
if (opts?.proxy) {
|
|
53
63
|
assertValidProxyUrl(opts.proxy);
|
|
@@ -59,6 +69,9 @@ export async function fetchSpec(url, opts) {
|
|
|
59
69
|
}));
|
|
60
70
|
}
|
|
61
71
|
catch (err) {
|
|
72
|
+
if (isMissingUndiciError(err)) {
|
|
73
|
+
throw new Error(MISSING_UNDICI_MESSAGE);
|
|
74
|
+
}
|
|
62
75
|
throw new Error(`Failed to fetch spec from URL via proxy ${redacted}: ${describeFetchError(err)}`, {
|
|
63
76
|
cause: err,
|
|
64
77
|
});
|
|
@@ -72,6 +85,9 @@ export async function fetchSpec(url, opts) {
|
|
|
72
85
|
}));
|
|
73
86
|
}
|
|
74
87
|
catch (err) {
|
|
88
|
+
if (isMissingUndiciError(err)) {
|
|
89
|
+
throw new Error(MISSING_UNDICI_MESSAGE);
|
|
90
|
+
}
|
|
75
91
|
throw new Error(`Failed to fetch spec from URL via proxy env: ${describeFetchError(err)}`, {
|
|
76
92
|
cause: err,
|
|
77
93
|
});
|
package/dist/utils/string.d.ts
CHANGED
|
@@ -26,6 +26,13 @@ export declare function isReservedWord(str: string): boolean;
|
|
|
26
26
|
* @returns Safe TypeScript identifier
|
|
27
27
|
*/
|
|
28
28
|
export declare function sanitizeIdentifier(str: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Escape a value for interpolation inside a TypeScript single-quoted string
|
|
31
|
+
* literal (backslash first, then the quote itself)
|
|
32
|
+
* @param value The raw string value
|
|
33
|
+
* @returns The value with `\` and `'` escaped
|
|
34
|
+
*/
|
|
35
|
+
export declare function escapeStringLiteral(value: string): string;
|
|
29
36
|
/**
|
|
30
37
|
* Quote a key if needed for TypeScript object literals
|
|
31
38
|
* @param key The key to potentially quote
|
package/dist/utils/string.js
CHANGED
|
@@ -163,6 +163,15 @@ export function sanitizeIdentifier(str) {
|
|
|
163
163
|
}
|
|
164
164
|
return final;
|
|
165
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Escape a value for interpolation inside a TypeScript single-quoted string
|
|
168
|
+
* literal (backslash first, then the quote itself)
|
|
169
|
+
* @param value The raw string value
|
|
170
|
+
* @returns The value with `\` and `'` escaped
|
|
171
|
+
*/
|
|
172
|
+
export function escapeStringLiteral(value) {
|
|
173
|
+
return value.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
|
174
|
+
}
|
|
166
175
|
/**
|
|
167
176
|
* Quote a key if needed for TypeScript object literals
|
|
168
177
|
* @param key The key to potentially quote
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "genoc",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Generate typed HTTP clients from OpenAPI 3.0 / 3.1 specifications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"client",
|
|
@@ -43,19 +43,27 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@stricli/core": "^1.2.6",
|
|
45
45
|
"lilconfig": "^3.1.3",
|
|
46
|
-
"undici": "^6.13.0",
|
|
47
46
|
"yaml": "^2.2.2",
|
|
48
47
|
"zod": "^4.0.0"
|
|
49
48
|
},
|
|
50
49
|
"devDependencies": {
|
|
51
50
|
"@changesets/cli": "^2.31.0",
|
|
52
|
-
"@types/node": "^
|
|
53
|
-
"oxfmt": "^0.
|
|
54
|
-
"oxlint": "^1.
|
|
51
|
+
"@types/node": "^26.6.2",
|
|
52
|
+
"oxfmt": "^0.70.0",
|
|
53
|
+
"oxlint": "^1.85.0",
|
|
55
54
|
"typescript": "^6.0.3",
|
|
56
|
-
"
|
|
55
|
+
"undici": "^8",
|
|
56
|
+
"vitest": "^5.0.1"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"undici": "^6.13.0 || ^7 || ^8"
|
|
60
|
+
},
|
|
61
|
+
"peerDependenciesMeta": {
|
|
62
|
+
"undici": {
|
|
63
|
+
"optional": true
|
|
64
|
+
}
|
|
57
65
|
},
|
|
58
66
|
"engines": {
|
|
59
|
-
"node": ">=18"
|
|
67
|
+
"node": ">=20.18.1"
|
|
60
68
|
}
|
|
61
69
|
}
|