@innet/server 2.0.0-beta.14 → 2.0.0-beta.16
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/package.json
CHANGED
|
@@ -28,13 +28,15 @@ const success = () => {
|
|
|
28
28
|
? 'text/plain'
|
|
29
29
|
: 'application/json');
|
|
30
30
|
const content = contentType === 'application/json' ? JSONString(child) : String(child);
|
|
31
|
-
res.setHeader('Content-Type', contentType
|
|
32
|
-
|
|
31
|
+
res.setHeader('Content-Type', contentType === 'application/json'
|
|
32
|
+
? 'application/json; charset=utf-8'
|
|
33
|
+
: contentType);
|
|
34
|
+
res.setHeader('Content-Length', Buffer.byteLength(content));
|
|
33
35
|
if (contentType === 'application/json') {
|
|
34
|
-
res.write(
|
|
36
|
+
res.write(content, 'utf-8');
|
|
35
37
|
}
|
|
36
38
|
else {
|
|
37
|
-
res.write(
|
|
39
|
+
res.write(content);
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
res.end();
|
|
@@ -32,13 +32,15 @@ const success = () => {
|
|
|
32
32
|
? 'text/plain'
|
|
33
33
|
: 'application/json');
|
|
34
34
|
const content = contentType === 'application/json' ? JSONString.JSONString(child) : String(child);
|
|
35
|
-
res.setHeader('Content-Type', contentType
|
|
36
|
-
|
|
35
|
+
res.setHeader('Content-Type', contentType === 'application/json'
|
|
36
|
+
? 'application/json; charset=utf-8'
|
|
37
|
+
: contentType);
|
|
38
|
+
res.setHeader('Content-Length', Buffer.byteLength(content));
|
|
37
39
|
if (contentType === 'application/json') {
|
|
38
|
-
res.write(
|
|
40
|
+
res.write(content, 'utf-8');
|
|
39
41
|
}
|
|
40
42
|
else {
|
|
41
|
-
res.write(
|
|
43
|
+
res.write(content);
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
res.end();
|
|
@@ -15,67 +15,85 @@ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
|
|
|
15
15
|
if ('$ref' in schema) {
|
|
16
16
|
return `Schemas.${schema.$ref.slice(21)}${lastChar}`;
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
const types = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
19
|
+
let scope = '';
|
|
20
|
+
for (let i = 0; i < types.length; i++) {
|
|
21
|
+
const type = types[i];
|
|
22
|
+
const operator = i ? ' | ' : '';
|
|
23
|
+
if (schema.oneOf) {
|
|
24
|
+
let result = '';
|
|
25
|
+
for (const item of schema.oneOf) {
|
|
26
|
+
if (result) {
|
|
27
|
+
result += ' | ';
|
|
28
|
+
}
|
|
29
|
+
result += generateSchemaTypes(item, spaces + 2, '');
|
|
30
|
+
}
|
|
31
|
+
scope += `${operator}${result}`;
|
|
32
|
+
continue;
|
|
24
33
|
}
|
|
25
|
-
if (
|
|
26
|
-
|
|
34
|
+
if (!type) {
|
|
35
|
+
scope += `${operator}any`;
|
|
36
|
+
continue;
|
|
27
37
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
if (type === 'integer') {
|
|
39
|
+
scope += `${operator}${schema.format === 'int64' ? 'bigint' : 'number'}`;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (type === 'string') {
|
|
43
|
+
if (schema.format === 'date-time') {
|
|
44
|
+
scope += `${operator}Date`;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (schema.format === 'binary') {
|
|
48
|
+
scope += `${operator}Bin`;
|
|
49
|
+
continue;
|
|
38
50
|
}
|
|
39
|
-
|
|
51
|
+
scope += `${operator}string`;
|
|
52
|
+
continue;
|
|
40
53
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return `any${lastChar}`;
|
|
50
|
-
}
|
|
51
|
-
if (schema.type !== 'object') {
|
|
52
|
-
console.error('unknown type', schema);
|
|
53
|
-
return `any${lastChar}`;
|
|
54
|
-
}
|
|
55
|
-
let result = '{\n';
|
|
56
|
-
const required = schema.required || [];
|
|
57
|
-
const hasProps = Boolean(schema.properties && Object.keys(schema.properties).length);
|
|
58
|
-
const hasRestProps = Boolean(typeof schema.additionalProperties === 'object' &&
|
|
59
|
-
Object.keys(schema.additionalProperties).length);
|
|
60
|
-
if (hasProps) {
|
|
61
|
-
for (const key in schema.properties) {
|
|
62
|
-
const prop = schema.properties[key];
|
|
63
|
-
const splitter = required.includes(key) || hasDefault(prop)
|
|
64
|
-
? ':'
|
|
65
|
-
: '?:';
|
|
66
|
-
if ('deprecated' in prop && prop.deprecated) {
|
|
67
|
-
result += `${space}/** @deprecated */\n`;
|
|
54
|
+
if (['boolean', 'null', 'number'].includes(type)) {
|
|
55
|
+
scope += `${operator}${type}`;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (type === 'array') {
|
|
59
|
+
if (schema.type !== 'array' || !schema.items) {
|
|
60
|
+
scope += `${operator}any[]`;
|
|
61
|
+
continue;
|
|
68
62
|
}
|
|
69
|
-
|
|
63
|
+
scope += `${operator}Array<${generateSchemaTypes(schema.items, spaces + 2, '')}>`;
|
|
64
|
+
continue;
|
|
70
65
|
}
|
|
66
|
+
if (type !== 'object') {
|
|
67
|
+
console.error('Error: Unknown Type', schema);
|
|
68
|
+
scope += `${operator}any`;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
let result = '{\n';
|
|
72
|
+
const required = schema.required || [];
|
|
73
|
+
const hasProps = Boolean(schema.properties && Object.keys(schema.properties).length);
|
|
74
|
+
const hasRestProps = Boolean(typeof schema.additionalProperties === 'object' &&
|
|
75
|
+
Object.keys(schema.additionalProperties).length);
|
|
76
|
+
if (hasProps) {
|
|
77
|
+
for (const key in schema.properties) {
|
|
78
|
+
const prop = schema.properties[key];
|
|
79
|
+
const splitter = required.includes(key) || hasDefault(prop)
|
|
80
|
+
? ':'
|
|
81
|
+
: '?:';
|
|
82
|
+
if ('deprecated' in prop && prop.deprecated) {
|
|
83
|
+
result += `${space}/** @deprecated */\n`;
|
|
84
|
+
}
|
|
85
|
+
result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (hasRestProps) {
|
|
89
|
+
const value = hasProps
|
|
90
|
+
? 'any\n'
|
|
91
|
+
: generateSchemaTypes(schema.additionalProperties, spaces + 2);
|
|
92
|
+
result += `${space}[key: string]: ${value}`;
|
|
93
|
+
}
|
|
94
|
+
scope += `${operator}${result}${space.slice(0, -2)}}`;
|
|
71
95
|
}
|
|
72
|
-
|
|
73
|
-
const value = hasProps
|
|
74
|
-
? 'any\n'
|
|
75
|
-
: generateSchemaTypes(schema.additionalProperties, spaces + 2);
|
|
76
|
-
result += `${space}[key: string]: ${value}`;
|
|
77
|
-
}
|
|
78
|
-
return `${result}${space.slice(0, -2)}}${lastChar}`;
|
|
96
|
+
return `${scope}${lastChar}`;
|
|
79
97
|
}
|
|
80
98
|
function generateTypes(docs, namespace = 'Api') {
|
|
81
99
|
var _a;
|
|
@@ -19,67 +19,85 @@ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
|
|
|
19
19
|
if ('$ref' in schema) {
|
|
20
20
|
return `Schemas.${schema.$ref.slice(21)}${lastChar}`;
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
const types = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
23
|
+
let scope = '';
|
|
24
|
+
for (let i = 0; i < types.length; i++) {
|
|
25
|
+
const type = types[i];
|
|
26
|
+
const operator = i ? ' | ' : '';
|
|
27
|
+
if (schema.oneOf) {
|
|
28
|
+
let result = '';
|
|
29
|
+
for (const item of schema.oneOf) {
|
|
30
|
+
if (result) {
|
|
31
|
+
result += ' | ';
|
|
32
|
+
}
|
|
33
|
+
result += generateSchemaTypes(item, spaces + 2, '');
|
|
34
|
+
}
|
|
35
|
+
scope += `${operator}${result}`;
|
|
36
|
+
continue;
|
|
28
37
|
}
|
|
29
|
-
if (
|
|
30
|
-
|
|
38
|
+
if (!type) {
|
|
39
|
+
scope += `${operator}any`;
|
|
40
|
+
continue;
|
|
31
41
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
if (type === 'integer') {
|
|
43
|
+
scope += `${operator}${schema.format === 'int64' ? 'bigint' : 'number'}`;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (type === 'string') {
|
|
47
|
+
if (schema.format === 'date-time') {
|
|
48
|
+
scope += `${operator}Date`;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (schema.format === 'binary') {
|
|
52
|
+
scope += `${operator}Bin`;
|
|
53
|
+
continue;
|
|
42
54
|
}
|
|
43
|
-
|
|
55
|
+
scope += `${operator}string`;
|
|
56
|
+
continue;
|
|
44
57
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return `any${lastChar}`;
|
|
54
|
-
}
|
|
55
|
-
if (schema.type !== 'object') {
|
|
56
|
-
console.error('unknown type', schema);
|
|
57
|
-
return `any${lastChar}`;
|
|
58
|
-
}
|
|
59
|
-
let result = '{\n';
|
|
60
|
-
const required = schema.required || [];
|
|
61
|
-
const hasProps = Boolean(schema.properties && Object.keys(schema.properties).length);
|
|
62
|
-
const hasRestProps = Boolean(typeof schema.additionalProperties === 'object' &&
|
|
63
|
-
Object.keys(schema.additionalProperties).length);
|
|
64
|
-
if (hasProps) {
|
|
65
|
-
for (const key in schema.properties) {
|
|
66
|
-
const prop = schema.properties[key];
|
|
67
|
-
const splitter = required.includes(key) || hasDefault(prop)
|
|
68
|
-
? ':'
|
|
69
|
-
: '?:';
|
|
70
|
-
if ('deprecated' in prop && prop.deprecated) {
|
|
71
|
-
result += `${space}/** @deprecated */\n`;
|
|
58
|
+
if (['boolean', 'null', 'number'].includes(type)) {
|
|
59
|
+
scope += `${operator}${type}`;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (type === 'array') {
|
|
63
|
+
if (schema.type !== 'array' || !schema.items) {
|
|
64
|
+
scope += `${operator}any[]`;
|
|
65
|
+
continue;
|
|
72
66
|
}
|
|
73
|
-
|
|
67
|
+
scope += `${operator}Array<${generateSchemaTypes(schema.items, spaces + 2, '')}>`;
|
|
68
|
+
continue;
|
|
74
69
|
}
|
|
70
|
+
if (type !== 'object') {
|
|
71
|
+
console.error('Error: Unknown Type', schema);
|
|
72
|
+
scope += `${operator}any`;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
let result = '{\n';
|
|
76
|
+
const required = schema.required || [];
|
|
77
|
+
const hasProps = Boolean(schema.properties && Object.keys(schema.properties).length);
|
|
78
|
+
const hasRestProps = Boolean(typeof schema.additionalProperties === 'object' &&
|
|
79
|
+
Object.keys(schema.additionalProperties).length);
|
|
80
|
+
if (hasProps) {
|
|
81
|
+
for (const key in schema.properties) {
|
|
82
|
+
const prop = schema.properties[key];
|
|
83
|
+
const splitter = required.includes(key) || hasDefault(prop)
|
|
84
|
+
? ':'
|
|
85
|
+
: '?:';
|
|
86
|
+
if ('deprecated' in prop && prop.deprecated) {
|
|
87
|
+
result += `${space}/** @deprecated */\n`;
|
|
88
|
+
}
|
|
89
|
+
result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (hasRestProps) {
|
|
93
|
+
const value = hasProps
|
|
94
|
+
? 'any\n'
|
|
95
|
+
: generateSchemaTypes(schema.additionalProperties, spaces + 2);
|
|
96
|
+
result += `${space}[key: string]: ${value}`;
|
|
97
|
+
}
|
|
98
|
+
scope += `${operator}${result}${space.slice(0, -2)}}`;
|
|
75
99
|
}
|
|
76
|
-
|
|
77
|
-
const value = hasProps
|
|
78
|
-
? 'any\n'
|
|
79
|
-
: generateSchemaTypes(schema.additionalProperties, spaces + 2);
|
|
80
|
-
result += `${space}[key: string]: ${value}`;
|
|
81
|
-
}
|
|
82
|
-
return `${result}${space.slice(0, -2)}}${lastChar}`;
|
|
100
|
+
return `${scope}${lastChar}`;
|
|
83
101
|
}
|
|
84
102
|
function generateTypes(docs, namespace = 'Api') {
|
|
85
103
|
var _a;
|