api 6.0.0 → 6.1.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/README.md +1 -1
- package/dist/cache.d.ts +4 -1
- package/dist/cli/codegen/languages/typescript/util.d.ts +0 -1
- package/dist/cli/codegen/languages/typescript/util.js +1 -10
- package/dist/cli/codegen/languages/typescript.d.ts +22 -5
- package/dist/cli/codegen/languages/typescript.js +53 -17
- package/dist/cli/commands/install.js +33 -31
- package/dist/cli/storage.d.ts +10 -10
- package/dist/cli/storage.js +14 -1
- package/dist/core/errors/fetchError.d.ts +4 -4
- package/dist/core/getJSONSchemaDefaults.d.ts +0 -1
- package/dist/core/getJSONSchemaDefaults.js +0 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/prepareAuth.d.ts +1 -1
- package/dist/core/prepareParams.js +8 -5
- package/dist/core/prepareServer.d.ts +0 -3
- package/dist/core/prepareServer.js +0 -3
- package/dist/fetcher.js +0 -1
- package/dist/index.js +0 -1
- package/dist/packageInfo.d.ts +1 -1
- package/dist/packageInfo.js +1 -1
- package/package.json +9 -22
- package/src/cache.ts +4 -1
- package/src/cli/codegen/index.ts +1 -1
- package/src/cli/codegen/language.ts +1 -1
- package/src/cli/codegen/languages/typescript/util.ts +0 -9
- package/src/cli/codegen/languages/typescript.ts +89 -27
- package/src/cli/commands/install.ts +14 -17
- package/src/cli/lib/prompt.ts +1 -1
- package/src/cli/storage.ts +27 -10
- package/src/core/errors/fetchError.ts +4 -4
- package/src/core/getJSONSchemaDefaults.ts +2 -3
- package/src/core/index.ts +7 -2
- package/src/core/prepareAuth.ts +4 -4
- package/src/core/prepareParams.ts +15 -10
- package/src/core/prepareServer.ts +0 -3
- package/src/fetcher.ts +2 -3
- package/src/index.ts +0 -1
- package/src/packageInfo.ts +1 -1
- package/tsconfig.json +1 -1
package/src/core/prepareAuth.ts
CHANGED
|
@@ -11,8 +11,8 @@ export default function prepareAuth(authKey: (number | string)[], operation: Ope
|
|
|
11
11
|
| string
|
|
12
12
|
| number
|
|
13
13
|
| {
|
|
14
|
-
user: string | number;
|
|
15
14
|
pass: string | number;
|
|
15
|
+
user: string | number;
|
|
16
16
|
}
|
|
17
17
|
> = {};
|
|
18
18
|
|
|
@@ -26,7 +26,7 @@ export default function prepareAuth(authKey: (number | string)[], operation: Ope
|
|
|
26
26
|
// Does this operation require multiple forms of auth?
|
|
27
27
|
if (security.every(s => Object.keys(s).length > 1)) {
|
|
28
28
|
throw new Error(
|
|
29
|
-
"Sorry, this operation currently requires multiple forms of authentication which this library doesn't yet support."
|
|
29
|
+
"Sorry, this operation currently requires multiple forms of authentication which this library doesn't yet support.",
|
|
30
30
|
);
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -54,7 +54,7 @@ export default function prepareAuth(authKey: (number | string)[], operation: Ope
|
|
|
54
54
|
const schemes = preparedSecurity.Basic.filter(s => usableSecuritySchemes.includes(s._key));
|
|
55
55
|
if (!schemes.length) {
|
|
56
56
|
throw new Error(
|
|
57
|
-
'Credentials for Basic Authentication were supplied but this operation requires another form of auth in that case, which this library does not yet support. This operation does, however, allow supplying a single auth token.'
|
|
57
|
+
'Credentials for Basic Authentication were supplied but this operation requires another form of auth in that case, which this library does not yet support. This operation does, however, allow supplying a single auth token.',
|
|
58
58
|
);
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -101,7 +101,7 @@ export default function prepareAuth(authKey: (number | string)[], operation: Ope
|
|
|
101
101
|
|
|
102
102
|
default:
|
|
103
103
|
throw new Error(
|
|
104
|
-
`Sorry, this API currently uses a security scheme, ${scheme.type}, which this library doesn't yet support
|
|
104
|
+
`Sorry, this API currently uses a security scheme, ${scheme.type}, which this library doesn't yet support.`,
|
|
105
105
|
);
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -32,7 +32,7 @@ function digestParameters(parameters: ParameterObject[]): Record<string, Paramet
|
|
|
32
32
|
throw new Error("The OpenAPI document for this operation wasn't dereferenced before processing.");
|
|
33
33
|
} else if (param.name in prev) {
|
|
34
34
|
throw new Error(
|
|
35
|
-
`The operation you are using has the same parameter, ${param.name}, spread across multiple entry points. We unfortunately can't handle this right now
|
|
35
|
+
`The operation you are using has the same parameter, ${param.name}, spread across multiple entry points. We unfortunately can't handle this right now.`,
|
|
36
36
|
);
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -54,7 +54,7 @@ function isObject(thing: any) {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
function isPrimitive(obj: any) {
|
|
57
|
-
return
|
|
57
|
+
return obj === null || typeof obj === 'number' || typeof obj === 'string';
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
function merge(src: any, target: any) {
|
|
@@ -75,8 +75,8 @@ function merge(src: any, target: any) {
|
|
|
75
75
|
*/
|
|
76
76
|
function processFile(
|
|
77
77
|
paramName: string,
|
|
78
|
-
file: string | ReadStream
|
|
79
|
-
): Promise<{
|
|
78
|
+
file: string | ReadStream,
|
|
79
|
+
): Promise<{ base64: string; buffer: Buffer; filename: string; paramName: string }> {
|
|
80
80
|
if (typeof file === 'string') {
|
|
81
81
|
// In order to support relative pathed files, we need to attempt to resolve them.
|
|
82
82
|
const resolvedFile = path.resolve(file);
|
|
@@ -129,8 +129,8 @@ function processFile(
|
|
|
129
129
|
new TypeError(
|
|
130
130
|
paramName
|
|
131
131
|
? `The data supplied for the \`${paramName}\` request body parameter is not a file handler that we support.`
|
|
132
|
-
: 'The data supplied for the request body payload is not a file handler that we support.'
|
|
133
|
-
)
|
|
132
|
+
: 'The data supplied for the request body payload is not a file handler that we support.',
|
|
133
|
+
),
|
|
134
134
|
);
|
|
135
135
|
}
|
|
136
136
|
|
|
@@ -179,7 +179,7 @@ export default async function prepareParams(operation: Operation, body?: unknown
|
|
|
179
179
|
|
|
180
180
|
if (throwNoParamsError) {
|
|
181
181
|
throw new Error(
|
|
182
|
-
"You supplied metadata and/or body data for this operation but it doesn't have any documented parameters or request payloads. If you think this is an error please contact support for the API you're using."
|
|
182
|
+
"You supplied metadata and/or body data for this operation but it doesn't have any documented parameters or request payloads. If you think this is an error please contact support for the API you're using.",
|
|
183
183
|
);
|
|
184
184
|
}
|
|
185
185
|
}
|
|
@@ -332,6 +332,7 @@ export default async function prepareParams(operation: Operation, body?: unknown
|
|
|
332
332
|
if (typeof metadata === 'object' && !isEmpty(metadata)) {
|
|
333
333
|
if (paramName in metadata) {
|
|
334
334
|
value = metadata[paramName];
|
|
335
|
+
metadataHeaderParam = paramName;
|
|
335
336
|
} else if (param.in === 'header') {
|
|
336
337
|
// Headers are sent case-insensitive so we need to make sure that we're properly
|
|
337
338
|
// matching them when detecting what our incoming payload looks like.
|
|
@@ -379,9 +380,7 @@ export default async function prepareParams(operation: Operation, body?: unknown
|
|
|
379
380
|
// If there's any leftover metadata that hasn't been moved into form data for this request we
|
|
380
381
|
// need to move it or else it'll get tossed.
|
|
381
382
|
if (!isEmpty(metadata)) {
|
|
382
|
-
if (
|
|
383
|
-
params.formData = merge(params.formData, metadata);
|
|
384
|
-
} else if (typeof metadata === 'object') {
|
|
383
|
+
if (typeof metadata === 'object') {
|
|
385
384
|
// If the user supplied an `accept` or `authorization` header themselves we should allow it
|
|
386
385
|
// through. Normally these headers are automatically handled by `@readme/oas-to-har` but in
|
|
387
386
|
// the event that maybe the user wants to return XML for an API that normally returns JSON
|
|
@@ -391,8 +390,14 @@ export default async function prepareParams(operation: Operation, body?: unknown
|
|
|
391
390
|
const headerParam = Object.keys(metadata).find(m => m.toLowerCase() === headerName);
|
|
392
391
|
if (headerParam) {
|
|
393
392
|
params.header[headerName] = metadata[headerParam] as string;
|
|
393
|
+
// eslint-disable-next-line no-param-reassign
|
|
394
|
+
delete metadata[headerParam];
|
|
394
395
|
}
|
|
395
396
|
});
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (operation.isFormUrlEncoded()) {
|
|
400
|
+
params.formData = merge(params.formData, metadata);
|
|
396
401
|
} else {
|
|
397
402
|
// Any other remaining unused metadata will be unused because we don't know where to place
|
|
398
403
|
// it in the request.
|
|
@@ -12,9 +12,6 @@ function stripTrailingSlash(url: string) {
|
|
|
12
12
|
* With an SDK server config and an instance of OAS we should extract and prepare the server and
|
|
13
13
|
* any server variables to be supplied to `@readme/oas-to-har`.
|
|
14
14
|
*
|
|
15
|
-
* @param spec
|
|
16
|
-
* @param url
|
|
17
|
-
* @param variables
|
|
18
15
|
*/
|
|
19
16
|
export default function prepareServer(spec: Oas, url: string, variables: Record<string, string | number> = {}) {
|
|
20
17
|
let serverIdx;
|
package/src/fetcher.ts
CHANGED
|
@@ -14,7 +14,6 @@ export default class Fetcher {
|
|
|
14
14
|
* @example @petstore/v1.0#n6kvf10vakpemvplx
|
|
15
15
|
* @example @petstore#n6kvf10vakpemvplx
|
|
16
16
|
*/
|
|
17
|
-
// eslint-disable-next-line unicorn/no-unsafe-regex
|
|
18
17
|
static registryUUIDRegex = /^@(?<project>[a-zA-Z0-9-_]+)(\/?(?<version>.+))?#(?<uuid>[a-z0-9]+)$/;
|
|
19
18
|
|
|
20
19
|
constructor(uri: string | OASDocument) {
|
|
@@ -59,7 +58,7 @@ export default class Fetcher {
|
|
|
59
58
|
async load() {
|
|
60
59
|
if (typeof this.uri !== 'string') {
|
|
61
60
|
throw new TypeError(
|
|
62
|
-
"Something disastrous occurred and a non-string URI was supplied to the Fetcher library. This shouldn't have happened!"
|
|
61
|
+
"Something disastrous occurred and a non-string URI was supplied to the Fetcher library. This shouldn't have happened!",
|
|
63
62
|
);
|
|
64
63
|
}
|
|
65
64
|
|
|
@@ -103,7 +102,7 @@ export default class Fetcher {
|
|
|
103
102
|
|
|
104
103
|
if (!fs.existsSync(file)) {
|
|
105
104
|
throw new Error(
|
|
106
|
-
`Sorry, we were unable to load an API definition from ${file}. Please either supply a URL or a path on your filesystem
|
|
105
|
+
`Sorry, we were unable to load an API definition from ${file}. Please either supply a URL or a path on your filesystem.`,
|
|
107
106
|
);
|
|
108
107
|
}
|
|
109
108
|
|
package/src/index.ts
CHANGED
|
@@ -41,7 +41,6 @@ class Sdk {
|
|
|
41
41
|
* Create dynamic accessors for every operation with a defined operation ID. If an operation
|
|
42
42
|
* does not have an operation ID it can be accessed by its `.method('/path')` accessor instead.
|
|
43
43
|
*
|
|
44
|
-
* @param spec
|
|
45
44
|
*/
|
|
46
45
|
function loadOperations(spec: Oas) {
|
|
47
46
|
return Object.entries(spec.getPaths())
|
package/src/packageInfo.ts
CHANGED
package/tsconfig.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"noImplicitAny": true,
|
|
9
9
|
"outDir": "dist/",
|
|
10
10
|
"paths": {
|
|
11
|
-
// Because this library uses ES2015+ `#private` syntax that would require us to
|
|
11
|
+
// Because this library uses ES2015+ `#private` syntax that would require us to make this
|
|
12
12
|
// library ESM-only we're overloading its types with a `paths` config with this empty file.
|
|
13
13
|
// This isn't a great solution as we're losing type checks where this library is used, but
|
|
14
14
|
// it's far too early in the ESM lifecycle for us to make API an ESM-only library.
|