@spec2ts/openapi-client 2.0.0-beta.9 → 2.0.0

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,52 @@
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](https://github.com/touchifyapp/spec2ts/compare/@spec2ts/openapi-client@2.0.0-beta.13...@spec2ts/openapi-client@2.0.0) (2023-09-07)
7
+
8
+ **Note:** Version bump only for package @spec2ts/openapi-client
9
+
10
+
11
+
12
+
13
+
14
+ # [2.0.0-beta.13](https://github.com/touchifyapp/spec2ts/compare/@spec2ts/openapi-client@2.0.0-beta.12...@spec2ts/openapi-client@2.0.0-beta.13) (2022-09-21)
15
+
16
+ **Note:** Version bump only for package @spec2ts/openapi-client
17
+
18
+
19
+
20
+
21
+
22
+ # [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)
23
+
24
+
25
+ ### Features
26
+
27
+ * allow url & prefix override ([9139ccb](https://github.com/touchifyapp/spec2ts/commit/9139ccbb89329972e45e8d813adfd81648a01bb7))
28
+
29
+
30
+
31
+
32
+
33
+ # [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)
34
+
35
+ **Note:** Version bump only for package @spec2ts/openapi-client
36
+
37
+
38
+
39
+
40
+
41
+ # [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)
42
+
43
+
44
+ ### Bug Fixes
45
+
46
+ * **openapi-client:** upgrade to typescript 4 ([932877f](https://github.com/touchifyapp/spec2ts/commit/932877f83915a953400b41fc74ea921aeaed3b1d))
47
+
48
+
49
+
50
+
51
+
6
52
  # [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)
7
53
 
8
54
  **Note:** Version bump only for package @spec2ts/openapi-client
package/cli/command.js CHANGED
@@ -24,6 +24,14 @@ 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",
@@ -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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spec2ts/openapi-client",
3
- "version": "2.0.0-beta.9",
3
+ "version": "2.0.0",
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",
@@ -36,20 +36,20 @@
36
36
  "lint:ts": "eslint \"*.ts\" \"{bin,cli,lib}/**/*.ts\"",
37
37
  "lint:fix": "npm run lint -- -- --fix",
38
38
  "clean": "npm run clean:ts",
39
- "clean:ts": "rimraf *.{js,d.ts} {bin,cli,lib}/**/*.{js,d.ts}",
39
+ "clean:ts": "del *.{js,d.ts} {bin,cli,lib}/**/*.{js,d.ts}",
40
40
  "prepublishOnly": "npm test && npm run build"
41
41
  },
42
42
  "dependencies": {
43
- "@spec2ts/core": "^2.0.0-beta.2",
44
- "@spec2ts/jsonschema": "^2.0.0-beta.6",
45
- "@spec2ts/openapi": "^2.0.0-beta.6",
43
+ "@spec2ts/core": "^2.0.0",
44
+ "@spec2ts/jsonschema": "^2.0.0",
45
+ "@spec2ts/openapi": "^2.0.0",
46
46
  "openapi3-ts": "^1.3.0",
47
47
  "yargs": "^15.3.1"
48
48
  },
49
49
  "devDependencies": {
50
+ "del-cli": "^5.0.0",
50
51
  "eslint": "^7.11.0",
51
52
  "jest": "^26.5.3",
52
- "rimraf": "^3.0.2",
53
53
  "typescript": "^4.0.0"
54
54
  },
55
55
  "keywords": [
@@ -70,5 +70,5 @@
70
70
  "spec2ts",
71
71
  "share"
72
72
  ],
73
- "gitHead": "5717dc6d2eb06bdcebea9eff4339f5d4bd6ac140"
73
+ "gitHead": "34fe406a4701ba1b7c173d3580e85f65e2950012"
74
74
  }