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/package.json
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-alpha.1",
|
|
4
4
|
"description": "Magical SDK generation from an OpenAPI definition 🪄",
|
|
5
|
-
"main": "./dist/index.js",
|
|
6
|
-
"types": "./dist/index.d.ts",
|
|
7
5
|
"bin": {
|
|
8
6
|
"api": "./bin/api"
|
|
9
7
|
},
|
|
@@ -13,7 +11,7 @@
|
|
|
13
11
|
"lint:types": "tsc --noEmit",
|
|
14
12
|
"prebuild": "rm -rf dist/; npm run version",
|
|
15
13
|
"prepack": "npm run build",
|
|
16
|
-
"test": "vitest --coverage",
|
|
14
|
+
"test": "vitest run --coverage",
|
|
17
15
|
"test:smoke": "vitest --config=vitest-smoketest.config.ts ",
|
|
18
16
|
"version": "node -p \"'// This file is automatically updated by the build script.\\nexport const PACKAGE_NAME = \\'' + require('./package.json').name + '\\';\\nexport const PACKAGE_VERSION = \\'' + require('./package.json').version + '\\';'\" > src/packageInfo.ts; git add src/packageInfo.ts"
|
|
19
17
|
},
|
|
@@ -29,7 +27,7 @@
|
|
|
29
27
|
"author": "Jon Ursenbach <jon@readme.io>",
|
|
30
28
|
"license": "MIT",
|
|
31
29
|
"engines": {
|
|
32
|
-
"node": ">=
|
|
30
|
+
"node": ">=18"
|
|
33
31
|
},
|
|
34
32
|
"keywords": [
|
|
35
33
|
"api",
|
|
@@ -38,62 +36,46 @@
|
|
|
38
36
|
"swagger"
|
|
39
37
|
],
|
|
40
38
|
"dependencies": {
|
|
41
|
-
"@readme/oas-to-har": "^20.0.2",
|
|
42
39
|
"@readme/openapi-parser": "^2.4.0",
|
|
43
|
-
"caseless": "^0.12.0",
|
|
44
40
|
"chalk": "^4.1.2",
|
|
45
|
-
"commander": "^
|
|
46
|
-
"datauri": "^4.1.0",
|
|
41
|
+
"commander": "^11.0.0",
|
|
47
42
|
"execa": "^5.1.1",
|
|
48
|
-
"fetch-har": "^8.1.5",
|
|
49
43
|
"figures": "^3.2.0",
|
|
50
|
-
"find-cache-dir": "^3.3.1",
|
|
51
|
-
"form-data-encoder": "^1.7.2",
|
|
52
|
-
"formdata-node": "^4.3.2",
|
|
53
|
-
"get-stream": "^6.0.1",
|
|
54
|
-
"isomorphic-fetch": "^3.0.0",
|
|
55
44
|
"js-yaml": "^4.1.0",
|
|
56
|
-
"json-schema-to-ts": "^2.
|
|
57
|
-
"json-schema-traverse": "^1.0.0",
|
|
45
|
+
"json-schema-to-ts": "^2.9.2",
|
|
58
46
|
"lodash.camelcase": "^4.3.0",
|
|
59
47
|
"lodash.deburr": "^4.1.0",
|
|
60
|
-
"lodash.merge": "^4.6.2",
|
|
61
48
|
"lodash.setwith": "^4.3.2",
|
|
62
49
|
"lodash.startcase": "^4.4.0",
|
|
63
50
|
"make-dir": "^3.1.0",
|
|
64
|
-
"node-abort-controller": "^3.1.1",
|
|
65
51
|
"oas": "^20.4.0",
|
|
66
52
|
"ora": "^5.4.1",
|
|
67
53
|
"prompts": "^2.4.2",
|
|
68
|
-
"remove-undefined-objects": "^2.0.2",
|
|
69
54
|
"semver": "^7.3.8",
|
|
70
55
|
"ssri": "^10.0.1",
|
|
71
56
|
"ts-morph": "^17.0.1",
|
|
72
57
|
"validate-npm-package-name": "^5.0.0"
|
|
73
58
|
},
|
|
74
59
|
"devDependencies": {
|
|
75
|
-
"@
|
|
76
|
-
"@
|
|
77
|
-
"@
|
|
60
|
+
"@api/test-utils": "file:../test-utils",
|
|
61
|
+
"@readme/api-core": "file:../core",
|
|
62
|
+
"@readme/oas-examples": "^5.12.0",
|
|
78
63
|
"@types/js-yaml": "^4.0.5",
|
|
79
64
|
"@types/lodash.camelcase": "^4.3.7",
|
|
80
65
|
"@types/lodash.deburr": "^4.1.7",
|
|
81
|
-
"@types/lodash.merge": "^4.6.7",
|
|
82
66
|
"@types/lodash.setwith": "^4.3.7",
|
|
83
67
|
"@types/lodash.startcase": "^4.4.7",
|
|
84
|
-
"@types/
|
|
85
|
-
"@types/
|
|
86
|
-
"@types/semver": "^7.3.13",
|
|
68
|
+
"@types/prompts": "^2.4.4",
|
|
69
|
+
"@types/semver": "^7.5.1",
|
|
87
70
|
"@types/ssri": "^7.1.1",
|
|
88
71
|
"@types/validate-npm-package-name": "^4.0.0",
|
|
89
|
-
"@vitest/coverage-v8": "^0.34.
|
|
72
|
+
"@vitest/coverage-v8": "^0.34.4",
|
|
90
73
|
"fetch-mock": "^9.11.0",
|
|
91
74
|
"oas-normalize": "^8.3.2",
|
|
92
|
-
"type-fest": "^4.
|
|
93
|
-
"typescript": "^
|
|
75
|
+
"type-fest": "^4.3.1",
|
|
76
|
+
"typescript": "^5.2.2",
|
|
94
77
|
"unique-temp-dir": "^1.0.0",
|
|
95
78
|
"vitest": "^0.34.1"
|
|
96
79
|
},
|
|
97
|
-
"prettier": "@readme/eslint-config/prettier"
|
|
98
|
-
"gitHead": "e440a28841e753895bfb5315b4d31f679824fa39"
|
|
80
|
+
"prettier": "@readme/eslint-config/prettier"
|
|
99
81
|
}
|
package/src/bin.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type Storage from '../storage';
|
|
2
2
|
import type Oas from 'oas';
|
|
3
3
|
|
|
4
|
-
import { PACKAGE_NAME, PACKAGE_VERSION } from '
|
|
4
|
+
import { PACKAGE_NAME, PACKAGE_VERSION } from '../packageInfo';
|
|
5
5
|
|
|
6
6
|
export interface InstallerOptions {
|
|
7
7
|
/**
|
|
@@ -25,11 +25,12 @@ export default abstract class CodeGeneratorLanguage {
|
|
|
25
25
|
|
|
26
26
|
userAgent: string;
|
|
27
27
|
|
|
28
|
-
requiredPackages
|
|
28
|
+
requiredPackages!: Record<string, { reason: string; url: string }>;
|
|
29
29
|
|
|
30
30
|
constructor(spec: Oas, specPath: string, identifier: string) {
|
|
31
31
|
this.spec = spec;
|
|
32
32
|
this.specPath = specPath;
|
|
33
|
+
this.identifier = identifier;
|
|
33
34
|
|
|
34
35
|
// User agents should be contextual to the spec in question and the version of `api` that was
|
|
35
36
|
// used to generate the SDK. For example, this'll look like `petstore/1.0.0 (api/4.2.0)` for
|
|
@@ -123,7 +123,7 @@ export function docblockEscape(str: string) {
|
|
|
123
123
|
* @license MIT
|
|
124
124
|
* @see {@link https://github.com/bcherny/json-schema-to-typescript}
|
|
125
125
|
*/
|
|
126
|
-
|
|
126
|
+
function toSafeString(str: string) {
|
|
127
127
|
// identifiers in javaScript/ts:
|
|
128
128
|
// First character: a-zA-Z | _ | $
|
|
129
129
|
// Rest: a-zA-Z | _ | $ | 0-9
|
|
@@ -3,6 +3,7 @@ import type { InstallerOptions } from '../language';
|
|
|
3
3
|
import type Oas from 'oas';
|
|
4
4
|
import type { Operation } from 'oas';
|
|
5
5
|
import type { HttpMethods, SchemaObject } from 'oas/dist/rmoas.types';
|
|
6
|
+
import type { SemVer } from 'semver';
|
|
6
7
|
import type {
|
|
7
8
|
ClassDeclaration,
|
|
8
9
|
JSDocStructure,
|
|
@@ -12,8 +13,8 @@ import type {
|
|
|
12
13
|
} from 'ts-morph';
|
|
13
14
|
import type { PackageJson } from 'type-fest';
|
|
14
15
|
|
|
15
|
-
import fs from 'fs';
|
|
16
|
-
import path from 'path';
|
|
16
|
+
import fs from 'node:fs';
|
|
17
|
+
import path from 'node:path';
|
|
17
18
|
|
|
18
19
|
import execa from 'execa';
|
|
19
20
|
import setWith from 'lodash.setwith';
|
|
@@ -53,20 +54,18 @@ export default class TSGenerator extends CodeGeneratorLanguage {
|
|
|
53
54
|
|
|
54
55
|
types: Map<string, string>;
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
sdk: ClassDeclaration;
|
|
57
|
+
sdk!: ClassDeclaration;
|
|
59
58
|
|
|
60
59
|
schemas: Record<
|
|
61
60
|
string,
|
|
62
61
|
// Operation-level type
|
|
63
62
|
| {
|
|
64
|
-
body?:
|
|
65
|
-
metadata?:
|
|
66
|
-
response?: Record<string,
|
|
63
|
+
body?: unknown;
|
|
64
|
+
metadata?: unknown;
|
|
65
|
+
response?: Record<string, unknown>;
|
|
67
66
|
}
|
|
68
67
|
// Wholesale collection of `$ref` pointer types
|
|
69
|
-
| Record<string,
|
|
68
|
+
| Record<string, unknown>
|
|
70
69
|
>;
|
|
71
70
|
|
|
72
71
|
usesHTTPMethodRangeInterface = false;
|
|
@@ -87,15 +86,15 @@ export default class TSGenerator extends CodeGeneratorLanguage {
|
|
|
87
86
|
|
|
88
87
|
this.requiredPackages = {
|
|
89
88
|
api: {
|
|
90
|
-
reason: "Required for the
|
|
89
|
+
reason: "Required for the `@readme/api-core` library that the codegen'd SDK uses for making requests.",
|
|
91
90
|
url: 'https://npm.im/api',
|
|
92
91
|
},
|
|
93
|
-
'json-schema-to-ts
|
|
92
|
+
'json-schema-to-ts': {
|
|
94
93
|
reason: 'Required for TypeScript type handling.',
|
|
95
94
|
url: 'https://npm.im/json-schema-to-ts',
|
|
96
95
|
},
|
|
97
96
|
oas: {
|
|
98
|
-
reason: 'Used within
|
|
97
|
+
reason: 'Used within `@readme/api-core` and is also loaded for TypeScript types.',
|
|
99
98
|
url: 'https://npm.im/oas',
|
|
100
99
|
},
|
|
101
100
|
};
|
|
@@ -138,7 +137,7 @@ export default class TSGenerator extends CodeGeneratorLanguage {
|
|
|
138
137
|
if (!pkgVersion) {
|
|
139
138
|
// If the version that's in `info.version` isn't compatible with semver NPM won't be able to
|
|
140
139
|
// handle it properly so we need to fallback to something it can.
|
|
141
|
-
pkgVersion = semver.coerce('0.0.0');
|
|
140
|
+
pkgVersion = semver.coerce('0.0.0') as SemVer;
|
|
142
141
|
}
|
|
143
142
|
|
|
144
143
|
const pkg: PackageJson = {
|
|
@@ -221,7 +220,7 @@ export default class TSGenerator extends CodeGeneratorLanguage {
|
|
|
221
220
|
sdkSource
|
|
222
221
|
.getImportDeclarations()
|
|
223
222
|
.find(id => id.getText() === "import type * as types from './types';")
|
|
224
|
-
|
|
223
|
+
?.remove();
|
|
225
224
|
}
|
|
226
225
|
|
|
227
226
|
// If this SDK doesn't use the `HTTPMethodRange` interface for handling `2XX` response status
|
|
@@ -230,7 +229,7 @@ export default class TSGenerator extends CodeGeneratorLanguage {
|
|
|
230
229
|
sdkSource
|
|
231
230
|
.getImportDeclarations()
|
|
232
231
|
.find(id => id.getText().includes('HTTPMethodRange'))
|
|
233
|
-
|
|
232
|
+
?.replaceWithText("import type { ConfigOptions, FetchResponse } from '@readme/api-core';");
|
|
234
233
|
}
|
|
235
234
|
|
|
236
235
|
if (this.outputJS) {
|
|
@@ -301,10 +300,10 @@ export default class TSGenerator extends CodeGeneratorLanguage {
|
|
|
301
300
|
{
|
|
302
301
|
// `HTTPMethodRange` will be conditionally removed later if it ends up not being used.
|
|
303
302
|
defaultImport: 'type { ConfigOptions, FetchResponse, HTTPMethodRange }',
|
|
304
|
-
moduleSpecifier: 'api
|
|
303
|
+
moduleSpecifier: '@readme/api-core',
|
|
305
304
|
},
|
|
306
305
|
{ defaultImport: 'Oas', moduleSpecifier: 'oas' },
|
|
307
|
-
{ defaultImport: 'APICore', moduleSpecifier: 'api
|
|
306
|
+
{ defaultImport: 'APICore', moduleSpecifier: '@readme/api-core' },
|
|
308
307
|
{ defaultImport: 'definition', moduleSpecifier: this.specPath },
|
|
309
308
|
]);
|
|
310
309
|
|
|
@@ -566,10 +565,10 @@ sdk.server('https://eu.api.example.com/v14');`),
|
|
|
566
565
|
|
|
567
566
|
let hasOptionalBody = false;
|
|
568
567
|
let hasOptionalMetadata = false;
|
|
569
|
-
const parameters
|
|
570
|
-
body
|
|
571
|
-
metadata
|
|
572
|
-
}
|
|
568
|
+
const parameters = {} as {
|
|
569
|
+
body: OptionalKind<ParameterDeclarationStructure>;
|
|
570
|
+
metadata: OptionalKind<ParameterDeclarationStructure>;
|
|
571
|
+
};
|
|
573
572
|
|
|
574
573
|
if (paramTypes) {
|
|
575
574
|
// If an operation has a request body payload it will only ever have `body` or `formData`,
|
|
@@ -656,7 +655,7 @@ sdk.server('https://eu.api.example.com/v14');`),
|
|
|
656
655
|
// we should only add a docblock to the first overload we create because IDE Intellisense will
|
|
657
656
|
// always use that and adding a docblock to all three will bloat the SDK with unused and
|
|
658
657
|
// unsurfaced method documentation.
|
|
659
|
-
docs: shouldAddAltTypedOverloads ?
|
|
658
|
+
docs: shouldAddAltTypedOverloads ? undefined : Object.keys(docblock).length ? [docblock] : undefined,
|
|
660
659
|
statements: writer => {
|
|
661
660
|
/**
|
|
662
661
|
* @example return this.core.fetch('/pet/findByStatus', 'get', body, metadata);
|
|
@@ -698,7 +697,7 @@ sdk.server('https://eu.api.example.com/v14');`),
|
|
|
698
697
|
{ ...parameters.metadata, hasQuestionToken: false },
|
|
699
698
|
],
|
|
700
699
|
returnType,
|
|
701
|
-
docs: Object.keys(docblock).length ? [docblock] :
|
|
700
|
+
docs: Object.keys(docblock).length ? [docblock] : undefined,
|
|
702
701
|
});
|
|
703
702
|
|
|
704
703
|
// Create an overload that just has a single `metadata` parameter.
|
|
@@ -711,7 +710,7 @@ sdk.server('https://eu.api.example.com/v14');`),
|
|
|
711
710
|
// our `metadata` parameter is actually required for this operation this is the only way we're
|
|
712
711
|
// able to have an optional `body` parameter be present before `metadata`.
|
|
713
712
|
//
|
|
714
|
-
// Thankfully our core fetch work in
|
|
713
|
+
// Thankfully our core fetch work in `@readme/api-core` is able to do the proper determination to
|
|
715
714
|
// see if what the user is supplying is `metadata` or `body` content when they supply one or
|
|
716
715
|
// both.
|
|
717
716
|
operationIdAccessor.addParameters([
|
|
@@ -739,13 +738,13 @@ sdk.server('https://eu.api.example.com/v14');`),
|
|
|
739
738
|
*/
|
|
740
739
|
loadOperationsAndMethods() {
|
|
741
740
|
const operations: Record</* operationId */ string, OperationTypeHousing> = {};
|
|
742
|
-
const methods = new Set();
|
|
741
|
+
const methods = new Set<HttpMethods>();
|
|
743
742
|
|
|
744
743
|
// Prepare all of the schemas that we need to process for every operation within this API
|
|
745
744
|
// definition.
|
|
746
745
|
Object.entries(this.spec.getPaths()).forEach(([, ops]) => {
|
|
747
|
-
Object.entries(ops).forEach(([method, operation]: [
|
|
748
|
-
methods.add(method);
|
|
746
|
+
Object.entries(ops).forEach(([method, operation]: [string, Operation]) => {
|
|
747
|
+
methods.add(method as HttpMethods);
|
|
749
748
|
|
|
750
749
|
const operationId = operation.getOperationId({
|
|
751
750
|
// This `camelCase` option will clean up any weird characters that might be present in
|
|
@@ -786,7 +785,7 @@ sdk.server('https://eu.api.example.com/v14');`),
|
|
|
786
785
|
transformer: (s: SchemaObject) => {
|
|
787
786
|
// As our schemas are dereferenced in the `oas` library we don't want to pollute our
|
|
788
787
|
// codegen'd schemas file with duplicate schemas.
|
|
789
|
-
if ('x-readme-ref-name' in s) {
|
|
788
|
+
if ('x-readme-ref-name' in s && typeof s['x-readme-ref-name'] !== 'undefined') {
|
|
790
789
|
const typeName = generateTypeName(s['x-readme-ref-name']);
|
|
791
790
|
this.addSchemaToExport(s, typeName, typeName);
|
|
792
791
|
|
|
@@ -806,7 +805,7 @@ sdk.server('https://eu.api.example.com/v14');`),
|
|
|
806
805
|
.reduce((prev, next) => Object.assign(prev, next));
|
|
807
806
|
|
|
808
807
|
return Object.entries(res)
|
|
809
|
-
.map(([paramType, schema]: [string, string |
|
|
808
|
+
.map(([paramType, schema]: [string, string | SchemaObject]) => {
|
|
810
809
|
let typeName;
|
|
811
810
|
|
|
812
811
|
if (typeof schema === 'string' && schema.startsWith('::convert::')) {
|
|
@@ -815,7 +814,7 @@ sdk.server('https://eu.api.example.com/v14');`),
|
|
|
815
814
|
typeName = schema.replace('::convert::', '');
|
|
816
815
|
} else {
|
|
817
816
|
typeName = generateTypeName(operationId, paramType, 'param');
|
|
818
|
-
this.addSchemaToExport(schema, typeName, `${generateTypeName(operationId)}.${paramType}`);
|
|
817
|
+
this.addSchemaToExport(schema as SchemaObject, typeName, `${generateTypeName(operationId)}.${paramType}`);
|
|
819
818
|
}
|
|
820
819
|
|
|
821
820
|
return {
|
|
@@ -844,7 +843,7 @@ sdk.server('https://eu.api.example.com/v14');`),
|
|
|
844
843
|
transformer: (s: SchemaObject) => {
|
|
845
844
|
// As our schemas are dereferenced in the `oas` library we don't want to pollute our
|
|
846
845
|
// codegen'd schemas file with duplicate schemas.
|
|
847
|
-
if ('x-readme-ref-name' in s) {
|
|
846
|
+
if ('x-readme-ref-name' in s && typeof s['x-readme-ref-name'] !== 'undefined') {
|
|
848
847
|
const typeName = generateTypeName(s['x-readme-ref-name']);
|
|
849
848
|
this.addSchemaToExport(s, typeName, `${typeName}`);
|
|
850
849
|
|
|
@@ -900,7 +899,7 @@ sdk.server('https://eu.api.example.com/v14');`),
|
|
|
900
899
|
* Add a given schema into our schema dataset that we'll be be exporting as types.
|
|
901
900
|
*
|
|
902
901
|
*/
|
|
903
|
-
addSchemaToExport(schema:
|
|
902
|
+
addSchemaToExport(schema: SchemaObject, typeName: string, pointer: string) {
|
|
904
903
|
if (this.types.has(typeName)) {
|
|
905
904
|
return;
|
|
906
905
|
}
|
|
@@ -5,8 +5,8 @@ import figures from 'figures';
|
|
|
5
5
|
import Oas from 'oas';
|
|
6
6
|
import ora from 'ora';
|
|
7
7
|
|
|
8
|
-
import Fetcher from '../../fetcher';
|
|
9
8
|
import codegen from '../codegen';
|
|
9
|
+
import Fetcher from '../fetcher';
|
|
10
10
|
import promptTerminal from '../lib/prompt';
|
|
11
11
|
import logger from '../logger';
|
|
12
12
|
import Storage from '../storage';
|
package/src/fetcher.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { OASDocument } from 'oas/dist/rmoas.types';
|
|
2
2
|
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import path from 'path';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
5
|
|
|
6
6
|
import OpenAPIParser from '@readme/openapi-parser';
|
|
7
|
-
import 'isomorphic-fetch';
|
|
8
7
|
import yaml from 'js-yaml';
|
|
9
8
|
|
|
10
9
|
export default class Fetcher {
|
|
@@ -52,7 +51,7 @@ export default class Fetcher {
|
|
|
52
51
|
return undefined;
|
|
53
52
|
}
|
|
54
53
|
|
|
55
|
-
return matches.groups
|
|
54
|
+
return matches.groups?.project;
|
|
56
55
|
}
|
|
57
56
|
|
|
58
57
|
async load() {
|
|
@@ -115,7 +114,7 @@ export default class Fetcher {
|
|
|
115
114
|
});
|
|
116
115
|
}
|
|
117
116
|
|
|
118
|
-
static validate(json:
|
|
117
|
+
static validate(json: OASDocument) {
|
|
119
118
|
if (json.swagger) {
|
|
120
119
|
throw new Error('Sorry, this module only supports OpenAPI definitions.');
|
|
121
120
|
}
|
package/src/packageInfo.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { OASDocument } from 'oas/dist/rmoas.types';
|
|
2
2
|
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import path from 'path';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
5
|
|
|
6
6
|
import makeDir from 'make-dir';
|
|
7
7
|
import ssri from 'ssri';
|
|
8
8
|
import validateNPMPackageName from 'validate-npm-package-name';
|
|
9
9
|
|
|
10
|
-
import Fetcher from '
|
|
11
|
-
import { PACKAGE_VERSION } from '
|
|
10
|
+
import Fetcher from './fetcher';
|
|
11
|
+
import { PACKAGE_VERSION } from './packageInfo';
|
|
12
12
|
|
|
13
13
|
export default class Storage {
|
|
14
14
|
static dir: string;
|
|
@@ -21,7 +21,7 @@ export default class Storage {
|
|
|
21
21
|
*/
|
|
22
22
|
source: string;
|
|
23
23
|
|
|
24
|
-
identifier
|
|
24
|
+
identifier!: string;
|
|
25
25
|
|
|
26
26
|
fetcher: Fetcher;
|
|
27
27
|
|
|
@@ -31,7 +31,9 @@ export default class Storage {
|
|
|
31
31
|
this.fetcher = new Fetcher(source);
|
|
32
32
|
|
|
33
33
|
this.source = source;
|
|
34
|
-
|
|
34
|
+
if (identifier) {
|
|
35
|
+
this.identifier = identifier;
|
|
36
|
+
}
|
|
35
37
|
|
|
36
38
|
// This should default to false so we have awareness if we've looked at the lockfile yet.
|
|
37
39
|
Storage.lockfile = false;
|
|
@@ -116,7 +118,9 @@ export default class Storage {
|
|
|
116
118
|
if (!isValidForNPM.validForNewPackages) {
|
|
117
119
|
// `prompts` doesn't support surfacing multiple errors in a `validate` call so we can only
|
|
118
120
|
// surface the first to the user.
|
|
119
|
-
throw new Error(
|
|
121
|
+
throw new Error(
|
|
122
|
+
`Identifier cannot be used for an NPM package: ${isValidForNPM?.errors?.[0] || '[error unavailable]'}`,
|
|
123
|
+
);
|
|
120
124
|
}
|
|
121
125
|
|
|
122
126
|
return true;
|
|
@@ -269,7 +273,7 @@ export default class Storage {
|
|
|
269
273
|
}
|
|
270
274
|
}
|
|
271
275
|
|
|
272
|
-
|
|
276
|
+
interface Lockfile {
|
|
273
277
|
apis: LockfileAPI[];
|
|
274
278
|
|
|
275
279
|
/**
|
|
@@ -279,7 +283,7 @@ export interface Lockfile {
|
|
|
279
283
|
version: '1.0';
|
|
280
284
|
}
|
|
281
285
|
|
|
282
|
-
|
|
286
|
+
interface LockfileAPI {
|
|
283
287
|
/**
|
|
284
288
|
* A unique identifier of the API. This'll be used to do requires on `@api/<identifier>` and also
|
|
285
289
|
* where the SDK code will be located in `.api/apis/<identifier>`.
|
package/tsconfig.json
CHANGED
|
@@ -4,21 +4,11 @@
|
|
|
4
4
|
"baseUrl": "./src",
|
|
5
5
|
"declaration": true,
|
|
6
6
|
"esModuleInterop": true,
|
|
7
|
-
"lib": ["
|
|
7
|
+
"lib": ["DOM", "DOM.Iterable", "ES2020"],
|
|
8
8
|
"noImplicitAny": true,
|
|
9
9
|
"outDir": "dist/",
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
// library ESM-only we're overloading its types with a `paths` config with this empty file.
|
|
13
|
-
// This isn't a great solution as we're losing type checks where this library is used, but
|
|
14
|
-
// it's far too early in the ESM lifecycle for us to make API an ESM-only library.
|
|
15
|
-
//
|
|
16
|
-
// And though TS offers an unstable `node12` module resolution that lets us manage this in
|
|
17
|
-
// another way that module resolution requires TS nightlies to be installed, which no thanks!
|
|
18
|
-
//
|
|
19
|
-
// https://github.com/microsoft/TypeScript/issues/17042
|
|
20
|
-
"form-data-encoder": [".sink.d.ts"]
|
|
21
|
-
}
|
|
10
|
+
"strict": true,
|
|
11
|
+
"useUnknownInCatchVariables": false
|
|
22
12
|
},
|
|
23
13
|
"include": ["./src/**/*"]
|
|
24
14
|
}
|
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 {};
|