• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

horiuchi / dtsgenerator / 4311460381

pending completion
4311460381

push

github

GitHub
Merge pull request #552 from horiuchi/update-feature

673 of 775 branches covered (86.84%)

20 of 20 new or added lines in 3 files covered. (100.0%)

1115 of 1225 relevant lines covered (91.02%)

1508.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.81
/src/core/utils.ts
1
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
2
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
3
import Debug from 'debug';
1✔
4
import * as ts from 'typescript';
1✔
5
import { JsonSchemaDraft04 } from './jsonSchemaDraft04';
6
import { JsonSchemaObject } from './type';
7

8
import SimpleTypes = JsonSchemaDraft04.Schema.Definitions.SimpleTypes;
9

10
const debug = Debug('dtsgen');
1✔
11

12
export function toTSType(
1✔
13
    type: string,
14
    debugSource?: JsonSchemaObject
15
): ts.KeywordTypeSyntaxKind | ts.SyntaxKind.NullKeyword | undefined {
16
    switch (type) {
1,026✔
17
        case 'any':
18
            return ts.SyntaxKind.AnyKeyword;
4✔
19
        case 'boolean':
20
            return ts.SyntaxKind.BooleanKeyword;
110✔
21
        case 'integer':
22
            return ts.SyntaxKind.NumberKeyword;
134✔
23
        case 'null':
24
            return ts.SyntaxKind.NullKeyword;
17✔
25
        case 'number':
26
            return ts.SyntaxKind.NumberKeyword;
58✔
27
        case 'string':
28
            return ts.SyntaxKind.StringKeyword;
443✔
29
        case 'undefined':
30
            return ts.SyntaxKind.UndefinedKeyword;
3✔
31
        case 'object':
32
        case 'array':
33
            return undefined;
254✔
34
        case 'file': // 'file' is a valid type only in OpenAPI v2.
35
            return ts.SyntaxKind.UnknownKeyword;
1✔
36
        default:
37
            if (debugSource) {
2!
38
                debug(
2✔
39
                    `toTSType: unknown type: ${JSON.stringify(
40
                        debugSource,
41
                        null,
42
                        2
43
                    )}`
44
                );
45
            }
46
            throw new Error('unknown type: ' + type);
2✔
47
    }
48
}
49

50
export function reduceTypes(types: SimpleTypes[]): SimpleTypes[] {
1✔
51
    if (types.length < 2) {
47✔
52
        return types;
5✔
53
    }
54
    const set = new Set<SimpleTypes>(types);
42✔
55
    return Array.from(set.values());
42✔
56
}
57

58
export function checkValidMIMEType(mime: string): boolean {
1✔
59
    const type = mime.toLowerCase().split(';')[0]?.trim();
66!
60
    if (type == null) {
66!
61
        return false;
×
62
    }
63
    if (
66✔
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;
10✔
74
    }
75
    if (type.startsWith('text/') || type.startsWith('image/')) {
56✔
76
        return true;
8✔
77
    }
78
    return /^application\/(?:[a-z0-9-_.]+\+)?json5?$/.test(type);
48✔
79
}
80

81
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
82
export function mergeSchema(a: any, b: any): boolean {
1✔
83
    if ('$ref' in a || '$ref' in b) {
497✔
84
        a.$ref = b.$ref || a.$ref;
129✔
85
        return false;
129✔
86
    }
87
    Object.keys(b as object).forEach((key: string) => {
368✔
88
        const value = b[key];
580✔
89
        if (a[key] != null && typeof value !== typeof a[key]) {
580!
90
            debug(`mergeSchema warning: type is mismatched, key=${key}`);
×
91
        }
92
        if (Array.isArray(value)) {
580✔
93
            // eslint-disable-next-line @typescript-eslint/no-unsafe-call
94
            a[key] = (a[key] ?? []).concat(value);
27✔
95
        } else if (value != null && typeof value === 'object') {
553✔
96
            a[key] ??= {};
183✔
97
            mergeSchema(a[key], value);
183✔
98
        } else {
99
            a[key] = value;
370✔
100
        }
101
    });
102
    return true;
368✔
103
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc