api 5.0.0-beta.3 → 5.0.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.
Files changed (46) hide show
  1. package/README.md +7 -7
  2. package/dist/bin.js +1 -1
  3. package/dist/cache.d.ts +37 -2
  4. package/dist/cache.js +7 -26
  5. package/dist/cli/codegen/index.d.ts +1 -1
  6. package/dist/cli/codegen/language.d.ts +1 -1
  7. package/dist/cli/codegen/language.js +13 -0
  8. package/dist/cli/codegen/languages/typescript/util.d.ts +21 -0
  9. package/dist/cli/codegen/languages/typescript/util.js +185 -0
  10. package/dist/cli/codegen/languages/typescript.d.ts +31 -38
  11. package/dist/cli/codegen/languages/typescript.js +390 -478
  12. package/dist/cli/commands/install.js +6 -6
  13. package/dist/cli/storage.js +2 -2
  14. package/dist/core/errors/fetchError.d.ts +12 -0
  15. package/dist/core/errors/fetchError.js +36 -0
  16. package/dist/core/index.d.ts +11 -3
  17. package/dist/core/index.js +36 -11
  18. package/dist/core/parseResponse.d.ts +6 -1
  19. package/dist/core/parseResponse.js +9 -3
  20. package/dist/core/prepareAuth.js +47 -18
  21. package/dist/core/prepareParams.d.ts +0 -3
  22. package/dist/core/prepareParams.js +81 -57
  23. package/dist/fetcher.js +3 -3
  24. package/dist/index.js +24 -40
  25. package/dist/packageInfo.d.ts +1 -1
  26. package/dist/packageInfo.js +1 -1
  27. package/package.json +28 -17
  28. package/src/bin.ts +2 -1
  29. package/src/cache.ts +8 -30
  30. package/src/cli/codegen/index.ts +1 -1
  31. package/src/cli/codegen/language.ts +18 -1
  32. package/src/cli/codegen/languages/typescript/util.ts +183 -0
  33. package/src/cli/codegen/languages/typescript.ts +340 -402
  34. package/src/cli/commands/install.ts +6 -8
  35. package/src/cli/storage.ts +3 -3
  36. package/src/core/errors/fetchError.ts +31 -0
  37. package/src/core/getJSONSchemaDefaults.ts +2 -1
  38. package/src/core/index.ts +52 -17
  39. package/src/core/parseResponse.ts +8 -2
  40. package/src/core/prepareAuth.ts +55 -31
  41. package/src/core/prepareParams.ts +88 -55
  42. package/src/fetcher.ts +4 -3
  43. package/src/index.ts +24 -32
  44. package/src/packageInfo.ts +1 -1
  45. package/src/typings.d.ts +0 -1
  46. package/tsconfig.json +1 -1
package/README.md CHANGED
@@ -17,7 +17,7 @@
17
17
  - [Usage](https://api.readme.dev/docs/usage)
18
18
  - [Authentication](https://api.readme.dev/docs/authentication)
19
19
  - [Parameters and Payloads](https://api.readme.dev/docs/parameters-and-payloads)
20
- - [HTTP requests](https://api.readme.dev/docs/http-requests)
20
+ - [Making requests](https://api.readme.dev/docs/making-requests)
21
21
  - [Server configurations](https://api.readme.dev/docs/server-configurations)
22
22
  - [How does it work?](https://api.readme.dev/docs/how-it-works)
23
23
  - [FAQ](https://api.readme.dev/docs/faq)
@@ -29,21 +29,21 @@ $ npx api install https://raw.githubusercontent.com/OAI/OpenAPI-Specification/ma
29
29
  ```
30
30
 
31
31
  ```js
32
- const SDK = require('@api/petstore');
32
+ const petstore = require('@api/petstore');
33
33
 
34
- petstore.listPets().then(res => {
35
- console.log(`My pets name is ${res[0].name}!`);
34
+ petstore.listPets().then(({ data }) => {
35
+ console.log(`My pets name is ${data[0].name}!`);
36
36
  });
37
37
  ```
38
38
 
39
- Or you can use it dynamically (though you won't have fancy TypeScript types):
39
+ Or you can use it dynamically (though you won't have fancy TypeScript types to help you out!):
40
40
 
41
41
  ```js
42
42
  const petstore = require('api')(
43
43
  'https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/petstore.json'
44
44
  );
45
45
 
46
- petstore.listPets().then(res => {
47
- console.log(`My pets name is ${res[0].name}!`);
46
+ petstore.listPets().then(({ data })) => {
47
+ console.log(`My pets name is ${data[0].name}!`);
48
48
  });
49
49
  ```
package/dist/bin.js CHANGED
@@ -63,8 +63,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
63
63
  };
64
64
  exports.__esModule = true;
65
65
  var commander_1 = require("commander");
66
- var pkg = __importStar(require("./packageInfo"));
67
66
  var commands_1 = __importDefault(require("./cli/commands"));
67
+ var pkg = __importStar(require("./packageInfo"));
68
68
  (function () { return __awaiter(void 0, void 0, void 0, function () {
69
69
  var program;
70
70
  return __generator(this, function (_a) {
package/dist/cache.d.ts CHANGED
@@ -20,11 +20,46 @@ export default class Cache {
20
20
  static getCacheHash(file: string | OASDocument): string;
21
21
  static setCacheDir(dir?: string | false): void;
22
22
  static reset(): Promise<void>;
23
- static validate(json: any): Promise<import("openapi-types").OpenAPI.Document<{}>>;
24
23
  isCached(): boolean;
25
24
  getCache(): CacheStore;
26
25
  get(): any;
27
- load(): Promise<OASDocument>;
26
+ load(): Promise<import("openapi-types").OpenAPIV3.Document<{}> | (Omit<Omit<import("openapi-types").OpenAPIV3.Document<{}>, "paths" | "components">, "paths" | "components" | "info" | "servers" | "webhooks" | "jsonSchemaDialect"> & {
27
+ info: import("openapi-types").OpenAPIV3_1.InfoObject;
28
+ jsonSchemaDialect?: string;
29
+ servers?: import("openapi-types").OpenAPIV3_1.ServerObject[];
30
+ } & Pick<{
31
+ paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
32
+ webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
33
+ components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
34
+ }, "paths"> & Omit<Partial<{
35
+ paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
36
+ webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
37
+ components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
38
+ }>, "paths">) | (Omit<Omit<import("openapi-types").OpenAPIV3.Document<{}>, "paths" | "components">, "paths" | "components" | "info" | "servers" | "webhooks" | "jsonSchemaDialect"> & {
39
+ info: import("openapi-types").OpenAPIV3_1.InfoObject;
40
+ jsonSchemaDialect?: string;
41
+ servers?: import("openapi-types").OpenAPIV3_1.ServerObject[];
42
+ } & Pick<{
43
+ paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
44
+ webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
45
+ components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
46
+ }, "webhooks"> & Omit<Partial<{
47
+ paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
48
+ webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
49
+ components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
50
+ }>, "webhooks">) | (Omit<Omit<import("openapi-types").OpenAPIV3.Document<{}>, "paths" | "components">, "paths" | "components" | "info" | "servers" | "webhooks" | "jsonSchemaDialect"> & {
51
+ info: import("openapi-types").OpenAPIV3_1.InfoObject;
52
+ jsonSchemaDialect?: string;
53
+ servers?: import("openapi-types").OpenAPIV3_1.ServerObject[];
54
+ } & Pick<{
55
+ paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
56
+ webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
57
+ components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
58
+ }, "components"> & Omit<Partial<{
59
+ paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
60
+ webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
61
+ components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
62
+ }>, "components">) | import("openapi-types").OpenAPIV2.Document<{}>>;
28
63
  save(spec: OASDocument): OASDocument;
29
64
  }
30
65
  export {};
package/dist/cache.js CHANGED
@@ -39,16 +39,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  exports.__esModule = true;
42
- require("isomorphic-fetch");
43
- var openapi_parser_1 = __importDefault(require("@readme/openapi-parser"));
44
42
  var crypto_1 = __importDefault(require("crypto"));
45
- var find_cache_dir_1 = __importDefault(require("find-cache-dir"));
46
43
  var fs_1 = __importDefault(require("fs"));
47
44
  var os_1 = __importDefault(require("os"));
48
45
  var path_1 = __importDefault(require("path"));
46
+ var find_cache_dir_1 = __importDefault(require("find-cache-dir"));
47
+ require("isomorphic-fetch");
49
48
  var make_dir_1 = __importDefault(require("make-dir"));
50
- var packageInfo_1 = require("./packageInfo");
51
49
  var fetcher_1 = __importDefault(require("./fetcher"));
50
+ var packageInfo_1 = require("./packageInfo");
52
51
  var Cache = /** @class */ (function () {
53
52
  function Cache(uri, cacheDir) {
54
53
  if (cacheDir === void 0) { cacheDir = false; }
@@ -120,25 +119,6 @@ var Cache = /** @class */ (function () {
120
119
  });
121
120
  });
122
121
  };
123
- Cache.validate = function (json) {
124
- if (json.swagger) {
125
- throw new Error('Sorry, this module only supports OpenAPI definitions.');
126
- }
127
- // The `validate` method handles dereferencing for us.
128
- return openapi_parser_1["default"].validate(json, {
129
- dereference: {
130
- // If circular `$refs` are ignored they'll remain in the API definition as `$ref: String`.
131
- // This allows us to not only do easy circular reference detection but also stringify and
132
- // save dereferenced API definitions back into the cache directory.
133
- circular: 'ignore'
134
- }
135
- })["catch"](function (err) {
136
- if (/is not a valid openapi definition/i.test(err.message)) {
137
- throw new Error("Sorry, that doesn't look like a valid OpenAPI definition.");
138
- }
139
- throw err;
140
- });
141
- };
142
122
  Cache.prototype.isCached = function () {
143
123
  var cache = this.getCache();
144
124
  return cache && this.uriHash in cache;
@@ -178,10 +158,11 @@ var Cache = /** @class */ (function () {
178
158
  return __awaiter(this, void 0, void 0, function () {
179
159
  var _this = this;
180
160
  return __generator(this, function (_a) {
181
- // If the class was supplied a raw object, just go ahead and bypass the caching system and
182
- // return that.
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.
183
164
  if (typeof this.uri === 'object') {
184
- return [2 /*return*/, this.uri];
165
+ return [2 /*return*/, fetcher_1["default"].validate(this.uri)];
185
166
  }
186
167
  return [2 /*return*/, this.fetcher.load().then(function (spec) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
187
168
  return [2 /*return*/, this.save(spec)];
@@ -1,4 +1,4 @@
1
- import type Oas from 'oas';
2
1
  import type CodeGeneratorLanguage from './language';
2
+ import type Oas from 'oas';
3
3
  export declare type SupportedLanguages = 'js' | 'js-cjs' | 'js-esm' | 'ts';
4
4
  export default function codegen(language: SupportedLanguages, spec: Oas, specPath: string, identifier: string): CodeGeneratorLanguage;
@@ -1,5 +1,5 @@
1
- import type Oas from 'oas';
2
1
  import type Storage from '../storage';
2
+ import type Oas from 'oas';
3
3
  export interface InstallerOptions {
4
4
  /**
5
5
  * Will initiate a dry run install process. Used for simulating installations within a unit test.
@@ -10,6 +10,19 @@ var CodeGeneratorLanguage = /** @class */ (function () {
10
10
  // a `petstore` spec installed on api@4.2.0.
11
11
  var info = spec.getDefinition().info;
12
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
+ }
13
26
  }
14
27
  CodeGeneratorLanguage.prototype.hasRequiredPackages = function () {
15
28
  return Boolean(Object.keys(this.requiredPackages));
@@ -0,0 +1,21 @@
1
+ export declare function formatter(content: string): string;
2
+ /**
3
+ * @see {@link https://www.30secondsofcode.org/js/s/word-wrap}
4
+ */
5
+ export declare function wordWrap(str: string, max?: number): string;
6
+ /**
7
+ * Safely escape some string characters that may break a docblock.
8
+ *
9
+ */
10
+ export declare function docblockEscape(str: string): string;
11
+ /**
12
+ * Convert a string that might contain spaces or special characters to one that can safely be used
13
+ * as a TypeScript interface or enum name.
14
+ *
15
+ * This function has been adapted and slighty modified from `json-schema-to-typescript`.
16
+ *
17
+ * @license MIT
18
+ * @see {@link https://github.com/bcherny/json-schema-to-typescript}
19
+ */
20
+ export declare function toSafeString(str: string): string;
21
+ export declare function generateTypeName(...parts: string[]): string;
@@ -0,0 +1,185 @@
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 = exports.formatter = 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
+ var prettier_1 = require("prettier");
11
+ /**
12
+ * This is a mix of reserved JS words and keywords in TypeScript that might be reserved or
13
+ * allowable but functionally confusing (like `let any = 'buster';`)
14
+ *
15
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar}
16
+ */
17
+ var RESERVED_WORDS = [
18
+ 'abstract',
19
+ 'any',
20
+ 'arguments',
21
+ 'as',
22
+ 'async',
23
+ 'await',
24
+ 'boolean',
25
+ 'break',
26
+ 'byte',
27
+ 'case',
28
+ 'catch',
29
+ 'char',
30
+ 'class',
31
+ 'const',
32
+ 'continue',
33
+ 'constructor',
34
+ 'debugger',
35
+ 'default',
36
+ 'delete',
37
+ 'do',
38
+ 'double',
39
+ 'else',
40
+ 'enum',
41
+ 'eval',
42
+ 'export',
43
+ 'extends',
44
+ 'false',
45
+ 'final',
46
+ 'finally',
47
+ 'float',
48
+ 'for',
49
+ 'from',
50
+ 'function',
51
+ 'get',
52
+ 'goto',
53
+ 'if',
54
+ 'implements',
55
+ 'import',
56
+ 'interface',
57
+ 'in',
58
+ 'instanceof',
59
+ 'int',
60
+ 'let',
61
+ 'long',
62
+ 'native',
63
+ 'new',
64
+ 'null',
65
+ 'number',
66
+ 'of',
67
+ 'package',
68
+ 'private',
69
+ 'protected',
70
+ 'public',
71
+ 'module',
72
+ 'namespace',
73
+ 'return',
74
+ 'set',
75
+ 'short',
76
+ 'static',
77
+ 'string',
78
+ 'super',
79
+ 'switch',
80
+ 'synchronized',
81
+ 'this',
82
+ 'throw',
83
+ 'throws',
84
+ 'transient',
85
+ 'true',
86
+ 'try',
87
+ 'type',
88
+ 'typeof',
89
+ 'var',
90
+ 'void',
91
+ 'while',
92
+ 'with',
93
+ 'volatile',
94
+ 'yield',
95
+ // These aren't reserved keywords but because we maybe codegen'ing an SDK to be used in the
96
+ // browser it'd be very bad if we overwrote these. This obviously doesn't account for browser APIs
97
+ // you can access outside of the `Window` API (like `alert()`), but we can add checks for those
98
+ // later if we need to.
99
+ 'frames',
100
+ 'global',
101
+ 'globalThis',
102
+ 'navigator',
103
+ 'self',
104
+ 'window',
105
+ ];
106
+ function formatter(content) {
107
+ return (0, prettier_1.format)(content, {
108
+ parser: 'typescript',
109
+ printWidth: 100,
110
+ singleQuote: true
111
+ });
112
+ }
113
+ exports.formatter = formatter;
114
+ /**
115
+ * @see {@link https://www.30secondsofcode.org/js/s/word-wrap}
116
+ */
117
+ function wordWrap(str, max) {
118
+ if (max === void 0) { max = 88; }
119
+ return str.replace(new RegExp("(?![^\\n]{1,".concat(max, "}$)([^\\n]{1,").concat(max, "})\\s"), 'g'), '$1\n');
120
+ }
121
+ exports.wordWrap = wordWrap;
122
+ /**
123
+ * Safely escape some string characters that may break a docblock.
124
+ *
125
+ */
126
+ function docblockEscape(str) {
127
+ return str.replace(/\/\*/g, '/\\*').replace(/\*\//g, '*\\/');
128
+ }
129
+ exports.docblockEscape = docblockEscape;
130
+ /**
131
+ * Convert a string that might contain spaces or special characters to one that can safely be used
132
+ * as a TypeScript interface or enum name.
133
+ *
134
+ * This function has been adapted and slighty modified from `json-schema-to-typescript`.
135
+ *
136
+ * @license MIT
137
+ * @see {@link https://github.com/bcherny/json-schema-to-typescript}
138
+ */
139
+ function toSafeString(str) {
140
+ // identifiers in javaScript/ts:
141
+ // First character: a-zA-Z | _ | $
142
+ // Rest: a-zA-Z | _ | $ | 0-9
143
+ // remove accents, umlauts, ... by their basic latin letters
144
+ return ((0, lodash_deburr_1["default"])(str)
145
+ // if the string starts with a number, prefix it with character that typescript can accept
146
+ // https://github.com/bcherny/json-schema-to-typescript/issues/489
147
+ .replace(/^(\d){1}/, '$$1')
148
+ // replace chars which are not valid for typescript identifiers with whitespace
149
+ .replace(/(^\s*[^a-zA-Z_$])|([^a-zA-Z_$\d])/g, ' ')
150
+ // uppercase leading underscores followed by lowercase
151
+ .replace(/^_[a-z]/g, function (match) { return match.toUpperCase(); })
152
+ // remove non-leading underscores followed by lowercase (convert snake_case)
153
+ .replace(/_[a-z]/g, function (match) { return match.substr(1, match.length).toUpperCase(); })
154
+ // uppercase letters after digits, dollars
155
+ .replace(/([\d$]+[a-zA-Z])/g, function (match) { return match.toUpperCase(); })
156
+ // uppercase first letter after whitespace
157
+ .replace(/\s+([a-zA-Z])/g, function (match) { return match.toUpperCase().trim(); })
158
+ // remove remaining whitespace
159
+ .replace(/\s/g, ''));
160
+ }
161
+ exports.toSafeString = toSafeString;
162
+ function generateTypeName() {
163
+ var parts = [];
164
+ for (var _i = 0; _i < arguments.length; _i++) {
165
+ parts[_i] = arguments[_i];
166
+ }
167
+ var str;
168
+ // If the end of our string ends with something like `2XX`, the combination of `startCase` and
169
+ // `camelCase` will transform it into `2Xx`.
170
+ if (parts.length > 1) {
171
+ var last = parts[parts.length - 1];
172
+ if (last.match(/^(\d)XX$/)) {
173
+ str = (0, lodash_startcase_1["default"])((0, lodash_camelcase_1["default"])(parts.slice(0, -1).join(' ')));
174
+ str += " ".concat(last);
175
+ }
176
+ }
177
+ if (!str) {
178
+ str = (0, lodash_startcase_1["default"])((0, lodash_camelcase_1["default"])(parts.join(' ')));
179
+ }
180
+ if (RESERVED_WORDS.includes(str.toLowerCase())) {
181
+ str = "$".concat(str);
182
+ }
183
+ return toSafeString(str);
184
+ }
185
+ exports.generateTypeName = generateTypeName;
@@ -1,11 +1,10 @@
1
- import type Oas from 'oas';
2
- import type { Operation } from 'oas';
3
- import type { JSONSchema, SchemaObject } from 'oas/dist/rmoas.types';
4
- import type { ClassDeclaration, MethodDeclaration, VariableStatement } from 'ts-morph';
5
1
  import type Storage from '../../storage';
6
2
  import type { InstallerOptions } from '../language';
7
- import CodeGeneratorLanguage from '../language';
3
+ import type Oas from 'oas';
4
+ import type { Operation } from 'oas';
5
+ import type { ClassDeclaration } from 'ts-morph';
8
6
  import { Project } from 'ts-morph';
7
+ import CodeGeneratorLanguage from '../language';
9
8
  export declare type TSGeneratorOptions = {
10
9
  outputJS?: boolean;
11
10
  compilerTarget?: 'cjs' | 'esm';
@@ -23,16 +22,14 @@ export default class TSGenerator extends CodeGeneratorLanguage {
23
22
  compilerTarget: 'cjs' | 'esm';
24
23
  types: Map<string, string>;
25
24
  files: Record<string, string>;
26
- methodGenerics: Map<string, MethodDeclaration>;
27
25
  sdk: ClassDeclaration;
28
- sdkExport: VariableStatement;
29
- schemas: Map<string, {
30
- schema: SchemaObject;
31
- name: string;
32
- tsType?: string;
33
- }>;
26
+ schemas: Record<string, {
27
+ body?: any;
28
+ metadata?: any;
29
+ response?: Record<string, any>;
30
+ } | Record<string, any>>;
31
+ usesHTTPMethodRangeInterface: boolean;
34
32
  constructor(spec: Oas, specPath: string, identifier: string, opts?: TSGeneratorOptions);
35
- static formatter(content: string): string;
36
33
  installer(storage: Storage, opts?: InstallerOptions): Promise<void>;
37
34
  /**
38
35
  * Compile the current OpenAPI definition into a TypeScript library.
@@ -42,60 +39,56 @@ export default class TSGenerator extends CodeGeneratorLanguage {
42
39
  [x: string]: string;
43
40
  }>;
44
41
  /**
45
- * Create a generic HTTP method accessor on the SDK.
42
+ * Create our main SDK source file.
46
43
  *
47
- * @param method
48
44
  */
49
- createGenericMethodAccessor(method: string): void;
45
+ createSourceFile(): import("ts-morph").SourceFile;
50
46
  /**
51
- * Create operation accessors on the SDK.
47
+ * Create our main schemas file. This is where all of the JSON Schema that our TypeScript typing
48
+ * infrastructure sources its data from. Without this there are no types.
52
49
  *
53
- * @param operation
54
- * @param operationId
55
- * @param paramTypes
56
- * @param responseTypes
57
50
  */
58
- createOperationAccessor(operation: Operation, operationId: string, paramTypes?: OperationTypeHousing['types']['params'], responseTypes?: OperationTypeHousing['types']['responses']): void;
51
+ createSchemasFile(): import("ts-morph").SourceFile;
59
52
  /**
60
- * Convert a JSON Schema object into a readily available TypeScript type or interface along with
61
- * any `$ref` pointers that are in use and turn those into TS types too.
53
+ * Create our main types file. This sources its data from the JSON Schema `schemas.ts` file and
54
+ * will re-export types to be used in TypeScript implementations and IDE intellisense. This
55
+ * typing work is functional with the `json-schema-to-ts` library.
62
56
  *
63
- * Under the hood this uses https://npm.im/json-schema-to-typescript for all composition and
64
- * conversion.
57
+ * @see {@link https://npm.im/json-schema-to-ts}
58
+ */
59
+ createTypesFile(): import("ts-morph").SourceFile;
60
+ /**
61
+ * Create operation accessors on the SDK.
65
62
  *
66
- * @param schema
67
- * @param name
68
63
  */
69
- convertJSONSchemaToTypescript(schema: JSONSchema, name: string): Promise<{
70
- primaryType: string;
71
- }>;
64
+ createOperationAccessor(operation: Operation, operationId: string, paramTypes?: OperationTypeHousing['types']['params'], responseTypes?: OperationTypeHousing['types']['responses']): void;
72
65
  /**
73
66
  * Scour through the current OpenAPI definition and compile a store of every operation, along
74
67
  * with every HTTP method that's in use, and their available TypeScript types that we can use,
75
68
  * along with every HTTP method that's in use.
76
69
  *
77
70
  */
78
- loadOperationsAndMethods(): Promise<{
71
+ loadOperationsAndMethods(): {
79
72
  operations: Record<string, OperationTypeHousing>;
80
73
  methods: Set<unknown>;
81
- }>;
74
+ };
82
75
  /**
83
76
  * Compile the parameter (path, query, cookie, and header) schemas for an API operation into
84
77
  * usable TypeScript types.
85
78
  *
86
- * @param operation
87
- * @param operationId
88
79
  */
89
80
  prepareParameterTypesForOperation(operation: Operation, operationId: string): false | Record<"formData" | "body" | "metadata", string>;
90
81
  /**
91
82
  * Compile the response schemas for an API operation into usable TypeScript types.
92
83
  *
93
- * @todo what does this do for a spec that has no responses?
94
- * @param operation
95
- * @param operationId
96
84
  */
97
85
  prepareResponseTypesForOperation(operation: Operation, operationId: string): {
98
86
  [x: string]: string;
99
87
  };
88
+ /**
89
+ * Add a given schema into our schema dataset that we'll be be exporting as types.
90
+ *
91
+ */
92
+ addSchemaToExport(schema: any, typeName: string, pointer: string): void;
100
93
  }
101
94
  export {};