@spec2ts/openapi-client 2.0.0-beta.1 → 2.0.0-beta.12

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/CHANGELOG.md CHANGED
@@ -3,6 +3,112 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [2.0.0-beta.12](https://github.com/touchifyapp/spec2ts/compare/@spec2ts/openapi-client@2.0.0-beta.11...@spec2ts/openapi-client@2.0.0-beta.12) (2022-08-23)
7
+
8
+
9
+ ### Features
10
+
11
+ * allow url & prefix override ([9139ccb](https://github.com/touchifyapp/spec2ts/commit/9139ccbb89329972e45e8d813adfd81648a01bb7))
12
+
13
+
14
+
15
+
16
+
17
+ # [2.0.0-beta.11](https://github.com/touchifyapp/spec2ts/compare/@spec2ts/openapi-client@2.0.0-beta.10...@spec2ts/openapi-client@2.0.0-beta.11) (2022-07-29)
18
+
19
+ **Note:** Version bump only for package @spec2ts/openapi-client
20
+
21
+
22
+
23
+
24
+
25
+ # [2.0.0-beta.10](https://github.com/touchifyapp/spec2ts/compare/@spec2ts/openapi-client@2.0.0-beta.9...@spec2ts/openapi-client@2.0.0-beta.10) (2022-06-27)
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * **openapi-client:** upgrade to typescript 4 ([932877f](https://github.com/touchifyapp/spec2ts/commit/932877f83915a953400b41fc74ea921aeaed3b1d))
31
+
32
+
33
+
34
+
35
+
36
+ # [2.0.0-beta.9](https://github.com/touchifyapp/spec2ts/compare/@spec2ts/openapi-client@2.0.0-beta.8...@spec2ts/openapi-client@2.0.0-beta.9) (2022-01-27)
37
+
38
+ **Note:** Version bump only for package @spec2ts/openapi-client
39
+
40
+
41
+
42
+
43
+
44
+ # [2.0.0-beta.8](https://github.com/touchifyapp/spec2ts/compare/@spec2ts/openapi-client@2.0.0-beta.7...@spec2ts/openapi-client@2.0.0-beta.8) (2021-11-03)
45
+
46
+ **Note:** Version bump only for package @spec2ts/openapi-client
47
+
48
+
49
+
50
+
51
+
52
+ # [2.0.0-beta.7](https://github.com/touchifyapp/spec2ts/compare/@spec2ts/openapi-client@2.0.0-beta.6...@spec2ts/openapi-client@2.0.0-beta.7) (2021-10-23)
53
+
54
+ **Note:** Version bump only for package @spec2ts/openapi-client
55
+
56
+
57
+
58
+
59
+
60
+ # [2.0.0-beta.6](https://github.com/touchifyapp/spec2ts/compare/@spec2ts/openapi-client@2.0.0-beta.5...@spec2ts/openapi-client@2.0.0-beta.6) (2021-02-27)
61
+
62
+ **Note:** Version bump only for package @spec2ts/openapi-client
63
+
64
+
65
+
66
+
67
+
68
+ # [2.0.0-beta.5](https://github.com/touchifyapp/spec2ts/compare/@spec2ts/openapi-client@2.0.0-beta.4...@spec2ts/openapi-client@2.0.0-beta.5) (2020-12-21)
69
+
70
+
71
+ ### Bug Fixes
72
+
73
+ * **openapi-client:** allow $ and _ in camelCase ([08c244e](https://github.com/touchifyapp/spec2ts/commit/08c244eb6e2c0a6f3ab833faa5159483ca1adda7))
74
+
75
+
76
+
77
+
78
+
79
+ # [2.0.0-beta.4](https://github.com/touchifyapp/spec2ts/compare/@spec2ts/openapi-client@2.0.0-beta.3...@spec2ts/openapi-client@2.0.0-beta.4) (2020-12-14)
80
+
81
+
82
+ ### Bug Fixes
83
+
84
+ * **openapi-client:** type issue in TS 4.1 ([09da142](https://github.com/touchifyapp/spec2ts/commit/09da1423ce16e1a8ccee81ba0ad160f5f6313a67))
85
+
86
+
87
+
88
+
89
+
90
+ # [2.0.0-beta.3](https://github.com/touchifyapp/spec2ts/compare/@spec2ts/openapi-client@2.0.0-beta.2...@spec2ts/openapi-client@2.0.0-beta.3) (2020-11-29)
91
+
92
+
93
+ ### Bug Fixes
94
+
95
+ * **openapi:** bad yargs options for enableDate ([cc799cb](https://github.com/touchifyapp/spec2ts/commit/cc799cb14600f5a5388a825932622251ed1df19c))
96
+
97
+
98
+
99
+
100
+
101
+ # [2.0.0-beta.2](https://github.com/touchifyapp/spec2ts/compare/@spec2ts/openapi-client@2.0.0-beta.1...@spec2ts/openapi-client@2.0.0-beta.2) (2020-11-29)
102
+
103
+
104
+ ### Features
105
+
106
+ * **openapi-client:** add support for new lax date style ([73ac242](https://github.com/touchifyapp/spec2ts/commit/73ac2428cf7195817cc66c41a9e18fa6e9a7abee))
107
+
108
+
109
+
110
+
111
+
6
112
  # [2.0.0-beta.1](https://github.com/touchifyapp/spec2ts/compare/@spec2ts/openapi-client@2.0.0-beta.0...@spec2ts/openapi-client@2.0.0-beta.1) (2020-11-16)
7
113
 
8
114
 
package/cli/command.js CHANGED
@@ -24,15 +24,23 @@ function builder(argv) {
24
24
  type: "string",
25
25
  alias: "c",
26
26
  describe: "Root directory for resolving $refs"
27
+ })
28
+ .option("baseUrl", {
29
+ type: "string",
30
+ describe: "Base url of the server"
31
+ })
32
+ .option("prefix", {
33
+ type: "string",
34
+ describe: "Only generate paths with this prefix"
27
35
  })
28
36
  .option("avoidAny", {
29
37
  type: "boolean",
30
38
  describe: "Avoid the `any` type and use `unknown` instead"
31
39
  })
32
- // .option("enableDate", {
33
- // type: "boolean",
34
- // describe: "Build `Date` for format `date` and `date-time`"
35
- // })
40
+ .option("enableDate", {
41
+ choices: [true, "strict", "lax"],
42
+ describe: "Build `Date` for format `date` and `date-time`"
43
+ })
36
44
  .option("inlineRequired", {
37
45
  type: "boolean",
38
46
  describe: "Create a method argument for each required parameter"
@@ -140,12 +148,12 @@ async function generatePackage(output, options) {
140
148
  main: main.replace(/\.ts$/, ".js"),
141
149
  files: ["*.js", "*.d.ts"],
142
150
  scripts: {
143
- build: `tsc ${main} --strict --target ${options.packageBuildTarget || "ES2018"} --module ${options.packageBuildModule || "UMD"} --moduleResolution node`,
151
+ build: `tsc ${main} --strict --target ${options.packageBuildTarget || "ES2018"} --module ${options.packageBuildModule || "UMD"} --moduleResolution node --skipLibCheck`,
144
152
  prepublishOnly: "npm run build"
145
153
  },
146
154
  dependencies: {},
147
155
  devDependencies: {
148
- typescript: "^3.0.0"
156
+ typescript: "^4.2.0"
149
157
  }
150
158
  };
151
159
  if (options.importFetch) {
@@ -2,6 +2,6 @@ import * as ts from "typescript";
2
2
  import type { OpenAPIObject } from "openapi3-ts";
3
3
  import { OApiGeneratorContext } from "./core-parser";
4
4
  export declare type Formatter = "space" | "pipe" | "deep" | "explode" | "form";
5
- export declare function generateServers(file: ts.SourceFile, { servers }: OpenAPIObject): ts.SourceFile;
5
+ export declare function generateServers(file: ts.SourceFile, { servers }: OpenAPIObject, context: OApiGeneratorContext): ts.SourceFile;
6
6
  export declare function generateDefaults(file: ts.SourceFile, context: OApiGeneratorContext): ts.SourceFile;
7
7
  export declare function generateFunctions(file: ts.SourceFile, spec: OpenAPIObject, context: OApiGeneratorContext): ts.SourceFile;
@@ -8,8 +8,10 @@ const server_parser_1 = require("./server-parser");
8
8
  const core_parser_2 = require("./core-parser");
9
9
  const util_1 = require("./util");
10
10
  //#region Public
11
- function generateServers(file, { servers }) {
11
+ function generateServers(file, { servers }, context) {
12
12
  servers = servers || [];
13
+ if (context.options.baseUrl)
14
+ servers = [{ url: context.options.baseUrl }];
13
15
  const serversConst = core.findFirstVariableStatement(file.statements, "servers");
14
16
  const defaultsConst = core.findFirstVariableStatement(file.statements, "defaults");
15
17
  if (!serversConst || !defaultsConst) {
@@ -41,7 +43,10 @@ function generateDefaults(file, context) {
41
43
  exports.generateDefaults = generateDefaults;
42
44
  function generateFunctions(file, spec, context) {
43
45
  const functions = [];
44
- for (const path in spec.paths) {
46
+ const paths = Object.entries(spec.paths)
47
+ .filter(([path]) => !context.options.prefix || path.startsWith(context.options.prefix))
48
+ .reduce((acc, [path, pathSpec]) => ({ ...acc, [path]: pathSpec }), {});
49
+ for (const path in paths) {
45
50
  const item = core_parser_1.resolveReference(spec.paths[path], context);
46
51
  for (const verb in item) {
47
52
  const method = verb.toUpperCase();
@@ -5,6 +5,8 @@ export interface OApiGeneratorOptions extends ParserOptions {
5
5
  inlineRequired?: boolean;
6
6
  importFetch?: "node-fetch" | "cross-fetch" | "isomorphic-fetch";
7
7
  typesPath?: string;
8
+ baseUrl?: string;
9
+ prefix?: string;
8
10
  }
9
11
  export declare function generateClientFromFile(file: string, options: OApiGeneratorOptions & {
10
12
  typesPath: string;
@@ -25,7 +25,7 @@ async function generateClient(spec, options = {}) {
25
25
  if (context.options.typesPath) {
26
26
  context.typesFile = ts.createSourceFile("types.ts", "", ts.ScriptTarget.Latest, false, ts.ScriptKind.TS);
27
27
  }
28
- file = core_generator_1.generateServers(file, spec);
28
+ file = core_generator_1.generateServers(file, spec, context);
29
29
  file = core_generator_1.generateDefaults(file, context);
30
30
  file = core_generator_1.generateFunctions(file, spec, context);
31
31
  if (context.options.typesPath) {
@@ -30,7 +30,7 @@ export declare const _: {
30
30
  encodeReserved: (typeof encodeURI)[];
31
31
  allowReserved: (typeof encodeURI)[];
32
32
  /** Deeply remove all properties with undefined values. */
33
- stripUndefined<T>(obj?: T | undefined): T | undefined;
33
+ stripUndefined<T extends Record<string, U | undefined>, U>(obj?: T | undefined): Record<string, U> | undefined;
34
34
  isEmpty(v: unknown): boolean;
35
35
  /** Creates a tag-function to encode template strings with the given encoders. */
36
36
  encode(encoders: Encoders, delimiter?: string): TagFunction;
@@ -43,7 +43,7 @@ export const _ = {
43
43
  allowReserved: [encodeURI, encodeURI],
44
44
 
45
45
  /** Deeply remove all properties with undefined values. */
46
- stripUndefined<T>(obj?: T): T | undefined {
46
+ stripUndefined<T extends Record<string, U | undefined>, U>(obj?: T): Record<string, U> | undefined {
47
47
  return obj && JSON.parse(JSON.stringify(obj));
48
48
  },
49
49
 
package/lib/util.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.camelCase = void 0;
4
4
  function camelCase(str) {
5
- const regex = /[A-Z\xC0-\xD6\xD8-\xDE]?[a-z\xDF-\xF6\xF8-\xFF]+|[A-Z\xC0-\xD6\xD8-\xDE]+(?![a-z\xDF-\xF6\xF8-\xFF])|\d+/g;
5
+ const regex = /[A-Z\xC0-\xD6\xD8-\xDE_$]?[a-z\xDF-\xF6\xF8-\xFF_$]+|[A-Z\xC0-\xD6\xD8-\xDE_$]+(?![a-z\xDF-\xF6\xF8-\xFF_$])|\d+/g;
6
6
  const words = str.match(regex);
7
7
  if (!words)
8
8
  return "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spec2ts/openapi-client",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.12",
4
4
  "description": "Utility to convert OpenAPI v3 specifications to Typescript HTTP client using TypeScript native compiler",
5
5
  "author": "Touchify <dev@touchify.co>",
6
6
  "license": "MIT",
@@ -40,9 +40,9 @@
40
40
  "prepublishOnly": "npm test && npm run build"
41
41
  },
42
42
  "dependencies": {
43
- "@spec2ts/core": "^2.0.0-beta.0",
44
- "@spec2ts/jsonschema": "^2.0.0-beta.0",
45
- "@spec2ts/openapi": "^2.0.0-beta.0",
43
+ "@spec2ts/core": "^2.0.0-beta.2",
44
+ "@spec2ts/jsonschema": "^2.0.0-beta.7",
45
+ "@spec2ts/openapi": "^2.0.0-beta.7",
46
46
  "openapi3-ts": "^1.3.0",
47
47
  "yargs": "^15.3.1"
48
48
  },
@@ -70,5 +70,5 @@
70
70
  "spec2ts",
71
71
  "share"
72
72
  ],
73
- "gitHead": "d8b36dac0efa2756b1284f8977ddf1d405633c9c"
73
+ "gitHead": "bea7fe666a107170cd32a1f006a9de5bbcc2be4c"
74
74
  }