api 7.0.0-alpha.1 → 7.0.0-alpha.3
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/bin.js +16 -62
- package/dist/codegen/index.js +2 -2
- package/dist/codegen/language.js +13 -9
- package/dist/codegen/languages/typescript/util.js +15 -20
- package/dist/codegen/languages/typescript.d.ts +3 -3
- package/dist/codegen/languages/typescript.js +324 -397
- package/dist/commands/index.js +1 -1
- package/dist/commands/install.js +155 -215
- package/dist/fetcher.d.ts +3 -3
- package/dist/fetcher.js +54 -95
- package/dist/lib/prompt.js +15 -67
- package/dist/logger.js +1 -1
- package/dist/packageInfo.d.ts +1 -1
- package/dist/packageInfo.js +1 -1
- package/dist/storage.d.ts +1 -1
- package/dist/storage.js +79 -133
- package/package.json +9 -8
- package/src/codegen/languages/typescript.ts +2 -2
- package/src/fetcher.ts +1 -1
- package/src/packageInfo.ts +1 -1
- package/src/storage.ts +1 -1
- package/tsconfig.json +2 -0
package/dist/bin.js
CHANGED
|
@@ -22,70 +22,24 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
-
function step(op) {
|
|
39
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
41
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
-
switch (op[0]) {
|
|
44
|
-
case 0: case 1: t = op; break;
|
|
45
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
-
default:
|
|
49
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
-
if (t[2]) _.ops.pop();
|
|
54
|
-
_.trys.pop(); continue;
|
|
55
|
-
}
|
|
56
|
-
op = body.call(thisArg, _);
|
|
57
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
62
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
27
|
};
|
|
64
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
* and argument parsing within this file than having each command manage that itself.
|
|
80
|
-
*/
|
|
81
|
-
Object.entries(commands_1.default).forEach(function (_a) {
|
|
82
|
-
var cmd = _a[1];
|
|
83
|
-
program.addCommand(cmd);
|
|
84
|
-
});
|
|
85
|
-
return [4 /*yield*/, program.parseAsync(process.argv)];
|
|
86
|
-
case 1:
|
|
87
|
-
_a.sent();
|
|
88
|
-
return [2 /*return*/];
|
|
89
|
-
}
|
|
29
|
+
const commander_1 = require("commander");
|
|
30
|
+
const commands_1 = __importDefault(require("./commands"));
|
|
31
|
+
const pkg = __importStar(require("./packageInfo"));
|
|
32
|
+
(async () => {
|
|
33
|
+
const program = new commander_1.Command();
|
|
34
|
+
program.name(pkg.PACKAGE_NAME);
|
|
35
|
+
program.version(pkg.PACKAGE_VERSION);
|
|
36
|
+
/**
|
|
37
|
+
* Instead of using Commander's `executableDir` API for loading in external command files we're
|
|
38
|
+
* programatically doing it like this because it's cleaner for us to let Commander manage option
|
|
39
|
+
* and argument parsing within this file than having each command manage that itself.
|
|
40
|
+
*/
|
|
41
|
+
Object.entries(commands_1.default).forEach(([, cmd]) => {
|
|
42
|
+
program.addCommand(cmd);
|
|
90
43
|
});
|
|
91
|
-
|
|
44
|
+
await program.parseAsync(process.argv);
|
|
45
|
+
})();
|
package/dist/codegen/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
6
|
+
const typescript_1 = __importDefault(require("./languages/typescript"));
|
|
7
7
|
function codegen(language, spec, specPath, identifier) {
|
|
8
8
|
switch (language) {
|
|
9
9
|
case 'js':
|
|
@@ -17,7 +17,7 @@ function codegen(language, spec, specPath, identifier) {
|
|
|
17
17
|
compilerTarget: language === 'js-cjs' ? 'cjs' : 'esm',
|
|
18
18
|
});
|
|
19
19
|
default:
|
|
20
|
-
throw new TypeError(
|
|
20
|
+
throw new TypeError(`Unsupported language supplied: ${language}`);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
exports.default = codegen;
|
package/dist/codegen/language.js
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const packageInfo_1 = require("../packageInfo");
|
|
4
|
+
class CodeGeneratorLanguage {
|
|
5
|
+
spec;
|
|
6
|
+
specPath;
|
|
7
|
+
identifier;
|
|
8
|
+
userAgent;
|
|
9
|
+
requiredPackages;
|
|
10
|
+
constructor(spec, specPath, identifier) {
|
|
6
11
|
this.spec = spec;
|
|
7
12
|
this.specPath = specPath;
|
|
8
13
|
this.identifier = identifier;
|
|
9
14
|
// User agents should be contextual to the spec in question and the version of `api` that was
|
|
10
15
|
// used to generate the SDK. For example, this'll look like `petstore/1.0.0 (api/4.2.0)` for
|
|
11
16
|
// a `petstore` spec installed on api@4.2.0.
|
|
12
|
-
|
|
13
|
-
this.userAgent =
|
|
17
|
+
const info = spec.getDefinition().info;
|
|
18
|
+
this.userAgent = `${identifier}/${info.version} (${packageInfo_1.PACKAGE_NAME}/${packageInfo_1.PACKAGE_VERSION})`;
|
|
14
19
|
/**
|
|
15
20
|
* This check is barbaric but there are a number of issues with how the `transformer` work we
|
|
16
21
|
* have in `oas` and in `.getParametersAsJSONSchema()` and `.getResponseAsJSONSchema()` that
|
|
@@ -25,9 +30,8 @@ var CodeGeneratorLanguage = /** @class */ (function () {
|
|
|
25
30
|
throw new Error('Sorry, this library does not yet support generating an SDK for an OpenAPI definition that contains circular references.');
|
|
26
31
|
}
|
|
27
32
|
}
|
|
28
|
-
|
|
33
|
+
hasRequiredPackages() {
|
|
29
34
|
return Boolean(Object.keys(this.requiredPackages));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
}());
|
|
35
|
+
}
|
|
36
|
+
}
|
|
33
37
|
exports.default = CodeGeneratorLanguage;
|
|
@@ -4,16 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.generateTypeName = exports.docblockEscape = exports.wordWrap = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const lodash_camelcase_1 = __importDefault(require("lodash.camelcase"));
|
|
8
|
+
const lodash_deburr_1 = __importDefault(require("lodash.deburr"));
|
|
9
|
+
const lodash_startcase_1 = __importDefault(require("lodash.startcase"));
|
|
10
10
|
/**
|
|
11
11
|
* This is a mix of reserved JS words and keywords in TypeScript that might be reserved or
|
|
12
12
|
* allowable but functionally confusing (like `let any = 'buster';`)
|
|
13
13
|
*
|
|
14
14
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar}
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
const RESERVED_WORDS = [
|
|
17
17
|
'abstract',
|
|
18
18
|
'any',
|
|
19
19
|
'arguments',
|
|
@@ -105,9 +105,8 @@ var RESERVED_WORDS = [
|
|
|
105
105
|
/**
|
|
106
106
|
* @see {@link https://www.30secondsofcode.org/js/s/word-wrap}
|
|
107
107
|
*/
|
|
108
|
-
function wordWrap(str, max) {
|
|
109
|
-
|
|
110
|
-
return str.replace(new RegExp("(?![^\\n]{1,".concat(max, "}$)([^\\n]{1,").concat(max, "})\\s"), 'g'), '$1\n');
|
|
108
|
+
function wordWrap(str, max = 88) {
|
|
109
|
+
return str.replace(new RegExp(`(?![^\\n]{1,${max}}$)([^\\n]{1,${max}})\\s`, 'g'), '$1\n');
|
|
111
110
|
}
|
|
112
111
|
exports.wordWrap = wordWrap;
|
|
113
112
|
/**
|
|
@@ -139,36 +138,32 @@ function toSafeString(str) {
|
|
|
139
138
|
// replace chars which are not valid for typescript identifiers with whitespace
|
|
140
139
|
.replace(/(^\s*[^a-zA-Z_$])|([^a-zA-Z_$\d])/g, ' ')
|
|
141
140
|
// uppercase leading underscores followed by lowercase
|
|
142
|
-
.replace(/^_[a-z]/g,
|
|
141
|
+
.replace(/^_[a-z]/g, (match) => match.toUpperCase())
|
|
143
142
|
// remove non-leading underscores followed by lowercase (convert snake_case)
|
|
144
|
-
.replace(/_[a-z]/g,
|
|
143
|
+
.replace(/_[a-z]/g, (match) => match.substr(1, match.length).toUpperCase())
|
|
145
144
|
// uppercase letters after digits, dollars
|
|
146
|
-
.replace(/([\d$]+[a-zA-Z])/g,
|
|
145
|
+
.replace(/([\d$]+[a-zA-Z])/g, (match) => match.toUpperCase())
|
|
147
146
|
// uppercase first letter after whitespace
|
|
148
|
-
.replace(/\s+([a-zA-Z])/g,
|
|
147
|
+
.replace(/\s+([a-zA-Z])/g, (match) => match.toUpperCase().trim())
|
|
149
148
|
// remove remaining whitespace
|
|
150
149
|
.replace(/\s/g, ''));
|
|
151
150
|
}
|
|
152
|
-
function generateTypeName() {
|
|
153
|
-
|
|
154
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
155
|
-
parts[_i] = arguments[_i];
|
|
156
|
-
}
|
|
157
|
-
var str;
|
|
151
|
+
function generateTypeName(...parts) {
|
|
152
|
+
let str;
|
|
158
153
|
// If the end of our string ends with something like `2XX`, the combination of `startCase` and
|
|
159
154
|
// `camelCase` will transform it into `2Xx`.
|
|
160
155
|
if (parts.length > 1) {
|
|
161
|
-
|
|
156
|
+
const last = parts[parts.length - 1];
|
|
162
157
|
if (last.match(/^(\d)XX$/)) {
|
|
163
158
|
str = (0, lodash_startcase_1.default)((0, lodash_camelcase_1.default)(parts.slice(0, -1).join(' ')));
|
|
164
|
-
str +=
|
|
159
|
+
str += ` ${last}`;
|
|
165
160
|
}
|
|
166
161
|
}
|
|
167
162
|
if (!str) {
|
|
168
163
|
str = (0, lodash_startcase_1.default)((0, lodash_camelcase_1.default)(parts.join(' ')));
|
|
169
164
|
}
|
|
170
165
|
if (RESERVED_WORDS.includes(str.toLowerCase())) {
|
|
171
|
-
str =
|
|
166
|
+
str = `$${str}`;
|
|
172
167
|
}
|
|
173
168
|
return toSafeString(str);
|
|
174
169
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type Storage from '../../storage';
|
|
2
2
|
import type { InstallerOptions } from '../language';
|
|
3
3
|
import type Oas from 'oas';
|
|
4
|
-
import type
|
|
5
|
-
import type { HttpMethods, SchemaObject } from 'oas/
|
|
4
|
+
import type Operation from 'oas/operation';
|
|
5
|
+
import type { HttpMethods, SchemaObject } from 'oas/rmoas.types';
|
|
6
6
|
import type { ClassDeclaration, JSDocStructure, JSDocTagStructure, OptionalKind } from 'ts-morph';
|
|
7
7
|
import { Project } from 'ts-morph';
|
|
8
8
|
import CodeGeneratorLanguage from '../language';
|
|
@@ -91,7 +91,7 @@ export default class TSGenerator extends CodeGeneratorLanguage {
|
|
|
91
91
|
* usable TypeScript types.
|
|
92
92
|
*
|
|
93
93
|
*/
|
|
94
|
-
prepareParameterTypesForOperation(operation: Operation, operationId: string): false | Record<"
|
|
94
|
+
prepareParameterTypesForOperation(operation: Operation, operationId: string): false | Record<"body" | "formData" | "metadata", string>;
|
|
95
95
|
/**
|
|
96
96
|
* Compile the response schemas for an API operation into usable TypeScript types.
|
|
97
97
|
*
|