@icib.dev/api-client 1.0.4 → 1.0.5
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 +1 -1
- package/dist/api/client.js +1 -1
- package/dist/api/contexts/items.js +1 -1
- package/dist/scripts/generate.js +10 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ npx api-client-generate --url https://api.example.com/docs/openapi --out api
|
|
|
42
42
|
# Using BASE_URL env (default: $BASE_URL/docs/openapi)
|
|
43
43
|
BASE_URL=https://api.example.com npx api-client-generate --out api
|
|
44
44
|
|
|
45
|
-
# Custom base path (
|
|
45
|
+
# Custom base path (default empty; when set, included in axios baseURL)
|
|
46
46
|
npx api-client-generate --base-path /v1/api
|
|
47
47
|
BASE_PATH=/v2 npx api-client-generate
|
|
48
48
|
```
|
package/dist/api/client.js
CHANGED
package/dist/scripts/generate.js
CHANGED
|
@@ -26,7 +26,8 @@ function parseArgs() {
|
|
|
26
26
|
else if (args[i] === "--out" && args[i + 1]) {
|
|
27
27
|
out = args[++i];
|
|
28
28
|
}
|
|
29
|
-
else if ((args[i] === "--base-path" || args[i] === "--basePath") &&
|
|
29
|
+
else if ((args[i] === "--base-path" || args[i] === "--basePath") &&
|
|
30
|
+
args[i + 1]) {
|
|
30
31
|
basePath = args[++i];
|
|
31
32
|
}
|
|
32
33
|
}
|
|
@@ -70,10 +71,6 @@ function getOrigin(doc) {
|
|
|
70
71
|
}
|
|
71
72
|
return "https://api.icib.dev";
|
|
72
73
|
}
|
|
73
|
-
function getBasePath(doc) {
|
|
74
|
-
const oas2 = doc;
|
|
75
|
-
return oas2.basePath ?? "";
|
|
76
|
-
}
|
|
77
74
|
function getDefinitions(doc) {
|
|
78
75
|
return doc.definitions ?? doc.components?.schemas ?? {};
|
|
79
76
|
}
|
|
@@ -172,11 +169,11 @@ function generateTypes(definitions) {
|
|
|
172
169
|
lines.push("}\n");
|
|
173
170
|
return lines.join("\n");
|
|
174
171
|
}
|
|
175
|
-
function extractOperations(paths,
|
|
172
|
+
function extractOperations(paths, definitions) {
|
|
176
173
|
const ops = [];
|
|
177
174
|
const methods = ["get", "post", "put", "patch", "delete"];
|
|
178
175
|
for (const [path, pathItem] of Object.entries(paths)) {
|
|
179
|
-
const fullPath =
|
|
176
|
+
const fullPath = path.startsWith("/") ? path : `/${path}`;
|
|
180
177
|
for (const method of methods) {
|
|
181
178
|
const op = pathItem[method];
|
|
182
179
|
if (!op?.operationId)
|
|
@@ -625,7 +622,7 @@ async function main() {
|
|
|
625
622
|
const doc = await parseSpec(rawSpec);
|
|
626
623
|
const baseUrl = getOrigin(doc);
|
|
627
624
|
const basePath = (() => {
|
|
628
|
-
const raw = basePathOverride ??
|
|
625
|
+
const raw = basePathOverride ?? "";
|
|
629
626
|
if (raw === "")
|
|
630
627
|
return "";
|
|
631
628
|
return raw.startsWith("/") ? raw : `/${raw}`;
|
|
@@ -636,7 +633,7 @@ async function main() {
|
|
|
636
633
|
console.log(`Base path: ${basePath}`);
|
|
637
634
|
console.log(`Paths: ${Object.keys(paths).length}`);
|
|
638
635
|
console.log(`Definitions: ${Object.keys(definitions).length}`);
|
|
639
|
-
const ops = extractOperations(paths,
|
|
636
|
+
const ops = extractOperations(paths, definitions);
|
|
640
637
|
const byTag = groupByTag(ops, paths);
|
|
641
638
|
const cwd = process.cwd();
|
|
642
639
|
const outDir = join(cwd, out);
|
|
@@ -644,8 +641,11 @@ async function main() {
|
|
|
644
641
|
const contextsDir = join(outDir, "contexts");
|
|
645
642
|
mkdirSync(typesDir, { recursive: true });
|
|
646
643
|
mkdirSync(contextsDir, { recursive: true });
|
|
644
|
+
const clientBaseUrl = basePath
|
|
645
|
+
? `${baseUrl.replace(/\/$/, "")}${basePath}`
|
|
646
|
+
: baseUrl;
|
|
647
647
|
writeFileSync(join(typesDir, "index.ts"), generateTypes(definitions));
|
|
648
|
-
writeFileSync(join(outDir, "client.ts"), generateClient(
|
|
648
|
+
writeFileSync(join(outDir, "client.ts"), generateClient(clientBaseUrl));
|
|
649
649
|
const sortedTags = [...byTag.keys()].sort();
|
|
650
650
|
for (const tag of sortedTags) {
|
|
651
651
|
const ctxName = sanitizeContextName(tag);
|