@7nohe/openapi-react-query-codegen 0.1.5 → 0.2.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/README.md +14 -9
- package/dist/node_modules/.bin/openapi +17 -0
- package/dist/node_modules/.bin/tsc +17 -0
- package/dist/node_modules/.bin/tsserver +17 -0
- package/dist/package.json +1 -1
- package/dist/src/cli.js +9 -4
- package/dist/src/constants.js +6 -0
- package/dist/src/generate.js +18 -8
- package/dist/src/print.js +8 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,15 +18,20 @@ $ npm install -D @7nohe/openapi-react-query-codegen
|
|
|
18
18
|
```
|
|
19
19
|
$ openapi-rq --help
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
Usage: openapi-rq [options]
|
|
22
|
+
|
|
23
|
+
Generate React Query code based on OpenAPI
|
|
24
|
+
|
|
25
|
+
Options:
|
|
26
|
+
-V, --version output the version number
|
|
27
|
+
-i, --input <value> OpenAPI specification, can be a path, url or string content (required)
|
|
28
|
+
-o, --output <value> Output directory (default: "openapi")
|
|
29
|
+
-c, --client <value> HTTP client to generate [fetch, xhr, node, axios, angular] (default: "fetch")
|
|
30
|
+
--exportSchemas <value> Write schemas to disk (default: false)
|
|
31
|
+
--indent <value> Indentation options [4, 2, tabs] (default: "4")
|
|
32
|
+
--postfix <value> Service name postfix (default: "Service")
|
|
33
|
+
--request <value> Path to custom request file
|
|
34
|
+
-h, --help display help for command
|
|
30
35
|
```
|
|
31
36
|
|
|
32
37
|
## Example Usage
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
+
|
|
4
|
+
case `uname` in
|
|
5
|
+
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
+
esac
|
|
7
|
+
|
|
8
|
+
if [ -z "$NODE_PATH" ]; then
|
|
9
|
+
export NODE_PATH="/Users/daiki/Documents/openapi-react-query-codegen/node_modules/.pnpm/node_modules"
|
|
10
|
+
else
|
|
11
|
+
export NODE_PATH="$NODE_PATH:/Users/daiki/Documents/openapi-react-query-codegen/node_modules/.pnpm/node_modules"
|
|
12
|
+
fi
|
|
13
|
+
if [ -x "$basedir/node" ]; then
|
|
14
|
+
exec "$basedir/node" "$basedir/../../../node_modules/.pnpm/openapi-typescript-codegen@0.23.0/node_modules/openapi-typescript-codegen/bin/index.js" "$@"
|
|
15
|
+
else
|
|
16
|
+
exec node "$basedir/../../../node_modules/.pnpm/openapi-typescript-codegen@0.23.0/node_modules/openapi-typescript-codegen/bin/index.js" "$@"
|
|
17
|
+
fi
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
+
|
|
4
|
+
case `uname` in
|
|
5
|
+
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
+
esac
|
|
7
|
+
|
|
8
|
+
if [ -z "$NODE_PATH" ]; then
|
|
9
|
+
export NODE_PATH="/Users/daiki/Documents/openapi-react-query-codegen/node_modules/.pnpm/node_modules"
|
|
10
|
+
else
|
|
11
|
+
export NODE_PATH="$NODE_PATH:/Users/daiki/Documents/openapi-react-query-codegen/node_modules/.pnpm/node_modules"
|
|
12
|
+
fi
|
|
13
|
+
if [ -x "$basedir/node" ]; then
|
|
14
|
+
exec "$basedir/node" "$basedir/../../../node_modules/.pnpm/typescript@4.7.4/node_modules/typescript/bin/tsc" "$@"
|
|
15
|
+
else
|
|
16
|
+
exec node "$basedir/../../../node_modules/.pnpm/typescript@4.7.4/node_modules/typescript/bin/tsc" "$@"
|
|
17
|
+
fi
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
+
|
|
4
|
+
case `uname` in
|
|
5
|
+
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
+
esac
|
|
7
|
+
|
|
8
|
+
if [ -z "$NODE_PATH" ]; then
|
|
9
|
+
export NODE_PATH="/Users/daiki/Documents/openapi-react-query-codegen/node_modules/.pnpm/node_modules"
|
|
10
|
+
else
|
|
11
|
+
export NODE_PATH="$NODE_PATH:/Users/daiki/Documents/openapi-react-query-codegen/node_modules/.pnpm/node_modules"
|
|
12
|
+
fi
|
|
13
|
+
if [ -x "$basedir/node" ]; then
|
|
14
|
+
exec "$basedir/node" "$basedir/../../../node_modules/.pnpm/typescript@4.7.4/node_modules/typescript/bin/tsserver" "$@"
|
|
15
|
+
else
|
|
16
|
+
exec node "$basedir/../../../node_modules/.pnpm/typescript@4.7.4/node_modules/typescript/bin/tsserver" "$@"
|
|
17
|
+
fi
|
package/dist/package.json
CHANGED
package/dist/src/cli.js
CHANGED
|
@@ -9,12 +9,17 @@ var commander_1 = require("commander");
|
|
|
9
9
|
var package_json_1 = __importDefault(require("../package.json"));
|
|
10
10
|
var program = new commander_1.Command();
|
|
11
11
|
program
|
|
12
|
-
.name(
|
|
12
|
+
.name("openapi-rq")
|
|
13
13
|
.version(package_json_1["default"].version)
|
|
14
14
|
.description("Generate React Query code based on OpenAPI")
|
|
15
|
-
.requiredOption("-
|
|
16
|
-
.option("-o, --output
|
|
15
|
+
.requiredOption("-i, --input <value>", "OpenAPI specification, can be a path, url or string content (required)")
|
|
16
|
+
.option("-o, --output <value>", "Output directory", "openapi")
|
|
17
|
+
.option("-c, --client <value>", "HTTP client to generate [fetch, xhr, node, axios, angular]", "fetch")
|
|
18
|
+
.option("--exportSchemas <value>", "Write schemas to disk", false)
|
|
19
|
+
.option("--indent <value>", "Indentation options [4, 2, tabs]", "4")
|
|
20
|
+
.option("--postfix <value>", "Service name postfix", "Service")
|
|
21
|
+
.option("--request <value>", "Path to custom request file")
|
|
17
22
|
.parse();
|
|
18
23
|
var options = program.opts();
|
|
19
|
-
console.log("Generating React Query code using OpenApi file ".concat(options.
|
|
24
|
+
console.log("Generating React Query code using OpenApi file ".concat(options.output));
|
|
20
25
|
(0, generate_1.generate)(options);
|
package/dist/src/generate.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -44,19 +55,18 @@ var openapi_typescript_codegen_1 = require("openapi-typescript-codegen");
|
|
|
44
55
|
var print_1 = require("./print");
|
|
45
56
|
var path_1 = __importDefault(require("path"));
|
|
46
57
|
var createSource_1 = require("./createSource");
|
|
58
|
+
var constants_1 = require("./constants");
|
|
47
59
|
function generate(options) {
|
|
60
|
+
var _a;
|
|
48
61
|
return __awaiter(this, void 0, void 0, function () {
|
|
49
62
|
var openApiOutputPath, source;
|
|
50
|
-
return __generator(this, function (
|
|
51
|
-
switch (
|
|
63
|
+
return __generator(this, function (_b) {
|
|
64
|
+
switch (_b.label) {
|
|
52
65
|
case 0:
|
|
53
|
-
openApiOutputPath = path_1["default"].join(options.
|
|
54
|
-
return [4 /*yield*/, (0, openapi_typescript_codegen_1.generate)({
|
|
55
|
-
input: options.path,
|
|
56
|
-
output: openApiOutputPath
|
|
57
|
-
})];
|
|
66
|
+
openApiOutputPath = path_1["default"].join((_a = options.output) !== null && _a !== void 0 ? _a : constants_1.defaultOutputPath, constants_1.requestsOutputPath);
|
|
67
|
+
return [4 /*yield*/, (0, openapi_typescript_codegen_1.generate)(__assign(__assign({}, options), { httpClient: options.client, output: openApiOutputPath }))];
|
|
58
68
|
case 1:
|
|
59
|
-
|
|
69
|
+
_b.sent();
|
|
60
70
|
source = (0, createSource_1.createSource)(openApiOutputPath);
|
|
61
71
|
(0, print_1.print)(source, options);
|
|
62
72
|
return [2 /*return*/];
|
package/dist/src/print.js
CHANGED
|
@@ -6,16 +6,20 @@ exports.__esModule = true;
|
|
|
6
6
|
exports.print = void 0;
|
|
7
7
|
var fs_1 = __importDefault(require("fs"));
|
|
8
8
|
var path_1 = __importDefault(require("path"));
|
|
9
|
+
var constants_1 = require("./constants");
|
|
9
10
|
function printGeneratedTS(result, options) {
|
|
10
|
-
var
|
|
11
|
+
var _a;
|
|
12
|
+
var dir = path_1["default"].join((_a = options.output) !== null && _a !== void 0 ? _a : constants_1.defaultOutputPath, constants_1.queriesOutputPath);
|
|
11
13
|
if (!fs_1["default"].existsSync(dir)) {
|
|
12
14
|
fs_1["default"].mkdirSync(dir, { recursive: true });
|
|
13
15
|
}
|
|
14
|
-
fs_1["default"].writeFileSync(path_1["default"].join(dir,
|
|
16
|
+
fs_1["default"].writeFileSync(path_1["default"].join(dir, "index.ts"), result);
|
|
15
17
|
}
|
|
16
18
|
function print(result, options) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
var _a;
|
|
20
|
+
var outputPath = (_a = options.output) !== null && _a !== void 0 ? _a : constants_1.defaultOutputPath;
|
|
21
|
+
if (!fs_1["default"].existsSync(outputPath)) {
|
|
22
|
+
fs_1["default"].mkdirSync(outputPath);
|
|
19
23
|
}
|
|
20
24
|
printGeneratedTS(result, options);
|
|
21
25
|
}
|