api 6.1.1 → 7.0.0-alpha.1
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/dist/bin.js +3 -3
- package/dist/{cli/codegen → codegen}/index.js +4 -4
- package/dist/{cli/codegen → codegen}/language.js +4 -3
- package/dist/codegen/languages/typescript/util.d.ts +10 -0
- package/dist/{cli/codegen → codegen}/languages/typescript/util.js +5 -6
- package/dist/{cli/codegen → codegen}/languages/typescript.d.ts +12 -12
- package/dist/{cli/codegen → codegen}/languages/typescript.js +75 -75
- package/dist/{cli/commands → commands}/index.js +3 -3
- package/dist/{cli/commands → commands}/install.js +37 -34
- package/dist/fetcher.d.ts +8 -9
- package/dist/fetcher.js +15 -15
- package/dist/{cli/lib → lib}/prompt.js +3 -3
- package/dist/{cli/logger.js → logger.js} +3 -3
- package/dist/packageInfo.d.ts +1 -1
- package/dist/packageInfo.js +2 -2
- package/dist/{cli/storage.d.ts → storage.d.ts} +5 -4
- package/dist/{cli/storage.js → storage.js} +39 -36
- 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/cache.d.ts +0 -68
- package/dist/cache.js +0 -198
- package/dist/cli/codegen/languages/typescript/util.d.ts +0 -20
- 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/index.d.ts +0 -6
- package/dist/index.js +0 -259
- 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/dist/{cli/codegen → codegen}/index.d.ts +0 -0
- /package/dist/{cli/codegen → codegen}/language.d.ts +0 -0
- /package/dist/{cli/commands → commands}/index.d.ts +0 -0
- /package/dist/{cli/commands → commands}/install.d.ts +0 -0
- /package/dist/{cli/lib → lib}/prompt.d.ts +0 -0
- /package/dist/{cli/logger.d.ts → logger.d.ts} +0 -0
- /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
|
@@ -73,9 +73,9 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
73
73
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
74
74
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
75
75
|
};
|
|
76
|
-
exports
|
|
77
|
-
var
|
|
78
|
-
var
|
|
76
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
77
|
+
var node_fs_1 = __importDefault(require("node:fs"));
|
|
78
|
+
var node_path_1 = __importDefault(require("node:path"));
|
|
79
79
|
var execa_1 = __importDefault(require("execa"));
|
|
80
80
|
var lodash_setwith_1 = __importDefault(require("lodash.setwith"));
|
|
81
81
|
var semver_1 = __importDefault(require("semver"));
|
|
@@ -86,8 +86,8 @@ var util_1 = require("./typescript/util");
|
|
|
86
86
|
var TSGenerator = /** @class */ (function (_super) {
|
|
87
87
|
__extends(TSGenerator, _super);
|
|
88
88
|
function TSGenerator(spec, specPath, identifier, opts) {
|
|
89
|
-
if (opts === void 0) { opts = {}; }
|
|
90
89
|
var _this = this;
|
|
90
|
+
if (opts === void 0) { opts = {}; }
|
|
91
91
|
var options = __assign({ outputJS: false, compilerTarget: 'cjs' }, opts);
|
|
92
92
|
if (!options.outputJS) {
|
|
93
93
|
// TypeScript compilation will always target towards ESM-like imports and exports.
|
|
@@ -97,27 +97,27 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
97
97
|
_this.usesHTTPMethodRangeInterface = false;
|
|
98
98
|
_this.requiredPackages = {
|
|
99
99
|
api: {
|
|
100
|
-
reason: "Required for the
|
|
101
|
-
url: 'https://npm.im/api'
|
|
100
|
+
reason: "Required for the `@readme/api-core` library that the codegen'd SDK uses for making requests.",
|
|
101
|
+
url: 'https://npm.im/api',
|
|
102
102
|
},
|
|
103
|
-
'json-schema-to-ts
|
|
103
|
+
'json-schema-to-ts': {
|
|
104
104
|
reason: 'Required for TypeScript type handling.',
|
|
105
|
-
url: 'https://npm.im/json-schema-to-ts'
|
|
105
|
+
url: 'https://npm.im/json-schema-to-ts',
|
|
106
106
|
},
|
|
107
107
|
oas: {
|
|
108
|
-
reason: 'Used within
|
|
109
|
-
url: 'https://npm.im/oas'
|
|
110
|
-
}
|
|
108
|
+
reason: 'Used within `@readme/api-core` and is also loaded for TypeScript types.',
|
|
109
|
+
url: 'https://npm.im/oas',
|
|
110
|
+
},
|
|
111
111
|
};
|
|
112
112
|
_this.project = new ts_morph_1.Project({
|
|
113
113
|
manipulationSettings: {
|
|
114
114
|
indentationText: ts_morph_1.IndentationText.TwoSpaces,
|
|
115
|
-
quoteKind: ts_morph_1.QuoteKind.Single
|
|
115
|
+
quoteKind: ts_morph_1.QuoteKind.Single,
|
|
116
116
|
},
|
|
117
117
|
compilerOptions: __assign({
|
|
118
118
|
// If we're exporting a TypeScript SDK then we don't need to pollute the codegen directory
|
|
119
119
|
// with unnecessary declaration `.d.ts` files.
|
|
120
|
-
declaration: options.outputJS, outDir: 'dist', resolveJsonModule: true, target: options.compilerTarget === 'cjs' ? ts_morph_1.ScriptTarget.ES5 : ts_morph_1.ScriptTarget.ES2020 }, (options.compilerTarget === 'cjs' ? { esModuleInterop: true } : {}))
|
|
120
|
+
declaration: options.outputJS, outDir: 'dist', resolveJsonModule: true, target: options.compilerTarget === 'cjs' ? ts_morph_1.ScriptTarget.ES5 : ts_morph_1.ScriptTarget.ES2020 }, (options.compilerTarget === 'cjs' ? { esModuleInterop: true } : {})),
|
|
121
121
|
});
|
|
122
122
|
_this.compilerTarget = options.compilerTarget;
|
|
123
123
|
_this.outputJS = options.outputJS;
|
|
@@ -134,27 +134,27 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
134
134
|
case 0:
|
|
135
135
|
installDir = storage.getIdentifierStorageDir();
|
|
136
136
|
info = this.spec.getDefinition().info;
|
|
137
|
-
pkgVersion = semver_1
|
|
137
|
+
pkgVersion = semver_1.default.coerce(info.version);
|
|
138
138
|
if (!pkgVersion) {
|
|
139
139
|
// If the version that's in `info.version` isn't compatible with semver NPM won't be able to
|
|
140
140
|
// handle it properly so we need to fallback to something it can.
|
|
141
|
-
pkgVersion = semver_1
|
|
141
|
+
pkgVersion = semver_1.default.coerce('0.0.0');
|
|
142
142
|
}
|
|
143
143
|
pkg = {
|
|
144
144
|
name: "@api/".concat(storage.identifier),
|
|
145
145
|
version: pkgVersion.version,
|
|
146
146
|
main: "./index.".concat(this.outputJS ? 'js' : 'ts'),
|
|
147
|
-
types: './index.d.ts'
|
|
147
|
+
types: './index.d.ts', // Types are always present regardless if you're getting compiled JS.
|
|
148
148
|
};
|
|
149
|
-
|
|
149
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(installDir, 'package.json'), JSON.stringify(pkg, null, 2));
|
|
150
150
|
npmInstall = ['install', '--save', opts.dryRun ? '--dry-run' : ''].filter(Boolean);
|
|
151
151
|
// This will install packages required for the SDK within its installed directory in `.apis/`.
|
|
152
|
-
return [4 /*yield*/, (0, execa_1
|
|
153
|
-
cwd: installDir
|
|
152
|
+
return [4 /*yield*/, (0, execa_1.default)('npm', __spreadArray(__spreadArray([], npmInstall, true), Object.keys(this.requiredPackages), true).filter(Boolean), {
|
|
153
|
+
cwd: installDir,
|
|
154
154
|
}).then(function (res) {
|
|
155
155
|
if (opts.dryRun) {
|
|
156
|
-
(opts.logger ? opts.logger : logger_1
|
|
157
|
-
(opts.logger ? opts.logger : logger_1
|
|
156
|
+
(opts.logger ? opts.logger : logger_1.default)(res.command);
|
|
157
|
+
(opts.logger ? opts.logger : logger_1.default)(res.stdout);
|
|
158
158
|
}
|
|
159
159
|
})];
|
|
160
160
|
case 1:
|
|
@@ -163,15 +163,16 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
163
163
|
// This will install the installed SDK as a dependency within the current working directory,
|
|
164
164
|
// adding `@api/<sdk identifier>` as a dependency there so you can load it with
|
|
165
165
|
// `require('@api/<sdk identifier>)`.
|
|
166
|
-
return [2 /*return*/, (0, execa_1
|
|
166
|
+
return [2 /*return*/, (0, execa_1.default)('npm', __spreadArray(__spreadArray([], npmInstall, true), [installDir], false).filter(Boolean))
|
|
167
167
|
.then(function (res) {
|
|
168
168
|
if (opts.dryRun) {
|
|
169
|
-
(opts.logger ? opts.logger : logger_1
|
|
170
|
-
(opts.logger ? opts.logger : logger_1
|
|
169
|
+
(opts.logger ? opts.logger : logger_1.default)(res.command);
|
|
170
|
+
(opts.logger ? opts.logger : logger_1.default)(res.stdout);
|
|
171
171
|
}
|
|
172
|
-
})
|
|
172
|
+
})
|
|
173
|
+
.catch(function (err) {
|
|
173
174
|
if (opts.dryRun) {
|
|
174
|
-
(opts.logger ? opts.logger : logger_1
|
|
175
|
+
(opts.logger ? opts.logger : logger_1.default)(err.message);
|
|
175
176
|
return;
|
|
176
177
|
}
|
|
177
178
|
throw err;
|
|
@@ -185,10 +186,11 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
185
186
|
*
|
|
186
187
|
*/
|
|
187
188
|
TSGenerator.prototype.generator = function () {
|
|
189
|
+
var _a, _b;
|
|
188
190
|
return __awaiter(this, void 0, void 0, function () {
|
|
189
191
|
var sdkSource, types;
|
|
190
192
|
var _this = this;
|
|
191
|
-
return __generator(this, function (
|
|
193
|
+
return __generator(this, function (_c) {
|
|
192
194
|
sdkSource = this.createSourceFile();
|
|
193
195
|
if (Object.keys(this.schemas).length) {
|
|
194
196
|
this.createSchemasFile();
|
|
@@ -211,25 +213,23 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
211
213
|
{
|
|
212
214
|
isTypeOnly: true,
|
|
213
215
|
namedExports: types,
|
|
214
|
-
moduleSpecifier: './types'
|
|
216
|
+
moduleSpecifier: './types',
|
|
215
217
|
},
|
|
216
218
|
]);
|
|
217
219
|
}
|
|
218
220
|
}
|
|
219
221
|
else {
|
|
220
222
|
// If we don't have any schemas then we shouldn't import a `types` file that doesn't exist.
|
|
221
|
-
sdkSource
|
|
223
|
+
(_a = sdkSource
|
|
222
224
|
.getImportDeclarations()
|
|
223
|
-
.find(function (id) { return id.getText() === "import type * as types from './types';"; })
|
|
224
|
-
.remove();
|
|
225
|
+
.find(function (id) { return id.getText() === "import type * as types from './types';"; })) === null || _a === void 0 ? void 0 : _a.remove();
|
|
225
226
|
}
|
|
226
227
|
// If this SDK doesn't use the `HTTPMethodRange` interface for handling `2XX` response status
|
|
227
228
|
// codes then we should remove it from being imported.
|
|
228
229
|
if (!this.usesHTTPMethodRangeInterface) {
|
|
229
|
-
sdkSource
|
|
230
|
+
(_b = sdkSource
|
|
230
231
|
.getImportDeclarations()
|
|
231
|
-
.find(function (id) { return id.getText().includes('HTTPMethodRange'); })
|
|
232
|
-
.replaceWithText("import type { ConfigOptions, FetchResponse } from 'api/dist/core'");
|
|
232
|
+
.find(function (id) { return id.getText().includes('HTTPMethodRange'); })) === null || _b === void 0 ? void 0 : _b.replaceWithText("import type { ConfigOptions, FetchResponse } from '@readme/api-core';");
|
|
233
233
|
}
|
|
234
234
|
if (this.outputJS) {
|
|
235
235
|
return [2 /*return*/, this.project
|
|
@@ -237,7 +237,7 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
237
237
|
.getFiles()
|
|
238
238
|
.map(function (sourceFile) {
|
|
239
239
|
var _a;
|
|
240
|
-
var file =
|
|
240
|
+
var file = node_path_1.default.basename(sourceFile.filePath);
|
|
241
241
|
if (file === 'schemas.js' || file === 'types.js') {
|
|
242
242
|
// If we're generating a JS SDK then we don't need to generate these two files as the
|
|
243
243
|
// user will have `.d.ts` files for them instead.
|
|
@@ -276,7 +276,7 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
276
276
|
.map(function (sourceFile) {
|
|
277
277
|
var _a;
|
|
278
278
|
return (_a = {},
|
|
279
|
-
_a[
|
|
279
|
+
_a[node_path_1.default.basename(sourceFile.filePath)] = sourceFile.text,
|
|
280
280
|
_a);
|
|
281
281
|
}), true).reduce(function (prev, next) { return Object.assign(prev, next); })];
|
|
282
282
|
});
|
|
@@ -296,10 +296,10 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
296
296
|
{
|
|
297
297
|
// `HTTPMethodRange` will be conditionally removed later if it ends up not being used.
|
|
298
298
|
defaultImport: 'type { ConfigOptions, FetchResponse, HTTPMethodRange }',
|
|
299
|
-
moduleSpecifier: 'api
|
|
299
|
+
moduleSpecifier: '@readme/api-core',
|
|
300
300
|
},
|
|
301
301
|
{ defaultImport: 'Oas', moduleSpecifier: 'oas' },
|
|
302
|
-
{ defaultImport: 'APICore', moduleSpecifier: 'api
|
|
302
|
+
{ defaultImport: 'APICore', moduleSpecifier: '@readme/api-core' },
|
|
303
303
|
{ defaultImport: 'definition', moduleSpecifier: this.specPath },
|
|
304
304
|
]);
|
|
305
305
|
// @todo add TOS, License, info.* to a docblock at the top of the SDK.
|
|
@@ -308,14 +308,14 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
308
308
|
properties: [
|
|
309
309
|
{ name: 'spec', type: 'Oas' },
|
|
310
310
|
{ name: 'core', type: 'APICore' },
|
|
311
|
-
]
|
|
311
|
+
],
|
|
312
312
|
});
|
|
313
313
|
this.sdk.addConstructor({
|
|
314
314
|
statements: function (writer) {
|
|
315
315
|
writer.writeLine('this.spec = Oas.init(definition);');
|
|
316
316
|
writer.write('this.core = new APICore(this.spec, ').quote(_this.userAgent).write(');');
|
|
317
317
|
return writer;
|
|
318
|
-
}
|
|
318
|
+
},
|
|
319
319
|
});
|
|
320
320
|
// Add our core API methods for controlling auth, servers, and various configurable abilities.
|
|
321
321
|
this.sdk.addMethods([
|
|
@@ -332,11 +332,11 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
332
332
|
{ tagName: 'param', text: 'config Object of supported SDK options and toggles.' },
|
|
333
333
|
{
|
|
334
334
|
tagName: 'param',
|
|
335
|
-
text: (0, util_1.wordWrap)('config.timeout Override the default `fetch` request timeout of 30 seconds. This number should be represented in milliseconds.')
|
|
335
|
+
text: (0, util_1.wordWrap)('config.timeout Override the default `fetch` request timeout of 30 seconds. This number should be represented in milliseconds.'),
|
|
336
336
|
},
|
|
337
|
-
]
|
|
337
|
+
],
|
|
338
338
|
},
|
|
339
|
-
]
|
|
339
|
+
],
|
|
340
340
|
},
|
|
341
341
|
{
|
|
342
342
|
name: 'auth',
|
|
@@ -356,11 +356,11 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
356
356
|
{ tagName: 'see', text: '{@link https://spec.openapis.org/oas/v3.1.0#fixed-fields-22}' },
|
|
357
357
|
{
|
|
358
358
|
tagName: 'param',
|
|
359
|
-
text: 'values Your auth credentials for the API; can specify up to two strings or numbers.'
|
|
359
|
+
text: 'values Your auth credentials for the API; can specify up to two strings or numbers.',
|
|
360
360
|
},
|
|
361
|
-
]
|
|
361
|
+
],
|
|
362
362
|
},
|
|
363
|
-
]
|
|
363
|
+
],
|
|
364
364
|
},
|
|
365
365
|
{
|
|
366
366
|
name: 'server',
|
|
@@ -377,9 +377,9 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
377
377
|
tags: [
|
|
378
378
|
{ tagName: 'param', text: 'url Server URL' },
|
|
379
379
|
{ tagName: 'param', text: 'variables An object of variables to replace into the server URL.' },
|
|
380
|
-
]
|
|
380
|
+
],
|
|
381
381
|
},
|
|
382
|
-
]
|
|
382
|
+
],
|
|
383
383
|
},
|
|
384
384
|
]);
|
|
385
385
|
// Add all available operation ID accessors into the SDK.
|
|
@@ -397,9 +397,9 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
397
397
|
// `ts-morph` doesn't have any way to cleanly create an IFEE.
|
|
398
398
|
writer.writeLine('(() => { return new SDK(); })()');
|
|
399
399
|
return writer;
|
|
400
|
-
}
|
|
400
|
+
},
|
|
401
401
|
},
|
|
402
|
-
]
|
|
402
|
+
],
|
|
403
403
|
});
|
|
404
404
|
sourceFile.addExportAssignment({
|
|
405
405
|
// Because CJS targets have `createSDK` exported with `module.exports`, but the TS type side
|
|
@@ -407,7 +407,7 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
407
407
|
// handle this accordingly and still create our JS file with `module.exports` and not
|
|
408
408
|
// `export =` -- only TS types will have this export style.
|
|
409
409
|
isExportEquals: this.compilerTarget === 'cjs' && this.outputJS,
|
|
410
|
-
expression: 'createSDK'
|
|
410
|
+
expression: 'createSDK',
|
|
411
411
|
});
|
|
412
412
|
return sourceFile;
|
|
413
413
|
};
|
|
@@ -444,9 +444,9 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
444
444
|
str = str.replace(/"::convert::([a-zA-Z_$\\d]*)"/g, '$1');
|
|
445
445
|
writer.writeLine("".concat(str, " as const"));
|
|
446
446
|
return writer;
|
|
447
|
-
}
|
|
447
|
+
},
|
|
448
448
|
},
|
|
449
|
-
]
|
|
449
|
+
],
|
|
450
450
|
});
|
|
451
451
|
});
|
|
452
452
|
sourceFile.addStatements("export { ".concat(Array.from(sortedSchemas.keys()).join(', '), " }"));
|
|
@@ -507,7 +507,7 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
507
507
|
if (summary && description) {
|
|
508
508
|
docblock = TSGenerator.addTagToDocblock(docblock, {
|
|
509
509
|
tagName: 'summary',
|
|
510
|
-
text: (0, util_1.docblockEscape)((0, util_1.wordWrap)(summary))
|
|
510
|
+
text: (0, util_1.docblockEscape)((0, util_1.wordWrap)(summary)),
|
|
511
511
|
});
|
|
512
512
|
}
|
|
513
513
|
}
|
|
@@ -522,7 +522,7 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
522
522
|
parameters.body = {
|
|
523
523
|
name: 'body',
|
|
524
524
|
type: paramTypes.body ? paramTypes.body : paramTypes.formData,
|
|
525
|
-
hasQuestionToken: hasOptionalBody
|
|
525
|
+
hasQuestionToken: hasOptionalBody,
|
|
526
526
|
};
|
|
527
527
|
}
|
|
528
528
|
if (paramTypes.metadata) {
|
|
@@ -530,7 +530,7 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
530
530
|
parameters.metadata = {
|
|
531
531
|
name: 'metadata',
|
|
532
532
|
type: paramTypes.metadata,
|
|
533
|
-
hasQuestionToken: hasOptionalMetadata
|
|
533
|
+
hasQuestionToken: hasOptionalMetadata,
|
|
534
534
|
};
|
|
535
535
|
}
|
|
536
536
|
}
|
|
@@ -552,7 +552,7 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
552
552
|
if (Number(statusPrefix) >= 4) {
|
|
553
553
|
docblock = TSGenerator.addTagToDocblock(docblock, {
|
|
554
554
|
tagName: 'throws',
|
|
555
|
-
text: "FetchError<".concat(status, ", ").concat(responseType, ">").concat(responseDescription ? (0, util_1.docblockEscape)((0, util_1.wordWrap)(" ".concat(responseDescription))) : '')
|
|
555
|
+
text: "FetchError<".concat(status, ", ").concat(responseType, ">").concat(responseDescription ? (0, util_1.docblockEscape)((0, util_1.wordWrap)(" ".concat(responseDescription))) : ''),
|
|
556
556
|
});
|
|
557
557
|
return false;
|
|
558
558
|
}
|
|
@@ -564,7 +564,7 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
564
564
|
if (Number(status) >= 400) {
|
|
565
565
|
docblock = TSGenerator.addTagToDocblock(docblock, {
|
|
566
566
|
tagName: 'throws',
|
|
567
|
-
text: "FetchError<".concat(status, ", ").concat(responseType, ">").concat(responseDescription ? (0, util_1.docblockEscape)((0, util_1.wordWrap)(" ".concat(responseDescription))) : '')
|
|
567
|
+
text: "FetchError<".concat(status, ", ").concat(responseType, ">").concat(responseDescription ? (0, util_1.docblockEscape)((0, util_1.wordWrap)(" ".concat(responseDescription))) : ''),
|
|
568
568
|
});
|
|
569
569
|
return false;
|
|
570
570
|
}
|
|
@@ -584,7 +584,7 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
584
584
|
// we should only add a docblock to the first overload we create because IDE Intellisense will
|
|
585
585
|
// always use that and adding a docblock to all three will bloat the SDK with unused and
|
|
586
586
|
// unsurfaced method documentation.
|
|
587
|
-
docs: shouldAddAltTypedOverloads ?
|
|
587
|
+
docs: shouldAddAltTypedOverloads ? undefined : Object.keys(docblock).length ? [docblock] : undefined,
|
|
588
588
|
statements: function (writer) {
|
|
589
589
|
/**
|
|
590
590
|
* @example return this.core.fetch('/pet/findByStatus', 'get', body, metadata);
|
|
@@ -609,7 +609,7 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
609
609
|
}
|
|
610
610
|
fetchStmt.write(');');
|
|
611
611
|
return fetchStmt;
|
|
612
|
-
}
|
|
612
|
+
},
|
|
613
613
|
});
|
|
614
614
|
// If we have both body and metadata parameters but only body is optional we need to create
|
|
615
615
|
// a couple function overloads as Typescript doesn't let us have an optional method parameter
|
|
@@ -622,18 +622,18 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
622
622
|
__assign(__assign({}, parameters.metadata), { hasQuestionToken: false }),
|
|
623
623
|
],
|
|
624
624
|
returnType: returnType,
|
|
625
|
-
docs: Object.keys(docblock).length ? [docblock] :
|
|
625
|
+
docs: Object.keys(docblock).length ? [docblock] : undefined,
|
|
626
626
|
});
|
|
627
627
|
// Create an overload that just has a single `metadata` parameter.
|
|
628
628
|
operationIdAccessor.addOverload({
|
|
629
629
|
parameters: [__assign({}, parameters.metadata)],
|
|
630
|
-
returnType: returnType
|
|
630
|
+
returnType: returnType,
|
|
631
631
|
});
|
|
632
632
|
// Create an overload that has both `body` and `metadata` parameters as optional. Even though
|
|
633
633
|
// our `metadata` parameter is actually required for this operation this is the only way we're
|
|
634
634
|
// able to have an optional `body` parameter be present before `metadata`.
|
|
635
635
|
//
|
|
636
|
-
// Thankfully our core fetch work in
|
|
636
|
+
// Thankfully our core fetch work in `@readme/api-core` is able to do the proper determination to
|
|
637
637
|
// see if what the user is supplying is `metadata` or `body` content when they supply one or
|
|
638
638
|
// both.
|
|
639
639
|
operationIdAccessor.addParameters([
|
|
@@ -670,14 +670,14 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
670
670
|
var operationId = operation.getOperationId({
|
|
671
671
|
// This `camelCase` option will clean up any weird characters that might be present in
|
|
672
672
|
// the `operationId` so as we don't break TS compilation with an invalid method accessor.
|
|
673
|
-
camelCase: true
|
|
673
|
+
camelCase: true,
|
|
674
674
|
});
|
|
675
675
|
operations[operationId] = {
|
|
676
676
|
types: {
|
|
677
677
|
params: _this.prepareParameterTypesForOperation(operation, operationId),
|
|
678
|
-
responses: _this.prepareResponseTypesForOperation(operation, operationId)
|
|
678
|
+
responses: _this.prepareResponseTypesForOperation(operation, operationId),
|
|
679
679
|
},
|
|
680
|
-
operation: operation
|
|
680
|
+
operation: operation,
|
|
681
681
|
};
|
|
682
682
|
});
|
|
683
683
|
});
|
|
@@ -686,7 +686,7 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
686
686
|
}
|
|
687
687
|
return {
|
|
688
688
|
operations: operations,
|
|
689
|
-
methods: methods
|
|
689
|
+
methods: methods,
|
|
690
690
|
};
|
|
691
691
|
};
|
|
692
692
|
/**
|
|
@@ -703,13 +703,13 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
703
703
|
transformer: function (s) {
|
|
704
704
|
// As our schemas are dereferenced in the `oas` library we don't want to pollute our
|
|
705
705
|
// codegen'd schemas file with duplicate schemas.
|
|
706
|
-
if ('x-readme-ref-name' in s) {
|
|
706
|
+
if ('x-readme-ref-name' in s && typeof s['x-readme-ref-name'] !== 'undefined') {
|
|
707
707
|
var typeName = (0, util_1.generateTypeName)(s['x-readme-ref-name']);
|
|
708
708
|
_this.addSchemaToExport(s, typeName, typeName);
|
|
709
709
|
return "::convert::".concat(typeName);
|
|
710
710
|
}
|
|
711
711
|
return s;
|
|
712
|
-
}
|
|
712
|
+
},
|
|
713
713
|
});
|
|
714
714
|
if (!schemas || !schemas.length) {
|
|
715
715
|
return false;
|
|
@@ -760,13 +760,13 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
760
760
|
transformer: function (s) {
|
|
761
761
|
// As our schemas are dereferenced in the `oas` library we don't want to pollute our
|
|
762
762
|
// codegen'd schemas file with duplicate schemas.
|
|
763
|
-
if ('x-readme-ref-name' in s) {
|
|
763
|
+
if ('x-readme-ref-name' in s && typeof s['x-readme-ref-name'] !== 'undefined') {
|
|
764
764
|
var typeName = (0, util_1.generateTypeName)(s['x-readme-ref-name']);
|
|
765
765
|
_this.addSchemaToExport(s, typeName, "".concat(typeName));
|
|
766
766
|
return "::convert::".concat(typeName);
|
|
767
767
|
}
|
|
768
768
|
return s;
|
|
769
|
-
}
|
|
769
|
+
},
|
|
770
770
|
});
|
|
771
771
|
if (!schema) {
|
|
772
772
|
return false;
|
|
@@ -798,7 +798,7 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
798
798
|
// `types.d.ts`.
|
|
799
799
|
_b[status] = {
|
|
800
800
|
type: "types.".concat(typeName),
|
|
801
|
-
description: description
|
|
801
|
+
description: description,
|
|
802
802
|
},
|
|
803
803
|
_b;
|
|
804
804
|
})
|
|
@@ -813,9 +813,9 @@ var TSGenerator = /** @class */ (function (_super) {
|
|
|
813
813
|
if (this.types.has(typeName)) {
|
|
814
814
|
return;
|
|
815
815
|
}
|
|
816
|
-
(0, lodash_setwith_1
|
|
816
|
+
(0, lodash_setwith_1.default)(this.schemas, pointer, schema, Object);
|
|
817
817
|
this.types.set(typeName, "FromSchema<typeof schemas.".concat(pointer, ">"));
|
|
818
818
|
};
|
|
819
819
|
return TSGenerator;
|
|
820
|
-
}(language_1
|
|
821
|
-
exports
|
|
820
|
+
}(language_1.default));
|
|
821
|
+
exports.default = TSGenerator;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
|
-
exports
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
var install_1 = __importDefault(require("./install"));
|
|
7
|
-
exports
|
|
8
|
-
install: install_1
|
|
7
|
+
exports.default = {
|
|
8
|
+
install: install_1.default,
|
|
9
9
|
};
|