apigen-ts 1.2.0 → 1.2.1

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/dist/cli.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var main$1 = require('./main-C0qK6dZX.cjs');
3
+ var main$1 = require('./main-BLaUzCCM.cjs');
4
4
  require('fs/promises');
5
5
  require('path');
6
6
  require('url');
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { a as apigen, g as getCliConfig } from './main-l0LIDQ3K.js';
2
+ import { a as apigen, g as getCliConfig } from './main-BZrWxHPM.js';
3
3
  import 'fs/promises';
4
4
  import 'path';
5
5
  import 'url';
package/dist/cli.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as apigen, g as getCliConfig } from './main-l0LIDQ3K.mjs';
1
+ import { a as apigen, g as getCliConfig } from './main-BZrWxHPM.mjs';
2
2
  import 'fs/promises';
3
3
  import 'path';
4
4
  import 'url';
@@ -13,7 +13,7 @@ var path = require('node:path');
13
13
 
14
14
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
15
15
  var name = "apigen-ts";
16
- var version = "1.2.0";
16
+ var version = "1.2.1";
17
17
 
18
18
  const initCtx = (config) => {
19
19
  return {
@@ -275,6 +275,8 @@ const makeType = (ctx, s) => {
275
275
  else if (s.type === "string") t = f$2.createKeywordTypeNode(ts.SyntaxKind.StringKeyword);
276
276
  else if (s.type === "null") t = f$2.createLiteralTypeNode(f$2.createNull());
277
277
  else if (lodashEs.isArray(s.type)) t = makeLiteralUnion(ctx, s.type);
278
+ else if (s.type === "array" && isPrefixItems(s) && s.prefixItems && !s.items)
279
+ t = f$2.createTupleTypeNode(s.prefixItems.map(mk));
278
280
  else if (s.type === "array" && !lodashEs.isBoolean(s.items)) t = f$2.createArrayTypeNode(mk(s.items));
279
281
  else {
280
282
  console.warn(`makeType: unknown type "${s.type}"`);
@@ -297,6 +299,9 @@ const isStringEnum = (s) => {
297
299
  }
298
300
  return false;
299
301
  };
302
+ const isPrefixItems = (s) => {
303
+ return s.prefixItems !== void 0;
304
+ };
300
305
  const makeTypeAlias = (ctx, name, s) => {
301
306
  if (isStringEnum(s) && !ctx.inlineEnums) {
302
307
  const tokens1 = lodashEs.uniq(s.enum);
@@ -550,7 +555,7 @@ const apigen = async (config) => {
550
555
  const doc = await loadSchema({ url: config.source, headers: config.headers });
551
556
  const ctx = initCtx({ ...config, doc });
552
557
  const { modules, types } = await generateAst(ctx);
553
- const filepath = path$1.join(path$1.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('main-C0qK6dZX.cjs', document.baseURI).href)))), "_template.ts");
558
+ const filepath = path$1.join(path$1.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('main-BLaUzCCM.cjs', document.baseURI).href)))), "_template.ts");
554
559
  const file = await fs.readFile(filepath, "utf-8");
555
560
  let code = [
556
561
  `// Auto-generated by https://github.com/vladkens/apigen-ts`,
@@ -10,7 +10,7 @@ import ts from 'typescript';
10
10
  import path from 'node:path';
11
11
 
12
12
  var name = "apigen-ts";
13
- var version = "1.2.0";
13
+ var version = "1.2.1";
14
14
 
15
15
  const initCtx = (config) => {
16
16
  return {
@@ -272,6 +272,8 @@ const makeType = (ctx, s) => {
272
272
  else if (s.type === "string") t = f$2.createKeywordTypeNode(ts.SyntaxKind.StringKeyword);
273
273
  else if (s.type === "null") t = f$2.createLiteralTypeNode(f$2.createNull());
274
274
  else if (isArray(s.type)) t = makeLiteralUnion(ctx, s.type);
275
+ else if (s.type === "array" && isPrefixItems(s) && s.prefixItems && !s.items)
276
+ t = f$2.createTupleTypeNode(s.prefixItems.map(mk));
275
277
  else if (s.type === "array" && !isBoolean(s.items)) t = f$2.createArrayTypeNode(mk(s.items));
276
278
  else {
277
279
  console.warn(`makeType: unknown type "${s.type}"`);
@@ -294,6 +296,9 @@ const isStringEnum = (s) => {
294
296
  }
295
297
  return false;
296
298
  };
299
+ const isPrefixItems = (s) => {
300
+ return s.prefixItems !== void 0;
301
+ };
297
302
  const makeTypeAlias = (ctx, name, s) => {
298
303
  if (isStringEnum(s) && !ctx.inlineEnums) {
299
304
  const tokens1 = uniq(s.enum);
@@ -10,7 +10,7 @@ import ts from 'typescript';
10
10
  import path from 'node:path';
11
11
 
12
12
  var name = "apigen-ts";
13
- var version = "1.2.0";
13
+ var version = "1.2.1";
14
14
 
15
15
  const initCtx = (config) => {
16
16
  return {
@@ -272,6 +272,8 @@ const makeType = (ctx, s) => {
272
272
  else if (s.type === "string") t = f$2.createKeywordTypeNode(ts.SyntaxKind.StringKeyword);
273
273
  else if (s.type === "null") t = f$2.createLiteralTypeNode(f$2.createNull());
274
274
  else if (isArray(s.type)) t = makeLiteralUnion(ctx, s.type);
275
+ else if (s.type === "array" && isPrefixItems(s) && s.prefixItems && !s.items)
276
+ t = f$2.createTupleTypeNode(s.prefixItems.map(mk));
275
277
  else if (s.type === "array" && !isBoolean(s.items)) t = f$2.createArrayTypeNode(mk(s.items));
276
278
  else {
277
279
  console.warn(`makeType: unknown type "${s.type}"`);
@@ -294,6 +296,9 @@ const isStringEnum = (s) => {
294
296
  }
295
297
  return false;
296
298
  };
299
+ const isPrefixItems = (s) => {
300
+ return s.prefixItems !== void 0;
301
+ };
297
302
  const makeTypeAlias = (ctx, name, s) => {
298
303
  if (isStringEnum(s) && !ctx.inlineEnums) {
299
304
  const tokens1 = uniq(s.enum);
package/dist/main.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  require('fs/promises');
4
4
  require('path');
5
5
  require('url');
6
- var main = require('./main-C0qK6dZX.cjs');
6
+ var main = require('./main-BLaUzCCM.cjs');
7
7
  require('cleye');
8
8
  require('@redocly/openapi-core');
9
9
  require('array-utils-ts');
package/dist/main.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import 'fs/promises';
2
2
  import 'path';
3
3
  import 'url';
4
- export { a as apigen } from './main-l0LIDQ3K.js';
4
+ export { a as apigen } from './main-BZrWxHPM.js';
5
5
  import 'cleye';
6
6
  import '@redocly/openapi-core';
7
7
  import 'array-utils-ts';
package/dist/main.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import 'fs/promises';
2
2
  import 'path';
3
3
  import 'url';
4
- export { a as apigen } from './main-l0LIDQ3K.mjs';
4
+ export { a as apigen } from './main-BZrWxHPM.mjs';
5
5
  import 'cleye';
6
6
  import '@redocly/openapi-core';
7
7
  import 'array-utils-ts';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "apigen-ts",
4
- "version": "1.2.0",
4
+ "version": "1.2.1",
5
5
  "license": "MIT",
6
6
  "author": "vladkens <v.pronsky@gmail.com>",
7
7
  "repository": "vladkens/apigen-ts",
@@ -22,7 +22,7 @@
22
22
  "ci": "tsc --noEmit && yarn test-cov && yarn build"
23
23
  },
24
24
  "dependencies": {
25
- "@redocly/openapi-core": "1.34.1",
25
+ "@redocly/openapi-core": "1.34.3",
26
26
  "@types/lodash-es": "4.17.12",
27
27
  "@types/swagger2openapi": "7.0.4",
28
28
  "array-utils-ts": "1.0.2",
@@ -31,10 +31,10 @@
31
31
  "swagger2openapi": "7.0.8"
32
32
  },
33
33
  "devDependencies": {
34
- "@types/node": "22.14.0",
34
+ "@types/node": "22.15.18",
35
35
  "c8": "10.1.3",
36
36
  "fetch-mock": "12.5.2",
37
- "pkgroll": "2.12.1",
37
+ "pkgroll": "2.12.2",
38
38
  "prettier": "3.5.3",
39
39
  "prettier-plugin-organize-imports": "4.1.0",
40
40
  "tsm": "2.3.0",
package/readme.md CHANGED
@@ -41,16 +41,16 @@ yarn add -D apigen-ts
41
41
 
42
42
  ```sh
43
43
  # From file
44
- yarn apigen-ts ./openapi.json ./api-client.ts
44
+ npx apigen-ts ./openapi.json ./api-client.ts
45
45
 
46
46
  # From url
47
- yarn apigen-ts https://petstore3.swagger.io/api/v3/openapi.json ./api-client.ts
47
+ npx apigen-ts https://petstore3.swagger.io/api/v3/openapi.json ./api-client.ts
48
48
 
49
49
  # From protected url
50
- yarn apigen-ts https://secret-api.example.com ./api-client.ts -H "x-api-key: secret-key"
50
+ npx apigen-ts https://secret-api.example.com ./api-client.ts -H "x-api-key: secret-key"
51
51
  ```
52
52
 
53
- Run `yarn apigen-ts --help` for more options. Examples of generated clients [here](./examples/).
53
+ Run `npx apigen-ts --help` for more options. Examples of generated clients [here](./examples/).
54
54
 
55
55
  ### 2. Import
56
56
 
@@ -90,7 +90,7 @@ await api.protectedRoute.get() // here authenticated
90
90
  ### Automatic date parsing
91
91
 
92
92
  ```sh
93
- yarn apigen-ts ./openapi.json ./api-client.ts --parse-dates
93
+ npx apigen-ts ./openapi.json ./api-client.ts --parse-dates
94
94
  ```
95
95
 
96
96
  ```ts
@@ -103,7 +103,7 @@ const createdAt: Date = pet.createdAt // date parsed from string with format=dat
103
103
  You can generate string literal union instead of native enums in case you want to run in Node.js environment with [type-stripping](https://nodejs.org/api/typescript.html#type-stripping). To achive this pass `--inline-enums` command line argument or use `inlineEnums: true` in Node.js API.
104
104
 
105
105
  ```sh
106
- yarn apigen-ts ./openapi.json ./api-client.ts --inline-enums
106
+ npx apigen-ts ./openapi.json ./api-client.ts --inline-enums
107
107
  ```
108
108
 
109
109
  This will generate: