api 6.1.1 → 7.0.0-alpha.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/LICENSE +1 -1
- package/README.md +0 -12
- package/package.json +14 -32
- package/src/bin.ts +1 -1
- package/src/{cli/codegen → codegen}/language.ts +3 -2
- package/src/{cli/codegen → codegen}/languages/typescript/util.ts +1 -1
- package/src/{cli/codegen → codegen}/languages/typescript.ts +31 -32
- package/src/{cli/commands → commands}/install.ts +1 -1
- package/src/fetcher.ts +4 -5
- package/src/packageInfo.ts +1 -1
- package/src/{cli/storage.ts → storage.ts} +13 -9
- package/tsconfig.json +3 -13
- package/dist/bin.d.ts +0 -1
- package/dist/bin.js +0 -91
- package/dist/cache.d.ts +0 -68
- package/dist/cache.js +0 -198
- package/dist/cli/codegen/index.d.ts +0 -4
- package/dist/cli/codegen/index.js +0 -23
- package/dist/cli/codegen/language.d.ts +0 -27
- package/dist/cli/codegen/language.js +0 -32
- package/dist/cli/codegen/languages/typescript/util.d.ts +0 -20
- package/dist/cli/codegen/languages/typescript/util.js +0 -176
- package/dist/cli/codegen/languages/typescript.d.ts +0 -111
- package/dist/cli/codegen/languages/typescript.js +0 -821
- package/dist/cli/commands/index.d.ts +0 -4
- package/dist/cli/commands/index.js +0 -9
- package/dist/cli/commands/install.d.ts +0 -3
- package/dist/cli/commands/install.js +0 -236
- package/dist/cli/lib/prompt.d.ts +0 -9
- package/dist/cli/lib/prompt.js +0 -81
- package/dist/cli/logger.d.ts +0 -1
- package/dist/cli/logger.js +0 -16
- package/dist/cli/storage.d.ts +0 -105
- package/dist/cli/storage.js +0 -277
- package/dist/core/errors/fetchError.d.ts +0 -12
- package/dist/core/errors/fetchError.js +0 -36
- package/dist/core/getJSONSchemaDefaults.d.ts +0 -14
- package/dist/core/getJSONSchemaDefaults.js +0 -61
- package/dist/core/index.d.ts +0 -40
- package/dist/core/index.js +0 -168
- package/dist/core/parseResponse.d.ts +0 -6
- package/dist/core/parseResponse.js +0 -71
- package/dist/core/prepareAuth.d.ts +0 -5
- package/dist/core/prepareAuth.js +0 -84
- package/dist/core/prepareParams.d.ts +0 -21
- package/dist/core/prepareParams.js +0 -425
- package/dist/core/prepareServer.d.ts +0 -10
- package/dist/core/prepareServer.js +0 -47
- package/dist/fetcher.d.ts +0 -54
- package/dist/fetcher.js +0 -164
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -259
- package/dist/packageInfo.d.ts +0 -2
- package/dist/packageInfo.js +0 -6
- package/src/.sink.d.ts +0 -1
- package/src/cache.ts +0 -193
- package/src/core/errors/fetchError.ts +0 -31
- package/src/core/getJSONSchemaDefaults.ts +0 -74
- package/src/core/index.ts +0 -148
- package/src/core/parseResponse.ts +0 -26
- package/src/core/prepareAuth.ts +0 -109
- package/src/core/prepareParams.ts +0 -415
- package/src/core/prepareServer.ts +0 -48
- package/src/index.ts +0 -203
- package/src/typings.d.ts +0 -2
- /package/src/{cli/codegen → codegen}/index.ts +0 -0
- /package/src/{cli/commands → commands}/index.ts +0 -0
- /package/src/{cli/lib → lib}/prompt.ts +0 -0
- /package/src/{cli/logger.ts → logger.ts} +0 -0
package/dist/cache.d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import type { OASDocument } from 'oas/dist/rmoas.types';
|
|
2
|
-
import 'isomorphic-fetch';
|
|
3
|
-
import Fetcher from './fetcher';
|
|
4
|
-
type CacheStore = Record<string, {
|
|
5
|
-
hash: string;
|
|
6
|
-
original: string | OASDocument;
|
|
7
|
-
/**
|
|
8
|
-
* @deprecated Deprecated in v4.5.0 in favor of `hash`.
|
|
9
|
-
*/
|
|
10
|
-
path?: string;
|
|
11
|
-
title?: string;
|
|
12
|
-
version?: string;
|
|
13
|
-
}>;
|
|
14
|
-
export default class Cache {
|
|
15
|
-
static dir: string;
|
|
16
|
-
static cacheStore: string;
|
|
17
|
-
static specsCache: string;
|
|
18
|
-
uri: string | OASDocument;
|
|
19
|
-
uriHash: string;
|
|
20
|
-
cached: false | CacheStore;
|
|
21
|
-
fetcher: Fetcher;
|
|
22
|
-
constructor(uri: string | OASDocument, cacheDir?: string | false);
|
|
23
|
-
static getCacheHash(file: string | OASDocument): string;
|
|
24
|
-
static setCacheDir(dir?: string | false): void;
|
|
25
|
-
static reset(): Promise<void>;
|
|
26
|
-
isCached(): boolean;
|
|
27
|
-
getCache(): CacheStore;
|
|
28
|
-
get(): any;
|
|
29
|
-
load(): Promise<import("openapi-types").OpenAPIV3.Document<{}> | (Omit<Omit<import("openapi-types").OpenAPIV3.Document<{}>, "paths" | "components">, "paths" | "components" | "info" | "servers" | "webhooks" | "jsonSchemaDialect"> & {
|
|
30
|
-
info: import("openapi-types").OpenAPIV3_1.InfoObject;
|
|
31
|
-
jsonSchemaDialect?: string;
|
|
32
|
-
servers?: import("openapi-types").OpenAPIV3_1.ServerObject[];
|
|
33
|
-
} & Pick<{
|
|
34
|
-
paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
|
|
35
|
-
webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
|
|
36
|
-
components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
|
|
37
|
-
}, "paths"> & Omit<Partial<{
|
|
38
|
-
paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
|
|
39
|
-
webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
|
|
40
|
-
components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
|
|
41
|
-
}>, "paths">) | (Omit<Omit<import("openapi-types").OpenAPIV3.Document<{}>, "paths" | "components">, "paths" | "components" | "info" | "servers" | "webhooks" | "jsonSchemaDialect"> & {
|
|
42
|
-
info: import("openapi-types").OpenAPIV3_1.InfoObject;
|
|
43
|
-
jsonSchemaDialect?: string;
|
|
44
|
-
servers?: import("openapi-types").OpenAPIV3_1.ServerObject[];
|
|
45
|
-
} & Pick<{
|
|
46
|
-
paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
|
|
47
|
-
webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
|
|
48
|
-
components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
|
|
49
|
-
}, "webhooks"> & Omit<Partial<{
|
|
50
|
-
paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
|
|
51
|
-
webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
|
|
52
|
-
components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
|
|
53
|
-
}>, "webhooks">) | (Omit<Omit<import("openapi-types").OpenAPIV3.Document<{}>, "paths" | "components">, "paths" | "components" | "info" | "servers" | "webhooks" | "jsonSchemaDialect"> & {
|
|
54
|
-
info: import("openapi-types").OpenAPIV3_1.InfoObject;
|
|
55
|
-
jsonSchemaDialect?: string;
|
|
56
|
-
servers?: import("openapi-types").OpenAPIV3_1.ServerObject[];
|
|
57
|
-
} & Pick<{
|
|
58
|
-
paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
|
|
59
|
-
webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
|
|
60
|
-
components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
|
|
61
|
-
}, "components"> & Omit<Partial<{
|
|
62
|
-
paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
|
|
63
|
-
webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
|
|
64
|
-
components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
|
|
65
|
-
}>, "components">) | import("openapi-types").OpenAPIV2.Document<{}>>;
|
|
66
|
-
save(spec: OASDocument): OASDocument;
|
|
67
|
-
}
|
|
68
|
-
export {};
|
package/dist/cache.js
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
exports.__esModule = true;
|
|
42
|
-
var crypto_1 = __importDefault(require("crypto"));
|
|
43
|
-
var fs_1 = __importDefault(require("fs"));
|
|
44
|
-
var os_1 = __importDefault(require("os"));
|
|
45
|
-
var path_1 = __importDefault(require("path"));
|
|
46
|
-
var find_cache_dir_1 = __importDefault(require("find-cache-dir"));
|
|
47
|
-
require("isomorphic-fetch");
|
|
48
|
-
var make_dir_1 = __importDefault(require("make-dir"));
|
|
49
|
-
var fetcher_1 = __importDefault(require("./fetcher"));
|
|
50
|
-
var packageInfo_1 = require("./packageInfo");
|
|
51
|
-
var Cache = /** @class */ (function () {
|
|
52
|
-
function Cache(uri, cacheDir) {
|
|
53
|
-
if (cacheDir === void 0) { cacheDir = false; }
|
|
54
|
-
Cache.setCacheDir(cacheDir);
|
|
55
|
-
Cache.cacheStore = path_1["default"].join(Cache.dir, 'cache.json');
|
|
56
|
-
Cache.specsCache = path_1["default"].join(Cache.dir, 'specs');
|
|
57
|
-
this.fetcher = new fetcher_1["default"](uri);
|
|
58
|
-
this.uri = this.fetcher.uri;
|
|
59
|
-
this.uriHash = Cache.getCacheHash(this.uri);
|
|
60
|
-
// This should default to false so we have awareness if we've looked at the cache yet.
|
|
61
|
-
this.cached = false;
|
|
62
|
-
}
|
|
63
|
-
Cache.getCacheHash = function (file) {
|
|
64
|
-
var data;
|
|
65
|
-
if (typeof file === 'object') {
|
|
66
|
-
// Under certain unit testing circumstances, we might be supplying the class with a raw JSON
|
|
67
|
-
// object so we'll need to convert it to a string in order to hand it off to the crypto
|
|
68
|
-
// module.
|
|
69
|
-
data = JSON.stringify(file);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
data = file;
|
|
73
|
-
}
|
|
74
|
-
return crypto_1["default"].createHash('md5').update(data).digest('hex');
|
|
75
|
-
};
|
|
76
|
-
Cache.setCacheDir = function (dir) {
|
|
77
|
-
if (dir) {
|
|
78
|
-
Cache.dir = dir;
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
else if (Cache.dir) {
|
|
82
|
-
// If we already have a cache dir set and aren't explicitly it to something new then we
|
|
83
|
-
// shouldn't overwrite what we've already got.
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
Cache.dir = (0, find_cache_dir_1["default"])({ name: packageInfo_1.PACKAGE_NAME });
|
|
87
|
-
if (typeof Cache.dir === 'undefined') {
|
|
88
|
-
// The `find-cache-dir` module returns `undefined` if the `node_modules/` directory isn't
|
|
89
|
-
// writable, or there's no `package.json` in the root-most directory. If this happens, we can
|
|
90
|
-
// instead adhoc create a cache directory in the users OS temp directory and store our data
|
|
91
|
-
// there.
|
|
92
|
-
//
|
|
93
|
-
// @link https://github.com/avajs/find-cache-dir/issues/29
|
|
94
|
-
Cache.dir = make_dir_1["default"].sync(path_1["default"].join(os_1["default"].tmpdir(), packageInfo_1.PACKAGE_NAME));
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
Cache.reset = function () {
|
|
98
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
99
|
-
return __generator(this, function (_a) {
|
|
100
|
-
switch (_a.label) {
|
|
101
|
-
case 0:
|
|
102
|
-
if (!Cache.cacheStore) return [3 /*break*/, 2];
|
|
103
|
-
return [4 /*yield*/, fs_1["default"].promises.rm(Cache.cacheStore)["catch"](function () {
|
|
104
|
-
// no-op
|
|
105
|
-
})];
|
|
106
|
-
case 1:
|
|
107
|
-
_a.sent();
|
|
108
|
-
_a.label = 2;
|
|
109
|
-
case 2:
|
|
110
|
-
if (!Cache.specsCache) return [3 /*break*/, 4];
|
|
111
|
-
return [4 /*yield*/, fs_1["default"].promises.rm(Cache.specsCache, { recursive: true })["catch"](function () {
|
|
112
|
-
// no-op
|
|
113
|
-
})];
|
|
114
|
-
case 3:
|
|
115
|
-
_a.sent();
|
|
116
|
-
_a.label = 4;
|
|
117
|
-
case 4: return [2 /*return*/];
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
Cache.prototype.isCached = function () {
|
|
123
|
-
var cache = this.getCache();
|
|
124
|
-
return cache && this.uriHash in cache;
|
|
125
|
-
};
|
|
126
|
-
Cache.prototype.getCache = function () {
|
|
127
|
-
if (typeof this.cached === 'object') {
|
|
128
|
-
return this.cached;
|
|
129
|
-
}
|
|
130
|
-
this.cached = {};
|
|
131
|
-
if (fs_1["default"].existsSync(Cache.cacheStore)) {
|
|
132
|
-
this.cached = JSON.parse(fs_1["default"].readFileSync(Cache.cacheStore, 'utf8'));
|
|
133
|
-
}
|
|
134
|
-
return this.cached;
|
|
135
|
-
};
|
|
136
|
-
Cache.prototype.get = function () {
|
|
137
|
-
// If the class was supplied a raw object, just go ahead and bypass the caching system and
|
|
138
|
-
// return that.
|
|
139
|
-
if (typeof this.uri === 'object') {
|
|
140
|
-
return this.uri;
|
|
141
|
-
}
|
|
142
|
-
if (!this.isCached()) {
|
|
143
|
-
throw new Error("".concat(this.uri, " has not been cached yet and must do so before being retrieved."));
|
|
144
|
-
}
|
|
145
|
-
var cache = this.getCache();
|
|
146
|
-
// Prior to v4.5.0 we were putting a fully resolved path to the API definition in the cache
|
|
147
|
-
// store but if you had specified a custom caching directory and would generate the cache on
|
|
148
|
-
// your system, that filepath would obviously not be the same in other environments. For this
|
|
149
|
-
// reason the `path` was removed from the cache store in favor of storing the `hash` instead.
|
|
150
|
-
//
|
|
151
|
-
// If we still have `path` in the config cache for backwards compatibility we should use it.
|
|
152
|
-
if ('path' in cache[this.uriHash]) {
|
|
153
|
-
return JSON.parse(fs_1["default"].readFileSync(cache[this.uriHash].path, 'utf8'));
|
|
154
|
-
}
|
|
155
|
-
return JSON.parse(fs_1["default"].readFileSync(path_1["default"].join(Cache.specsCache, "".concat(cache[this.uriHash].hash, ".json")), 'utf8'));
|
|
156
|
-
};
|
|
157
|
-
Cache.prototype.load = function () {
|
|
158
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
159
|
-
var _this = this;
|
|
160
|
-
return __generator(this, function (_a) {
|
|
161
|
-
// If the class was supplied a raw object we should still validate and make sure that it's
|
|
162
|
-
// dereferenced in order for everything to function, but we shouldn't worry about saving it
|
|
163
|
-
// into the cache directory architecture.
|
|
164
|
-
if (typeof this.uri === 'object') {
|
|
165
|
-
return [2 /*return*/, fetcher_1["default"].validate(this.uri)];
|
|
166
|
-
}
|
|
167
|
-
return [2 /*return*/, this.fetcher.load().then(function (spec) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
168
|
-
return [2 /*return*/, this.save(spec)];
|
|
169
|
-
}); }); })];
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
};
|
|
173
|
-
Cache.prototype.save = function (spec) {
|
|
174
|
-
if (!fs_1["default"].existsSync(Cache.dir)) {
|
|
175
|
-
fs_1["default"].mkdirSync(Cache.dir, { recursive: true });
|
|
176
|
-
}
|
|
177
|
-
if (!fs_1["default"].existsSync(Cache.specsCache)) {
|
|
178
|
-
fs_1["default"].mkdirSync(Cache.specsCache, { recursive: true });
|
|
179
|
-
}
|
|
180
|
-
var cache = this.getCache();
|
|
181
|
-
if (!(this.uriHash in cache)) {
|
|
182
|
-
var saved = JSON.stringify(spec, null, 2);
|
|
183
|
-
var fileHash = crypto_1["default"].createHash('md5').update(saved).digest('hex');
|
|
184
|
-
cache[this.uriHash] = {
|
|
185
|
-
hash: fileHash,
|
|
186
|
-
original: this.uri,
|
|
187
|
-
title: 'title' in spec.info ? spec.info.title : undefined,
|
|
188
|
-
version: 'version' in spec.info ? spec.info.version : undefined
|
|
189
|
-
};
|
|
190
|
-
fs_1["default"].writeFileSync(path_1["default"].join(Cache.specsCache, "".concat(fileHash, ".json")), saved);
|
|
191
|
-
fs_1["default"].writeFileSync(Cache.cacheStore, JSON.stringify(cache, null, 2));
|
|
192
|
-
this.cached = cache;
|
|
193
|
-
}
|
|
194
|
-
return spec;
|
|
195
|
-
};
|
|
196
|
-
return Cache;
|
|
197
|
-
}());
|
|
198
|
-
exports["default"] = Cache;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type CodeGeneratorLanguage from './language';
|
|
2
|
-
import type Oas from 'oas';
|
|
3
|
-
export type SupportedLanguages = 'js' | 'js-cjs' | 'js-esm' | 'ts';
|
|
4
|
-
export default function codegen(language: SupportedLanguages, spec: Oas, specPath: string, identifier: string): CodeGeneratorLanguage;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
exports.__esModule = true;
|
|
6
|
-
var typescript_1 = __importDefault(require("./languages/typescript"));
|
|
7
|
-
function codegen(language, spec, specPath, identifier) {
|
|
8
|
-
switch (language) {
|
|
9
|
-
case 'js':
|
|
10
|
-
throw new TypeError('An export format of CommonJS or ECMAScript is required for JavaScript compilation.');
|
|
11
|
-
case 'js-cjs':
|
|
12
|
-
case 'js-esm':
|
|
13
|
-
case 'ts':
|
|
14
|
-
return new typescript_1["default"](spec, specPath, identifier, {
|
|
15
|
-
outputJS: ['js-cjs', 'js-esm'].includes(language),
|
|
16
|
-
// TS will always generate with ESM-like exports.
|
|
17
|
-
compilerTarget: language === 'js-cjs' ? 'cjs' : 'esm'
|
|
18
|
-
});
|
|
19
|
-
default:
|
|
20
|
-
throw new TypeError("Unsupported language supplied: ".concat(language));
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports["default"] = codegen;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type Storage from '../storage';
|
|
2
|
-
import type Oas from 'oas';
|
|
3
|
-
export interface InstallerOptions {
|
|
4
|
-
/**
|
|
5
|
-
* Will initiate a dry run install process. Used for simulating installations within a unit test.
|
|
6
|
-
*/
|
|
7
|
-
dryRun?: boolean;
|
|
8
|
-
/**
|
|
9
|
-
* Used for stubbing out the logger that we use within the installation process so it can be
|
|
10
|
-
* easily introspected without having to mock out `console.*`.
|
|
11
|
-
*/
|
|
12
|
-
logger?: (msg: string) => void;
|
|
13
|
-
}
|
|
14
|
-
export default abstract class CodeGeneratorLanguage {
|
|
15
|
-
spec: Oas;
|
|
16
|
-
specPath: string;
|
|
17
|
-
identifier: string;
|
|
18
|
-
userAgent: string;
|
|
19
|
-
requiredPackages: Record<string, {
|
|
20
|
-
reason: string;
|
|
21
|
-
url: string;
|
|
22
|
-
}>;
|
|
23
|
-
constructor(spec: Oas, specPath: string, identifier: string);
|
|
24
|
-
abstract generator(): Promise<Record<string, string>>;
|
|
25
|
-
abstract installer(storage: Storage, opts?: InstallerOptions): Promise<void>;
|
|
26
|
-
hasRequiredPackages(): boolean;
|
|
27
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
exports.__esModule = true;
|
|
3
|
-
var packageInfo_1 = require("../../packageInfo");
|
|
4
|
-
var CodeGeneratorLanguage = /** @class */ (function () {
|
|
5
|
-
function CodeGeneratorLanguage(spec, specPath, identifier) {
|
|
6
|
-
this.spec = spec;
|
|
7
|
-
this.specPath = specPath;
|
|
8
|
-
// User agents should be contextual to the spec in question and the version of `api` that was
|
|
9
|
-
// used to generate the SDK. For example, this'll look like `petstore/1.0.0 (api/4.2.0)` for
|
|
10
|
-
// a `petstore` spec installed on api@4.2.0.
|
|
11
|
-
var info = spec.getDefinition().info;
|
|
12
|
-
this.userAgent = "".concat(identifier, "/").concat(info.version, " (").concat(packageInfo_1.PACKAGE_NAME, "/").concat(packageInfo_1.PACKAGE_VERSION, ")");
|
|
13
|
-
/**
|
|
14
|
-
* This check is barbaric but there are a number of issues with how the `transformer` work we
|
|
15
|
-
* have in `oas` and in `.getParametersAsJSONSchema()` and `.getResponseAsJSONSchema()` that
|
|
16
|
-
* are fully crashing when attempting to codegen an SDK for an API definition that has a
|
|
17
|
-
* circular reference.
|
|
18
|
-
*
|
|
19
|
-
* In order to get v5 out the door we're not going to support this case initialy.
|
|
20
|
-
*
|
|
21
|
-
* @see {@link https://github.com/readmeio/api/issues/549}
|
|
22
|
-
*/
|
|
23
|
-
if (JSON.stringify(spec.api).includes('"$ref":"#/')) {
|
|
24
|
-
throw new Error('Sorry, this library does not yet support generating an SDK for an OpenAPI definition that contains circular references.');
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
CodeGeneratorLanguage.prototype.hasRequiredPackages = function () {
|
|
28
|
-
return Boolean(Object.keys(this.requiredPackages));
|
|
29
|
-
};
|
|
30
|
-
return CodeGeneratorLanguage;
|
|
31
|
-
}());
|
|
32
|
-
exports["default"] = CodeGeneratorLanguage;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @see {@link https://www.30secondsofcode.org/js/s/word-wrap}
|
|
3
|
-
*/
|
|
4
|
-
export declare function wordWrap(str: string, max?: number): string;
|
|
5
|
-
/**
|
|
6
|
-
* Safely escape some string characters that may break a docblock.
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
export declare function docblockEscape(str: string): string;
|
|
10
|
-
/**
|
|
11
|
-
* Convert a string that might contain spaces or special characters to one that can safely be used
|
|
12
|
-
* as a TypeScript interface or enum name.
|
|
13
|
-
*
|
|
14
|
-
* This function has been adapted and slighty modified from `json-schema-to-typescript`.
|
|
15
|
-
*
|
|
16
|
-
* @license MIT
|
|
17
|
-
* @see {@link https://github.com/bcherny/json-schema-to-typescript}
|
|
18
|
-
*/
|
|
19
|
-
export declare function toSafeString(str: string): string;
|
|
20
|
-
export declare function generateTypeName(...parts: string[]): string;
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
exports.__esModule = true;
|
|
6
|
-
exports.generateTypeName = exports.toSafeString = exports.docblockEscape = exports.wordWrap = void 0;
|
|
7
|
-
var lodash_camelcase_1 = __importDefault(require("lodash.camelcase"));
|
|
8
|
-
var lodash_deburr_1 = __importDefault(require("lodash.deburr"));
|
|
9
|
-
var lodash_startcase_1 = __importDefault(require("lodash.startcase"));
|
|
10
|
-
/**
|
|
11
|
-
* This is a mix of reserved JS words and keywords in TypeScript that might be reserved or
|
|
12
|
-
* allowable but functionally confusing (like `let any = 'buster';`)
|
|
13
|
-
*
|
|
14
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar}
|
|
15
|
-
*/
|
|
16
|
-
var RESERVED_WORDS = [
|
|
17
|
-
'abstract',
|
|
18
|
-
'any',
|
|
19
|
-
'arguments',
|
|
20
|
-
'as',
|
|
21
|
-
'async',
|
|
22
|
-
'await',
|
|
23
|
-
'boolean',
|
|
24
|
-
'break',
|
|
25
|
-
'byte',
|
|
26
|
-
'case',
|
|
27
|
-
'catch',
|
|
28
|
-
'char',
|
|
29
|
-
'class',
|
|
30
|
-
'const',
|
|
31
|
-
'continue',
|
|
32
|
-
'constructor',
|
|
33
|
-
'debugger',
|
|
34
|
-
'default',
|
|
35
|
-
'delete',
|
|
36
|
-
'do',
|
|
37
|
-
'double',
|
|
38
|
-
'else',
|
|
39
|
-
'enum',
|
|
40
|
-
'eval',
|
|
41
|
-
'export',
|
|
42
|
-
'extends',
|
|
43
|
-
'false',
|
|
44
|
-
'final',
|
|
45
|
-
'finally',
|
|
46
|
-
'float',
|
|
47
|
-
'for',
|
|
48
|
-
'from',
|
|
49
|
-
'function',
|
|
50
|
-
'get',
|
|
51
|
-
'goto',
|
|
52
|
-
'if',
|
|
53
|
-
'implements',
|
|
54
|
-
'import',
|
|
55
|
-
'interface',
|
|
56
|
-
'in',
|
|
57
|
-
'instanceof',
|
|
58
|
-
'int',
|
|
59
|
-
'let',
|
|
60
|
-
'long',
|
|
61
|
-
'native',
|
|
62
|
-
'new',
|
|
63
|
-
'null',
|
|
64
|
-
'number',
|
|
65
|
-
'of',
|
|
66
|
-
'package',
|
|
67
|
-
'private',
|
|
68
|
-
'protected',
|
|
69
|
-
'public',
|
|
70
|
-
'module',
|
|
71
|
-
'namespace',
|
|
72
|
-
'return',
|
|
73
|
-
'set',
|
|
74
|
-
'short',
|
|
75
|
-
'static',
|
|
76
|
-
'string',
|
|
77
|
-
'super',
|
|
78
|
-
'switch',
|
|
79
|
-
'synchronized',
|
|
80
|
-
'this',
|
|
81
|
-
'throw',
|
|
82
|
-
'throws',
|
|
83
|
-
'transient',
|
|
84
|
-
'true',
|
|
85
|
-
'try',
|
|
86
|
-
'type',
|
|
87
|
-
'typeof',
|
|
88
|
-
'var',
|
|
89
|
-
'void',
|
|
90
|
-
'while',
|
|
91
|
-
'with',
|
|
92
|
-
'volatile',
|
|
93
|
-
'yield',
|
|
94
|
-
// These aren't reserved keywords but because we maybe codegen'ing an SDK to be used in the
|
|
95
|
-
// browser it'd be very bad if we overwrote these. This obviously doesn't account for browser APIs
|
|
96
|
-
// you can access outside of the `Window` API (like `alert()`), but we can add checks for those
|
|
97
|
-
// later if we need to.
|
|
98
|
-
'frames',
|
|
99
|
-
'global',
|
|
100
|
-
'globalThis',
|
|
101
|
-
'navigator',
|
|
102
|
-
'self',
|
|
103
|
-
'window',
|
|
104
|
-
];
|
|
105
|
-
/**
|
|
106
|
-
* @see {@link https://www.30secondsofcode.org/js/s/word-wrap}
|
|
107
|
-
*/
|
|
108
|
-
function wordWrap(str, max) {
|
|
109
|
-
if (max === void 0) { max = 88; }
|
|
110
|
-
return str.replace(new RegExp("(?![^\\n]{1,".concat(max, "}$)([^\\n]{1,").concat(max, "})\\s"), 'g'), '$1\n');
|
|
111
|
-
}
|
|
112
|
-
exports.wordWrap = wordWrap;
|
|
113
|
-
/**
|
|
114
|
-
* Safely escape some string characters that may break a docblock.
|
|
115
|
-
*
|
|
116
|
-
*/
|
|
117
|
-
function docblockEscape(str) {
|
|
118
|
-
return str.replace(/\/\*/g, '/\\*').replace(/\*\//g, '*\\/');
|
|
119
|
-
}
|
|
120
|
-
exports.docblockEscape = docblockEscape;
|
|
121
|
-
/**
|
|
122
|
-
* Convert a string that might contain spaces or special characters to one that can safely be used
|
|
123
|
-
* as a TypeScript interface or enum name.
|
|
124
|
-
*
|
|
125
|
-
* This function has been adapted and slighty modified from `json-schema-to-typescript`.
|
|
126
|
-
*
|
|
127
|
-
* @license MIT
|
|
128
|
-
* @see {@link https://github.com/bcherny/json-schema-to-typescript}
|
|
129
|
-
*/
|
|
130
|
-
function toSafeString(str) {
|
|
131
|
-
// identifiers in javaScript/ts:
|
|
132
|
-
// First character: a-zA-Z | _ | $
|
|
133
|
-
// Rest: a-zA-Z | _ | $ | 0-9
|
|
134
|
-
// remove accents, umlauts, ... by their basic latin letters
|
|
135
|
-
return ((0, lodash_deburr_1["default"])(str)
|
|
136
|
-
// if the string starts with a number, prefix it with character that typescript can accept
|
|
137
|
-
// https://github.com/bcherny/json-schema-to-typescript/issues/489
|
|
138
|
-
.replace(/^(\d){1}/, '$$1')
|
|
139
|
-
// replace chars which are not valid for typescript identifiers with whitespace
|
|
140
|
-
.replace(/(^\s*[^a-zA-Z_$])|([^a-zA-Z_$\d])/g, ' ')
|
|
141
|
-
// uppercase leading underscores followed by lowercase
|
|
142
|
-
.replace(/^_[a-z]/g, function (match) { return match.toUpperCase(); })
|
|
143
|
-
// remove non-leading underscores followed by lowercase (convert snake_case)
|
|
144
|
-
.replace(/_[a-z]/g, function (match) { return match.substr(1, match.length).toUpperCase(); })
|
|
145
|
-
// uppercase letters after digits, dollars
|
|
146
|
-
.replace(/([\d$]+[a-zA-Z])/g, function (match) { return match.toUpperCase(); })
|
|
147
|
-
// uppercase first letter after whitespace
|
|
148
|
-
.replace(/\s+([a-zA-Z])/g, function (match) { return match.toUpperCase().trim(); })
|
|
149
|
-
// remove remaining whitespace
|
|
150
|
-
.replace(/\s/g, ''));
|
|
151
|
-
}
|
|
152
|
-
exports.toSafeString = toSafeString;
|
|
153
|
-
function generateTypeName() {
|
|
154
|
-
var parts = [];
|
|
155
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
156
|
-
parts[_i] = arguments[_i];
|
|
157
|
-
}
|
|
158
|
-
var str;
|
|
159
|
-
// If the end of our string ends with something like `2XX`, the combination of `startCase` and
|
|
160
|
-
// `camelCase` will transform it into `2Xx`.
|
|
161
|
-
if (parts.length > 1) {
|
|
162
|
-
var last = parts[parts.length - 1];
|
|
163
|
-
if (last.match(/^(\d)XX$/)) {
|
|
164
|
-
str = (0, lodash_startcase_1["default"])((0, lodash_camelcase_1["default"])(parts.slice(0, -1).join(' ')));
|
|
165
|
-
str += " ".concat(last);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if (!str) {
|
|
169
|
-
str = (0, lodash_startcase_1["default"])((0, lodash_camelcase_1["default"])(parts.join(' ')));
|
|
170
|
-
}
|
|
171
|
-
if (RESERVED_WORDS.includes(str.toLowerCase())) {
|
|
172
|
-
str = "$".concat(str);
|
|
173
|
-
}
|
|
174
|
-
return toSafeString(str);
|
|
175
|
-
}
|
|
176
|
-
exports.generateTypeName = generateTypeName;
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import type Storage from '../../storage';
|
|
2
|
-
import type { InstallerOptions } from '../language';
|
|
3
|
-
import type Oas from 'oas';
|
|
4
|
-
import type { Operation } from 'oas';
|
|
5
|
-
import type { ClassDeclaration, JSDocStructure, JSDocTagStructure, OptionalKind } from 'ts-morph';
|
|
6
|
-
import { Project } from 'ts-morph';
|
|
7
|
-
import CodeGeneratorLanguage from '../language';
|
|
8
|
-
export interface TSGeneratorOptions {
|
|
9
|
-
compilerTarget?: 'cjs' | 'esm';
|
|
10
|
-
outputJS?: boolean;
|
|
11
|
-
}
|
|
12
|
-
interface OperationTypeHousing {
|
|
13
|
-
operation: Operation;
|
|
14
|
-
types: {
|
|
15
|
-
params?: false | Record<'body' | 'formData' | 'metadata', string>;
|
|
16
|
-
responses?: Record<string | number, {
|
|
17
|
-
description?: string;
|
|
18
|
-
type: string;
|
|
19
|
-
}>;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
export default class TSGenerator extends CodeGeneratorLanguage {
|
|
23
|
-
project: Project;
|
|
24
|
-
outputJS: boolean;
|
|
25
|
-
compilerTarget: 'cjs' | 'esm';
|
|
26
|
-
types: Map<string, string>;
|
|
27
|
-
files: Record<string, string>;
|
|
28
|
-
sdk: ClassDeclaration;
|
|
29
|
-
schemas: Record<string, {
|
|
30
|
-
body?: any;
|
|
31
|
-
metadata?: any;
|
|
32
|
-
response?: Record<string, any>;
|
|
33
|
-
} | Record<string, any>>;
|
|
34
|
-
usesHTTPMethodRangeInterface: boolean;
|
|
35
|
-
constructor(spec: Oas, specPath: string, identifier: string, opts?: TSGeneratorOptions);
|
|
36
|
-
installer(storage: Storage, opts?: InstallerOptions): Promise<void>;
|
|
37
|
-
/**
|
|
38
|
-
* Compile the current OpenAPI definition into a TypeScript library.
|
|
39
|
-
*
|
|
40
|
-
*/
|
|
41
|
-
generator(): Promise<{
|
|
42
|
-
[x: string]: string;
|
|
43
|
-
}>;
|
|
44
|
-
/**
|
|
45
|
-
* Create our main SDK source file.
|
|
46
|
-
*
|
|
47
|
-
*/
|
|
48
|
-
createSourceFile(): import("ts-morph").SourceFile;
|
|
49
|
-
/**
|
|
50
|
-
* Create our main schemas file. This is where all of the JSON Schema that our TypeScript typing
|
|
51
|
-
* infrastructure sources its data from. Without this there are no types.
|
|
52
|
-
*
|
|
53
|
-
*/
|
|
54
|
-
createSchemasFile(): import("ts-morph").SourceFile;
|
|
55
|
-
/**
|
|
56
|
-
* Create our main types file. This sources its data from the JSON Schema `schemas.ts` file and
|
|
57
|
-
* will re-export types to be used in TypeScript implementations and IDE intellisense. This
|
|
58
|
-
* typing work is functional with the `json-schema-to-ts` library.
|
|
59
|
-
*
|
|
60
|
-
* @see {@link https://npm.im/json-schema-to-ts}
|
|
61
|
-
*/
|
|
62
|
-
createTypesFile(): import("ts-morph").SourceFile;
|
|
63
|
-
/**
|
|
64
|
-
* Add a new JSDoc `@tag` to an existing docblock.
|
|
65
|
-
*
|
|
66
|
-
*/
|
|
67
|
-
static addTagToDocblock(docblock: OptionalKind<JSDocStructure>, tag: OptionalKind<JSDocTagStructure>): {
|
|
68
|
-
tags: OptionalKind<JSDocTagStructure>[];
|
|
69
|
-
description?: string | import("ts-morph").WriterFunction;
|
|
70
|
-
leadingTrivia?: string | import("ts-morph").WriterFunction | (string | import("ts-morph").WriterFunction)[];
|
|
71
|
-
trailingTrivia?: string | import("ts-morph").WriterFunction | (string | import("ts-morph").WriterFunction)[];
|
|
72
|
-
kind?: import("ts-morph").StructureKind.JSDoc;
|
|
73
|
-
};
|
|
74
|
-
/**
|
|
75
|
-
* Create operation accessors on the SDK.
|
|
76
|
-
*
|
|
77
|
-
*/
|
|
78
|
-
createOperationAccessor(operation: Operation, operationId: string, paramTypes?: OperationTypeHousing['types']['params'], responseTypes?: OperationTypeHousing['types']['responses']): void;
|
|
79
|
-
/**
|
|
80
|
-
* Scour through the current OpenAPI definition and compile a store of every operation, along
|
|
81
|
-
* with every HTTP method that's in use, and their available TypeScript types that we can use,
|
|
82
|
-
* along with every HTTP method that's in use.
|
|
83
|
-
*
|
|
84
|
-
*/
|
|
85
|
-
loadOperationsAndMethods(): {
|
|
86
|
-
operations: Record<string, OperationTypeHousing>;
|
|
87
|
-
methods: Set<unknown>;
|
|
88
|
-
};
|
|
89
|
-
/**
|
|
90
|
-
* Compile the parameter (path, query, cookie, and header) schemas for an API operation into
|
|
91
|
-
* usable TypeScript types.
|
|
92
|
-
*
|
|
93
|
-
*/
|
|
94
|
-
prepareParameterTypesForOperation(operation: Operation, operationId: string): false | Record<"formData" | "body" | "metadata", string>;
|
|
95
|
-
/**
|
|
96
|
-
* Compile the response schemas for an API operation into usable TypeScript types.
|
|
97
|
-
*
|
|
98
|
-
*/
|
|
99
|
-
prepareResponseTypesForOperation(operation: Operation, operationId: string): {
|
|
100
|
-
[x: string]: {
|
|
101
|
-
type: string;
|
|
102
|
-
description: any;
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
/**
|
|
106
|
-
* Add a given schema into our schema dataset that we'll be be exporting as types.
|
|
107
|
-
*
|
|
108
|
-
*/
|
|
109
|
-
addSchemaToExport(schema: any, typeName: string, pointer: string): void;
|
|
110
|
-
}
|
|
111
|
-
export {};
|