dtsgenerator 3.16.2 → 3.18.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.
- package/README.md +11 -1
- package/dist/cli.js +1 -0
- package/dist/core/jsonSchema.js +2 -1
- package/dist/core/utils.d.ts +1 -0
- package/dist/core/utils.js +22 -1
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +13 -10
- package/package.json +12 -13
- package/src/cli.ts +1 -0
- package/src/core/jsonSchema.ts +2 -5
- package/src/core/utils.ts +23 -0
- package/src/utils.ts +14 -11
package/README.md
CHANGED
|
@@ -143,7 +143,17 @@ Output debug message by [debug](https://www.npmjs.com/package/debug) library.
|
|
|
143
143
|
|
|
144
144
|
## ChangeLog
|
|
145
145
|
|
|
146
|
-
### [v3.
|
|
146
|
+
### [v3.18.0](https://github.com/horiuchi/dtsgenerator/releases/tag/v3.18.0) (2023-03-02)
|
|
147
|
+
|
|
148
|
+
- features:
|
|
149
|
+
- Support 'application/json' with parameter media type for #551. Thank you @denizkenan :+1:
|
|
150
|
+
|
|
151
|
+
### [v3.17.0](https://github.com/horiuchi/dtsgenerator/releases/tag/v3.17.0) (2023-02-21)
|
|
152
|
+
|
|
153
|
+
- features:
|
|
154
|
+
- Return exit code 1 when error occurs by #549. Thank you @lhotamir :+1:
|
|
155
|
+
|
|
156
|
+
### [v3.16.2](https://github.com/horiuchi/dtsgenerator/releases/tag/v3.16.2) (2022-12-20)
|
|
147
157
|
|
|
148
158
|
- fixed:
|
|
149
159
|
- Fix to remove deprecated decorators parameters for #547. Thank you @mcollina :+1:
|
package/dist/cli.js
CHANGED
package/dist/core/jsonSchema.js
CHANGED
|
@@ -5,6 +5,7 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const JsonPointer = tslib_1.__importStar(require("../jsonPointer"));
|
|
6
6
|
const schemaId_1 = tslib_1.__importDefault(require("./schemaId"));
|
|
7
7
|
const type_1 = require("./type");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
8
9
|
function getSubSchema(rootSchema, pointer, id) {
|
|
9
10
|
const content = JsonPointer.get(rootSchema.content, JsonPointer.parse(pointer));
|
|
10
11
|
if (id == null) {
|
|
@@ -258,7 +259,7 @@ function searchAllSubSchema(schema, onFoundSchema, onFoundReference) {
|
|
|
258
259
|
return;
|
|
259
260
|
}
|
|
260
261
|
for (const mime of Object.keys(types)) {
|
|
261
|
-
if (
|
|
262
|
+
if ((0, utils_1.checkValidMIMEType)(mime)) {
|
|
262
263
|
const mt = types[mime];
|
|
263
264
|
if (mt != null) {
|
|
264
265
|
setSubId(mt.schema, keys);
|
package/dist/core/utils.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ import { JsonSchemaObject } from './type';
|
|
|
4
4
|
import SimpleTypes = JsonSchemaDraft04.Schema.Definitions.SimpleTypes;
|
|
5
5
|
export declare function toTSType(type: string, debugSource?: JsonSchemaObject): ts.KeywordTypeSyntaxKind | ts.SyntaxKind.NullKeyword | undefined;
|
|
6
6
|
export declare function reduceTypes(types: SimpleTypes[]): SimpleTypes[];
|
|
7
|
+
export declare function checkValidMIMEType(mime: string): boolean;
|
|
7
8
|
export declare function mergeSchema(a: any, b: any): boolean;
|
package/dist/core/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mergeSchema = exports.reduceTypes = exports.toTSType = void 0;
|
|
3
|
+
exports.mergeSchema = exports.checkValidMIMEType = exports.reduceTypes = exports.toTSType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
6
6
|
const ts = tslib_1.__importStar(require("typescript"));
|
|
@@ -42,6 +42,27 @@ function reduceTypes(types) {
|
|
|
42
42
|
return Array.from(set.values());
|
|
43
43
|
}
|
|
44
44
|
exports.reduceTypes = reduceTypes;
|
|
45
|
+
function checkValidMIMEType(mime) {
|
|
46
|
+
var _a;
|
|
47
|
+
const type = (_a = mime.toLowerCase().split(';')[0]) === null || _a === void 0 ? void 0 : _a.trim();
|
|
48
|
+
if (type == null) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
if ([
|
|
52
|
+
'application/octet-stream',
|
|
53
|
+
'application/x-www-form-urlencoded',
|
|
54
|
+
'multipart/form-data',
|
|
55
|
+
'application/jwt',
|
|
56
|
+
'application/vnd.apple.pkpass',
|
|
57
|
+
].includes(type)) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
if (type.startsWith('text/') || type.startsWith('image/')) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
return /^application\/(?:[a-z0-9-_.]+\+)?json5?$/.test(type);
|
|
64
|
+
}
|
|
65
|
+
exports.checkValidMIMEType = checkValidMIMEType;
|
|
45
66
|
function mergeSchema(a, b) {
|
|
46
67
|
if ('$ref' in a || '$ref' in b) {
|
|
47
68
|
a.$ref = b.$ref || a.$ref;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import
|
|
3
|
+
import { GlobOptions } from 'glob';
|
|
4
4
|
import { CommandOptions } from './commandOptions';
|
|
5
5
|
import { PartialConfig } from './core/config';
|
|
6
6
|
export declare function readStream(stream: NodeJS.ReadableStream, encoding?: BufferEncoding): Promise<string>;
|
|
7
7
|
export declare function readUrl(url: string): Promise<string>;
|
|
8
8
|
export declare function buildProxyOptions(url: string): RequestInit | undefined;
|
|
9
|
-
export declare function globFiles(pattern: string, options?:
|
|
9
|
+
export declare function globFiles(pattern: string, options?: GlobOptions): Promise<string[]>;
|
|
10
10
|
export declare function readConfig(options: CommandOptions): PartialConfig;
|
package/dist/utils.js
CHANGED
|
@@ -62,16 +62,15 @@ function buildProxyOptions(url) {
|
|
|
62
62
|
return undefined;
|
|
63
63
|
}
|
|
64
64
|
exports.buildProxyOptions = buildProxyOptions;
|
|
65
|
-
function globFiles(pattern, options) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
});
|
|
65
|
+
async function globFiles(pattern, options) {
|
|
66
|
+
const res = await (0, glob_1.default)(pattern, options !== null && options !== void 0 ? options : {});
|
|
67
|
+
return res.map((r) => {
|
|
68
|
+
if (typeof r === 'string') {
|
|
69
|
+
return r;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
return r.fullpath();
|
|
73
|
+
}
|
|
75
74
|
});
|
|
76
75
|
}
|
|
77
76
|
exports.globFiles = globFiles;
|
|
@@ -150,6 +149,10 @@ function convertToScriptTarget(target) {
|
|
|
150
149
|
return typescript_1.ScriptTarget.ES2019;
|
|
151
150
|
case 'es2020':
|
|
152
151
|
return typescript_1.ScriptTarget.ES2020;
|
|
152
|
+
case 'es2021':
|
|
153
|
+
return typescript_1.ScriptTarget.ES2021;
|
|
154
|
+
case 'es2022':
|
|
155
|
+
return typescript_1.ScriptTarget.ES2022;
|
|
153
156
|
case 'esnext':
|
|
154
157
|
return typescript_1.ScriptTarget.ESNext;
|
|
155
158
|
default:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dtsgenerator",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.18.0",
|
|
4
4
|
"description": "TypeScript d.ts file generator for JSON Schema file",
|
|
5
5
|
"bin": {
|
|
6
6
|
"dtsgen": "bin/dtsgen"
|
|
@@ -44,14 +44,14 @@
|
|
|
44
44
|
"node": ">= 14.0"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"commander": "^
|
|
47
|
+
"commander": "^10.0.0",
|
|
48
48
|
"cross-fetch": "^3.1.5",
|
|
49
49
|
"debug": "^4.3.4",
|
|
50
|
-
"glob": "^
|
|
50
|
+
"glob": "^9.1.2",
|
|
51
51
|
"https-proxy-agent": "^5.0.1",
|
|
52
52
|
"js-yaml": "^4.1.0",
|
|
53
|
-
"tslib": "^2.
|
|
54
|
-
"typescript": "^4.9.
|
|
53
|
+
"tslib": "^2.5.0",
|
|
54
|
+
"typescript": "^4.9.5"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@dtsgenerator/do-nothing": "^2.5.3",
|
|
@@ -60,19 +60,18 @@
|
|
|
60
60
|
"@dtsgenerator/single-quote": "^1.6.3",
|
|
61
61
|
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
|
62
62
|
"@types/debug": "^4.1.7",
|
|
63
|
-
"@types/glob": "^8.
|
|
63
|
+
"@types/glob": "^8.1.0",
|
|
64
64
|
"@types/js-yaml": "^4.0.5",
|
|
65
|
-
"@types/mkdirp": "^1.0.2",
|
|
66
65
|
"@types/mocha": "^10.0.1",
|
|
67
|
-
"@types/node": "^16.18.
|
|
66
|
+
"@types/node": "^16.18.14",
|
|
68
67
|
"cross-env": "^7.0.3",
|
|
69
|
-
"eslint": "^8.
|
|
70
|
-
"husky": "^8.0.
|
|
71
|
-
"lint-staged": "^13.1.
|
|
68
|
+
"eslint": "^8.34.0",
|
|
69
|
+
"husky": "^8.0.3",
|
|
70
|
+
"lint-staged": "^13.1.2",
|
|
72
71
|
"mocha": "^10.2.0",
|
|
73
72
|
"nyc": "^15.1.0",
|
|
74
|
-
"prettier": "^2.8.
|
|
75
|
-
"rimraf": "^
|
|
73
|
+
"prettier": "^2.8.4",
|
|
74
|
+
"rimraf": "^4.1.3",
|
|
76
75
|
"source-map-support": "^0.5.21",
|
|
77
76
|
"ts-node": "^10.9.1"
|
|
78
77
|
},
|
package/src/cli.ts
CHANGED
package/src/core/jsonSchema.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
JsonSchema,
|
|
12
12
|
isJsonSchemaDraft04,
|
|
13
13
|
} from './type';
|
|
14
|
+
import { checkValidMIMEType } from './utils';
|
|
14
15
|
|
|
15
16
|
type OpenApiSchema = OpenApisV2.SchemaJson | OpenApisV3.SchemaJson;
|
|
16
17
|
type ParametersList =
|
|
@@ -382,11 +383,7 @@ export function searchAllSubSchema(
|
|
|
382
383
|
return;
|
|
383
384
|
}
|
|
384
385
|
for (const mime of Object.keys(types)) {
|
|
385
|
-
if (
|
|
386
|
-
/^text\/|^(?:application\/x-www-form-urlencoded$|^application\/([a-z0-9-_.]+\+)?json)$|^application\/octet-stream$|^application\/jwt$|^application\/vnd.apple.pkpass$|^multipart\/form-data$|^image\//.test(
|
|
387
|
-
mime
|
|
388
|
-
)
|
|
389
|
-
) {
|
|
386
|
+
if (checkValidMIMEType(mime)) {
|
|
390
387
|
const mt = types[mime];
|
|
391
388
|
if (mt != null) {
|
|
392
389
|
setSubId(mt.schema, keys);
|
package/src/core/utils.ts
CHANGED
|
@@ -55,6 +55,29 @@ export function reduceTypes(types: SimpleTypes[]): SimpleTypes[] {
|
|
|
55
55
|
return Array.from(set.values());
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
export function checkValidMIMEType(mime: string): boolean {
|
|
59
|
+
const type = mime.toLowerCase().split(';')[0]?.trim();
|
|
60
|
+
if (type == null) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
if (
|
|
64
|
+
[
|
|
65
|
+
'application/octet-stream',
|
|
66
|
+
'application/x-www-form-urlencoded',
|
|
67
|
+
'multipart/form-data',
|
|
68
|
+
|
|
69
|
+
'application/jwt',
|
|
70
|
+
'application/vnd.apple.pkpass',
|
|
71
|
+
].includes(type)
|
|
72
|
+
) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
if (type.startsWith('text/') || type.startsWith('image/')) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
return /^application\/(?:[a-z0-9-_.]+\+)?json5?$/.test(type);
|
|
79
|
+
}
|
|
80
|
+
|
|
58
81
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
59
82
|
export function mergeSchema(a: any, b: any): boolean {
|
|
60
83
|
if ('$ref' in a || '$ref' in b) {
|
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import { URL } from 'url';
|
|
3
|
-
import glob from 'glob';
|
|
3
|
+
import glob, { GlobOptions } from 'glob';
|
|
4
4
|
import proxy from 'https-proxy-agent';
|
|
5
5
|
import { ScriptTarget } from 'typescript';
|
|
6
6
|
import { CommandOptions, defaultConfigFile } from './commandOptions';
|
|
@@ -63,18 +63,17 @@ export function buildProxyOptions(url: string): RequestInit | undefined {
|
|
|
63
63
|
return undefined;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
export function globFiles(
|
|
66
|
+
export async function globFiles(
|
|
67
67
|
pattern: string,
|
|
68
|
-
options?:
|
|
68
|
+
options?: GlobOptions
|
|
69
69
|
): Promise<string[]> {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
});
|
|
70
|
+
const res = await glob(pattern, options ?? {});
|
|
71
|
+
return res.map((r) => {
|
|
72
|
+
if (typeof r === 'string') {
|
|
73
|
+
return r;
|
|
74
|
+
} else {
|
|
75
|
+
return r.fullpath();
|
|
76
|
+
}
|
|
78
77
|
});
|
|
79
78
|
}
|
|
80
79
|
|
|
@@ -150,6 +149,10 @@ function convertToScriptTarget(target: string): ScriptTarget {
|
|
|
150
149
|
return ScriptTarget.ES2019;
|
|
151
150
|
case 'es2020':
|
|
152
151
|
return ScriptTarget.ES2020;
|
|
152
|
+
case 'es2021':
|
|
153
|
+
return ScriptTarget.ES2021;
|
|
154
|
+
case 'es2022':
|
|
155
|
+
return ScriptTarget.ES2022;
|
|
153
156
|
case 'esnext':
|
|
154
157
|
return ScriptTarget.ESNext;
|
|
155
158
|
default:
|