@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 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 (overrides spec; default from spec or empty)
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
  ```
@@ -5,7 +5,7 @@ export function setAuthToken(token) {
5
5
  _token = token;
6
6
  }
7
7
  export const client = axios.create({
8
- baseURL: "https://api.example.com",
8
+ baseURL: "https://api.example.com/api",
9
9
  headers: {
10
10
  "Content-Type": "application/json",
11
11
  },
@@ -3,6 +3,6 @@ import { client } from "../client.js";
3
3
  /** API client for items endpoints */
4
4
  export const items = {
5
5
  async list() {
6
- return client.get("/api/items/");
6
+ return client.get("/items/");
7
7
  }
8
8
  };
@@ -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") && args[i + 1]) {
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, basePath, definitions) {
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 = basePath + (path.startsWith("/") ? path : `/${path}`);
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 ?? getBasePath(doc);
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, basePath, definitions);
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(baseUrl));
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icib.dev/api-client",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Strictly-typed TypeScript API client for ICIB API",
5
5
  "type": "module",
6
6
  "main": "./dist/api/index.js",