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
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -36,18 +36,6 @@ petstore.listPets().then(({ data }) => {
|
|
|
36
36
|
});
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
Or you can use it dynamically (though you won't have fancy TypeScript types to help you out!):
|
|
40
|
-
|
|
41
|
-
```js
|
|
42
|
-
const petstore = require('api')(
|
|
43
|
-
'https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/petstore.json',
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
petstore.listPets().then(({ data }) => {
|
|
47
|
-
console.log(`My pets name is ${data[0].name}!`);
|
|
48
|
-
});
|
|
49
|
-
```
|
|
50
|
-
|
|
51
39
|
The ESM syntax is supported as well:
|
|
52
40
|
|
|
53
41
|
```js
|
package/dist/bin.js
CHANGED
|
@@ -61,9 +61,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
61
61
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
62
62
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
63
|
};
|
|
64
|
-
exports
|
|
64
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
65
|
var commander_1 = require("commander");
|
|
66
|
-
var commands_1 = __importDefault(require("./
|
|
66
|
+
var commands_1 = __importDefault(require("./commands"));
|
|
67
67
|
var pkg = __importStar(require("./packageInfo"));
|
|
68
68
|
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
69
69
|
var program;
|
|
@@ -78,7 +78,7 @@ var pkg = __importStar(require("./packageInfo"));
|
|
|
78
78
|
* programatically doing it like this because it's cleaner for us to let Commander manage option
|
|
79
79
|
* and argument parsing within this file than having each command manage that itself.
|
|
80
80
|
*/
|
|
81
|
-
Object.entries(commands_1
|
|
81
|
+
Object.entries(commands_1.default).forEach(function (_a) {
|
|
82
82
|
var cmd = _a[1];
|
|
83
83
|
program.addCommand(cmd);
|
|
84
84
|
});
|
|
@@ -2,7 +2,7 @@
|
|
|
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 typescript_1 = __importDefault(require("./languages/typescript"));
|
|
7
7
|
function codegen(language, spec, specPath, identifier) {
|
|
8
8
|
switch (language) {
|
|
@@ -11,13 +11,13 @@ function codegen(language, spec, specPath, identifier) {
|
|
|
11
11
|
case 'js-cjs':
|
|
12
12
|
case 'js-esm':
|
|
13
13
|
case 'ts':
|
|
14
|
-
return new typescript_1
|
|
14
|
+
return new typescript_1.default(spec, specPath, identifier, {
|
|
15
15
|
outputJS: ['js-cjs', 'js-esm'].includes(language),
|
|
16
16
|
// TS will always generate with ESM-like exports.
|
|
17
|
-
compilerTarget: language === 'js-cjs' ? 'cjs' : 'esm'
|
|
17
|
+
compilerTarget: language === 'js-cjs' ? 'cjs' : 'esm',
|
|
18
18
|
});
|
|
19
19
|
default:
|
|
20
20
|
throw new TypeError("Unsupported language supplied: ".concat(language));
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
exports
|
|
23
|
+
exports.default = codegen;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
3
|
-
var packageInfo_1 = require("
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var packageInfo_1 = require("../packageInfo");
|
|
4
4
|
var CodeGeneratorLanguage = /** @class */ (function () {
|
|
5
5
|
function CodeGeneratorLanguage(spec, specPath, identifier) {
|
|
6
6
|
this.spec = spec;
|
|
7
7
|
this.specPath = specPath;
|
|
8
|
+
this.identifier = identifier;
|
|
8
9
|
// User agents should be contextual to the spec in question and the version of `api` that was
|
|
9
10
|
// used to generate the SDK. For example, this'll look like `petstore/1.0.0 (api/4.2.0)` for
|
|
10
11
|
// a `petstore` spec installed on api@4.2.0.
|
|
@@ -29,4 +30,4 @@ var CodeGeneratorLanguage = /** @class */ (function () {
|
|
|
29
30
|
};
|
|
30
31
|
return CodeGeneratorLanguage;
|
|
31
32
|
}());
|
|
32
|
-
exports
|
|
33
|
+
exports.default = CodeGeneratorLanguage;
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
export declare function generateTypeName(...parts: string[]): string;
|
|
@@ -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
|
|
6
|
-
exports.generateTypeName = exports.
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateTypeName = exports.docblockEscape = exports.wordWrap = void 0;
|
|
7
7
|
var lodash_camelcase_1 = __importDefault(require("lodash.camelcase"));
|
|
8
8
|
var lodash_deburr_1 = __importDefault(require("lodash.deburr"));
|
|
9
9
|
var lodash_startcase_1 = __importDefault(require("lodash.startcase"));
|
|
@@ -132,7 +132,7 @@ function toSafeString(str) {
|
|
|
132
132
|
// First character: a-zA-Z | _ | $
|
|
133
133
|
// Rest: a-zA-Z | _ | $ | 0-9
|
|
134
134
|
// remove accents, umlauts, ... by their basic latin letters
|
|
135
|
-
return ((0, lodash_deburr_1
|
|
135
|
+
return ((0, lodash_deburr_1.default)(str)
|
|
136
136
|
// if the string starts with a number, prefix it with character that typescript can accept
|
|
137
137
|
// https://github.com/bcherny/json-schema-to-typescript/issues/489
|
|
138
138
|
.replace(/^(\d){1}/, '$$1')
|
|
@@ -149,7 +149,6 @@ function toSafeString(str) {
|
|
|
149
149
|
// remove remaining whitespace
|
|
150
150
|
.replace(/\s/g, ''));
|
|
151
151
|
}
|
|
152
|
-
exports.toSafeString = toSafeString;
|
|
153
152
|
function generateTypeName() {
|
|
154
153
|
var parts = [];
|
|
155
154
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -161,12 +160,12 @@ function generateTypeName() {
|
|
|
161
160
|
if (parts.length > 1) {
|
|
162
161
|
var last = parts[parts.length - 1];
|
|
163
162
|
if (last.match(/^(\d)XX$/)) {
|
|
164
|
-
str = (0, lodash_startcase_1
|
|
163
|
+
str = (0, lodash_startcase_1.default)((0, lodash_camelcase_1.default)(parts.slice(0, -1).join(' ')));
|
|
165
164
|
str += " ".concat(last);
|
|
166
165
|
}
|
|
167
166
|
}
|
|
168
167
|
if (!str) {
|
|
169
|
-
str = (0, lodash_startcase_1
|
|
168
|
+
str = (0, lodash_startcase_1.default)((0, lodash_camelcase_1.default)(parts.join(' ')));
|
|
170
169
|
}
|
|
171
170
|
if (RESERVED_WORDS.includes(str.toLowerCase())) {
|
|
172
171
|
str = "$".concat(str);
|
|
@@ -2,6 +2,7 @@ import type Storage from '../../storage';
|
|
|
2
2
|
import type { InstallerOptions } from '../language';
|
|
3
3
|
import type Oas from 'oas';
|
|
4
4
|
import type { Operation } from 'oas';
|
|
5
|
+
import type { HttpMethods, SchemaObject } from 'oas/dist/rmoas.types';
|
|
5
6
|
import type { ClassDeclaration, JSDocStructure, JSDocTagStructure, OptionalKind } from 'ts-morph';
|
|
6
7
|
import { Project } from 'ts-morph';
|
|
7
8
|
import CodeGeneratorLanguage from '../language';
|
|
@@ -24,13 +25,12 @@ export default class TSGenerator extends CodeGeneratorLanguage {
|
|
|
24
25
|
outputJS: boolean;
|
|
25
26
|
compilerTarget: 'cjs' | 'esm';
|
|
26
27
|
types: Map<string, string>;
|
|
27
|
-
files: Record<string, string>;
|
|
28
28
|
sdk: ClassDeclaration;
|
|
29
29
|
schemas: Record<string, {
|
|
30
|
-
body?:
|
|
31
|
-
metadata?:
|
|
32
|
-
response?: Record<string,
|
|
33
|
-
} | Record<string,
|
|
30
|
+
body?: unknown;
|
|
31
|
+
metadata?: unknown;
|
|
32
|
+
response?: Record<string, unknown>;
|
|
33
|
+
} | Record<string, unknown>>;
|
|
34
34
|
usesHTTPMethodRangeInterface: boolean;
|
|
35
35
|
constructor(spec: Oas, specPath: string, identifier: string, opts?: TSGeneratorOptions);
|
|
36
36
|
installer(storage: Storage, opts?: InstallerOptions): Promise<void>;
|
|
@@ -66,10 +66,10 @@ export default class TSGenerator extends CodeGeneratorLanguage {
|
|
|
66
66
|
*/
|
|
67
67
|
static addTagToDocblock(docblock: OptionalKind<JSDocStructure>, tag: OptionalKind<JSDocTagStructure>): {
|
|
68
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;
|
|
69
|
+
description?: string | import("ts-morph").WriterFunction | undefined;
|
|
70
|
+
leadingTrivia?: string | import("ts-morph").WriterFunction | (string | import("ts-morph").WriterFunction)[] | undefined;
|
|
71
|
+
trailingTrivia?: string | import("ts-morph").WriterFunction | (string | import("ts-morph").WriterFunction)[] | undefined;
|
|
72
|
+
kind?: import("ts-morph").StructureKind.JSDoc | undefined;
|
|
73
73
|
};
|
|
74
74
|
/**
|
|
75
75
|
* Create operation accessors on the SDK.
|
|
@@ -84,7 +84,7 @@ export default class TSGenerator extends CodeGeneratorLanguage {
|
|
|
84
84
|
*/
|
|
85
85
|
loadOperationsAndMethods(): {
|
|
86
86
|
operations: Record<string, OperationTypeHousing>;
|
|
87
|
-
methods: Set<
|
|
87
|
+
methods: Set<HttpMethods>;
|
|
88
88
|
};
|
|
89
89
|
/**
|
|
90
90
|
* Compile the parameter (path, query, cookie, and header) schemas for an API operation into
|
|
@@ -101,11 +101,11 @@ export default class TSGenerator extends CodeGeneratorLanguage {
|
|
|
101
101
|
type: string;
|
|
102
102
|
description: any;
|
|
103
103
|
};
|
|
104
|
-
};
|
|
104
|
+
} | undefined;
|
|
105
105
|
/**
|
|
106
106
|
* Add a given schema into our schema dataset that we'll be be exporting as types.
|
|
107
107
|
*
|
|
108
108
|
*/
|
|
109
|
-
addSchemaToExport(schema:
|
|
109
|
+
addSchemaToExport(schema: SchemaObject, typeName: string, pointer: string): void;
|
|
110
110
|
}
|
|
111
111
|
export {};
|