dtsgenerator 2.0.0 → 2.0.6
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 +22 -0
- package/SupportedFeatures.md +1 -0
- package/ast.js +18 -0
- package/dist/core/dtsGenerator.js +17 -4
- package/dist/core/dtsGenerator.js.map +1 -1
- package/dist/core/referenceResolver.d.ts +1 -0
- package/dist/core/referenceResolver.js +31 -6
- package/dist/core/referenceResolver.js.map +1 -1
- package/dist/jsonPointer.d.ts +1 -0
- package/dist/jsonPointer.js +4 -0
- package/dist/jsonPointer.js.map +1 -1
- package/dist/utils.js +5 -2
- package/dist/utils.js.map +1 -1
- package/geojson.json +353 -0
- package/openapi.json +1607 -0
- package/package.json +15 -14
- package/src/core/dtsGenerator.js +327 -0
- package/src/core/dtsGenerator.js.map +1 -0
- package/src/core/dtsGenerator.ts +16 -4
- package/src/core/index.js +41 -0
- package/src/core/index.js.map +1 -0
- package/src/core/jsonSchema.js +371 -0
- package/src/core/jsonSchema.js.map +1 -0
- package/src/core/jsonSchemaDraft04.d.ts +1 -0
- package/src/core/jsonSchemaDraft07.d.ts +1 -0
- package/src/core/openApiV2.js +2 -0
- package/src/core/openApiV2.js.map +1 -0
- package/src/core/referenceResolver.js +199 -0
- package/src/core/referenceResolver.js.map +1 -0
- package/src/core/referenceResolver.ts +20 -6
- package/src/core/schemaConvertor.js +285 -0
- package/src/core/schemaConvertor.js.map +1 -0
- package/src/core/schemaId.js +51 -0
- package/src/core/schemaId.js.map +1 -0
- package/src/core/typeNameConvertor.js +43 -0
- package/src/core/typeNameConvertor.js.map +1 -0
- package/src/core/utils.js +58 -0
- package/src/core/utils.js.map +1 -0
- package/src/core/writeProcessor.js +130 -0
- package/src/core/writeProcessor.js.map +1 -0
- package/src/jsonPointer.ts +4 -0
- package/src/utils.ts +5 -2
- package/tsconfig.json +2 -0
|
@@ -38,11 +38,8 @@ export default class ReferenceResolver {
|
|
|
38
38
|
let result = this.schemaCache.get(id.getAbsoluteId());
|
|
39
39
|
if (result == null) {
|
|
40
40
|
const refSchema = this.schemaCache.get(fileId);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
error.push(`The $ref target is not exists: ${id.getAbsoluteId()}`);
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
41
|
+
debug(`get from schema cache, fileId=${fileId}, exists=${refSchema != null}, ${id.getAbsoluteId()}`);
|
|
42
|
+
if (refSchema == null && id.isFetchable()) {
|
|
46
43
|
try {
|
|
47
44
|
debug(`fetch remote schema: id=[${fileId}].`);
|
|
48
45
|
await this.registerRemoteSchema(fileId);
|
|
@@ -58,7 +55,7 @@ export default class ReferenceResolver {
|
|
|
58
55
|
this.referenceCache.set(id.getAbsoluteId(), result);
|
|
59
56
|
} else {
|
|
60
57
|
if (id.existsJsonPointerHash()) {
|
|
61
|
-
const rootSchema = this.
|
|
58
|
+
const rootSchema = this.searchParentSchema(id);
|
|
62
59
|
if (rootSchema == null) {
|
|
63
60
|
error.push(`The $ref targets root is not found: ${id.getAbsoluteId()}`);
|
|
64
61
|
continue;
|
|
@@ -79,6 +76,23 @@ export default class ReferenceResolver {
|
|
|
79
76
|
// debug(' resolve reference: resolved schema:');
|
|
80
77
|
// debug(Array.from(this.referenceCache.keys()).join('\n'));
|
|
81
78
|
}
|
|
79
|
+
private searchParentSchema(id: SchemaId): Schema | undefined {
|
|
80
|
+
const fileId = id.getFileId();
|
|
81
|
+
const rootSchema = this.schemaCache.get(fileId);
|
|
82
|
+
if (rootSchema != null) {
|
|
83
|
+
return rootSchema;
|
|
84
|
+
}
|
|
85
|
+
const key = id.getAbsoluteId();
|
|
86
|
+
for (const k of this.schemaCache.keys()) {
|
|
87
|
+
if (key.startsWith(k)) {
|
|
88
|
+
const s = this.schemaCache.get(k);
|
|
89
|
+
if (s != null && s.rootSchema != null) {
|
|
90
|
+
return s.rootSchema;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
82
96
|
|
|
83
97
|
public async registerRemoteSchema(url: string): Promise<void> {
|
|
84
98
|
const res = await fetch(url);
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
var JsonPointer = tslib_1.__importStar(require("../jsonPointer"));
|
|
5
|
+
var typeNameConvertor_1 = require("./typeNameConvertor");
|
|
6
|
+
var SchemaConvertor = /** @class */ (function () {
|
|
7
|
+
function SchemaConvertor(processor, convertor, namespaceName) {
|
|
8
|
+
if (convertor === void 0) { convertor = typeNameConvertor_1.DefaultTypeNameConvertor; }
|
|
9
|
+
this.processor = processor;
|
|
10
|
+
this.convertor = convertor;
|
|
11
|
+
this.replaceLevel = 0;
|
|
12
|
+
this.ns = namespaceName == null ? undefined : namespaceName.split('/').filter(function (s) { return s.length > 0; });
|
|
13
|
+
}
|
|
14
|
+
SchemaConvertor.prototype.getLastTypeName = function (id) {
|
|
15
|
+
var names = this.convertor(id);
|
|
16
|
+
if (names.length > 0) {
|
|
17
|
+
return names[names.length - 1];
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
SchemaConvertor.prototype.buildSchemaMergedMap = function (schemas, typeMarker) {
|
|
24
|
+
var e_1, _a, e_2, _b, _c;
|
|
25
|
+
var map = {};
|
|
26
|
+
var paths = [];
|
|
27
|
+
var minLevel = Number.MAX_SAFE_INTEGER;
|
|
28
|
+
try {
|
|
29
|
+
for (var schemas_1 = tslib_1.__values(schemas), schemas_1_1 = schemas_1.next(); !schemas_1_1.done; schemas_1_1 = schemas_1.next()) {
|
|
30
|
+
var type = schemas_1_1.value;
|
|
31
|
+
var path = this.convertor(type.id);
|
|
32
|
+
minLevel = Math.min(minLevel, path.length);
|
|
33
|
+
paths.push({ path: path, type: type });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
37
|
+
finally {
|
|
38
|
+
try {
|
|
39
|
+
if (schemas_1_1 && !schemas_1_1.done && (_a = schemas_1.return)) _a.call(schemas_1);
|
|
40
|
+
}
|
|
41
|
+
finally { if (e_1) throw e_1.error; }
|
|
42
|
+
}
|
|
43
|
+
this.replaceLevel = minLevel;
|
|
44
|
+
try {
|
|
45
|
+
for (var paths_1 = tslib_1.__values(paths), paths_1_1 = paths_1.next(); !paths_1_1.done; paths_1_1 = paths_1.next()) {
|
|
46
|
+
var item = paths_1_1.value;
|
|
47
|
+
var path = item.path;
|
|
48
|
+
this.replaceNamespace(path);
|
|
49
|
+
var parent_1 = JsonPointer.get(map, path, true);
|
|
50
|
+
if (parent_1 == null) {
|
|
51
|
+
JsonPointer.set(map, path, (_c = {}, _c[typeMarker] = item.type, _c));
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
parent_1[typeMarker] = item.type;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
59
|
+
finally {
|
|
60
|
+
try {
|
|
61
|
+
if (paths_1_1 && !paths_1_1.done && (_b = paths_1.return)) _b.call(paths_1);
|
|
62
|
+
}
|
|
63
|
+
finally { if (e_2) throw e_2.error; }
|
|
64
|
+
}
|
|
65
|
+
if (Object.keys(map).length === 0) {
|
|
66
|
+
throw new Error('There is no schema in the input contents.');
|
|
67
|
+
}
|
|
68
|
+
return map;
|
|
69
|
+
};
|
|
70
|
+
SchemaConvertor.prototype.replaceNamespace = function (paths) {
|
|
71
|
+
if (this.ns == null) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
paths.splice(0, this.replaceLevel - 1);
|
|
75
|
+
if (this.ns.length > 0) {
|
|
76
|
+
paths.unshift.apply(paths, tslib_1.__spread(this.ns));
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
SchemaConvertor.prototype.start = function () {
|
|
80
|
+
this.processor.clear();
|
|
81
|
+
};
|
|
82
|
+
SchemaConvertor.prototype.end = function () {
|
|
83
|
+
return this.processor.toDefinition();
|
|
84
|
+
};
|
|
85
|
+
SchemaConvertor.prototype.startNest = function (name) {
|
|
86
|
+
var processor = this.processor;
|
|
87
|
+
if (processor.indentLevel === 0) {
|
|
88
|
+
processor.output('declare ');
|
|
89
|
+
}
|
|
90
|
+
processor.output('namespace ').outputType(name, true).outputLine(' {');
|
|
91
|
+
processor.increaseIndent();
|
|
92
|
+
};
|
|
93
|
+
SchemaConvertor.prototype.endNest = function () {
|
|
94
|
+
var processor = this.processor;
|
|
95
|
+
processor.decreaseIndent();
|
|
96
|
+
processor.outputLine('}');
|
|
97
|
+
};
|
|
98
|
+
/// acutal type convert methods
|
|
99
|
+
SchemaConvertor.prototype.startInterfaceNest = function (id) {
|
|
100
|
+
var processor = this.processor;
|
|
101
|
+
if (processor.indentLevel === 0) {
|
|
102
|
+
processor.output('declare ');
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
processor.output('export ');
|
|
106
|
+
}
|
|
107
|
+
var name = this.getLastTypeName(id);
|
|
108
|
+
processor.output('interface ').outputType(name).output(' ');
|
|
109
|
+
this.startTypeNest();
|
|
110
|
+
};
|
|
111
|
+
SchemaConvertor.prototype.endInterfaceNest = function () {
|
|
112
|
+
this.endTypeNest(false);
|
|
113
|
+
this.processor.outputLine();
|
|
114
|
+
};
|
|
115
|
+
SchemaConvertor.prototype.outputExportType = function (id) {
|
|
116
|
+
var processor = this.processor;
|
|
117
|
+
if (processor.indentLevel === 0) {
|
|
118
|
+
processor.output('declare ');
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
processor.output('export ');
|
|
122
|
+
}
|
|
123
|
+
var name = this.getLastTypeName(id);
|
|
124
|
+
processor.output('type ').outputType(name).output(' = ');
|
|
125
|
+
};
|
|
126
|
+
SchemaConvertor.prototype.startTypeNest = function () {
|
|
127
|
+
this.processor.outputLine('{');
|
|
128
|
+
this.processor.increaseIndent();
|
|
129
|
+
};
|
|
130
|
+
SchemaConvertor.prototype.endTypeNest = function (terminate) {
|
|
131
|
+
this.processor.decreaseIndent();
|
|
132
|
+
this.processor.output('}');
|
|
133
|
+
if (terminate) {
|
|
134
|
+
this.processor.outputLine(';');
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
SchemaConvertor.prototype.outputRawValue = function (value, isEndOfLine) {
|
|
138
|
+
if (isEndOfLine === void 0) { isEndOfLine = false; }
|
|
139
|
+
this.processor.output(value);
|
|
140
|
+
if (isEndOfLine) {
|
|
141
|
+
this.processor.outputLine();
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
SchemaConvertor.prototype.outputComments = function (schema) {
|
|
145
|
+
var _a;
|
|
146
|
+
var content = schema.content;
|
|
147
|
+
var comments = [];
|
|
148
|
+
if ('$comment' in content) {
|
|
149
|
+
comments.push(content.$comment);
|
|
150
|
+
}
|
|
151
|
+
comments.push(content.title);
|
|
152
|
+
comments.push(content.description);
|
|
153
|
+
if ('example' in content || 'examples' in content) {
|
|
154
|
+
comments.push('example:');
|
|
155
|
+
if ('example' in content) {
|
|
156
|
+
comments.push(content.example);
|
|
157
|
+
}
|
|
158
|
+
if ('examples' in content) {
|
|
159
|
+
comments.push.apply(comments, tslib_1.__spread(content.examples));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
(_a = this.processor).outputJSDoc.apply(_a, tslib_1.__spread(comments));
|
|
163
|
+
};
|
|
164
|
+
SchemaConvertor.prototype.outputPropertyName = function (_schema, propertyName, required) {
|
|
165
|
+
var optionalProperty = required == null || required.indexOf(propertyName) < 0;
|
|
166
|
+
this.processor.outputKey(propertyName, optionalProperty).output(': ');
|
|
167
|
+
};
|
|
168
|
+
SchemaConvertor.prototype.outputPropertyAttribute = function (schema) {
|
|
169
|
+
var content = schema.content;
|
|
170
|
+
if ('readOnly' in content && content.readOnly) {
|
|
171
|
+
this.processor.output('readonly ');
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
SchemaConvertor.prototype.outputArrayedType = function (schema, types, output, terminate, outputOptional) {
|
|
175
|
+
var _this = this;
|
|
176
|
+
if (outputOptional === void 0) { outputOptional = true; }
|
|
177
|
+
if (!terminate) {
|
|
178
|
+
this.processor.output('(');
|
|
179
|
+
}
|
|
180
|
+
types.forEach(function (t, index) {
|
|
181
|
+
output(t, index);
|
|
182
|
+
if (index < types.length - 1) {
|
|
183
|
+
_this.processor.output(' | ');
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
if (!terminate) {
|
|
187
|
+
this.processor.output(')');
|
|
188
|
+
}
|
|
189
|
+
this.outputTypeNameTrailer(schema, terminate, outputOptional);
|
|
190
|
+
};
|
|
191
|
+
SchemaConvertor.prototype.outputTypeIdName = function (schema, currentSchema, terminate, outputOptional) {
|
|
192
|
+
var _this = this;
|
|
193
|
+
if (terminate === void 0) { terminate = true; }
|
|
194
|
+
if (outputOptional === void 0) { outputOptional = true; }
|
|
195
|
+
var typeName = this.getTypename(schema.id, currentSchema);
|
|
196
|
+
typeName.forEach(function (type, index) {
|
|
197
|
+
var isLast = index === typeName.length - 1;
|
|
198
|
+
_this.processor.outputType(type, isLast ? false : true);
|
|
199
|
+
if (!isLast) {
|
|
200
|
+
_this.processor.output('.');
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
this.outputTypeNameTrailer(schema, terminate, outputOptional);
|
|
204
|
+
};
|
|
205
|
+
SchemaConvertor.prototype.getTypename = function (id, baseSchema) {
|
|
206
|
+
var e_3, _a;
|
|
207
|
+
var result = this.convertor(id);
|
|
208
|
+
this.replaceNamespace(result);
|
|
209
|
+
var baseId = baseSchema.id;
|
|
210
|
+
if (baseId) {
|
|
211
|
+
var baseTypes = this.convertor(baseId).slice(0, -1);
|
|
212
|
+
try {
|
|
213
|
+
for (var baseTypes_1 = tslib_1.__values(baseTypes), baseTypes_1_1 = baseTypes_1.next(); !baseTypes_1_1.done; baseTypes_1_1 = baseTypes_1.next()) {
|
|
214
|
+
var type = baseTypes_1_1.value;
|
|
215
|
+
if (result[0] === type) {
|
|
216
|
+
result.shift();
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
224
|
+
finally {
|
|
225
|
+
try {
|
|
226
|
+
if (baseTypes_1_1 && !baseTypes_1_1.done && (_a = baseTypes_1.return)) _a.call(baseTypes_1);
|
|
227
|
+
}
|
|
228
|
+
finally { if (e_3) throw e_3.error; }
|
|
229
|
+
}
|
|
230
|
+
if (result.length === 0) {
|
|
231
|
+
return [this.getLastTypeName(id)];
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return result;
|
|
235
|
+
};
|
|
236
|
+
SchemaConvertor.prototype.outputPrimitiveTypeName = function (schema, typeName, terminate, outputOptional) {
|
|
237
|
+
if (terminate === void 0) { terminate = true; }
|
|
238
|
+
if (outputOptional === void 0) { outputOptional = true; }
|
|
239
|
+
this.processor.outputType(typeName, true);
|
|
240
|
+
this.outputTypeNameTrailer(schema, terminate, outputOptional);
|
|
241
|
+
};
|
|
242
|
+
SchemaConvertor.prototype.outputStringTypeName = function (schema, typeName, terminate, outputOptional) {
|
|
243
|
+
if (outputOptional === void 0) { outputOptional = true; }
|
|
244
|
+
if (typeName) {
|
|
245
|
+
this.processor.output(typeName);
|
|
246
|
+
}
|
|
247
|
+
this.outputTypeNameTrailer(schema, terminate, outputOptional);
|
|
248
|
+
};
|
|
249
|
+
SchemaConvertor.prototype.outputTypeNameTrailer = function (schema, terminate, outputOptional) {
|
|
250
|
+
if (terminate) {
|
|
251
|
+
this.processor.output(';');
|
|
252
|
+
}
|
|
253
|
+
if (outputOptional) {
|
|
254
|
+
this.outputOptionalInformation(schema, terminate);
|
|
255
|
+
}
|
|
256
|
+
if (terminate) {
|
|
257
|
+
this.processor.outputLine();
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
SchemaConvertor.prototype.outputOptionalInformation = function (schema, terminate) {
|
|
261
|
+
var format = schema.content.format;
|
|
262
|
+
var pattern = schema.content.pattern;
|
|
263
|
+
if (!format && !pattern) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if (terminate) {
|
|
267
|
+
this.processor.output(' //');
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
this.processor.output(' /*');
|
|
271
|
+
}
|
|
272
|
+
if (format) {
|
|
273
|
+
this.processor.output(' ').output(format);
|
|
274
|
+
}
|
|
275
|
+
if (pattern) {
|
|
276
|
+
this.processor.output(' ').output(pattern);
|
|
277
|
+
}
|
|
278
|
+
if (!terminate) {
|
|
279
|
+
this.processor.output(' */ ');
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
return SchemaConvertor;
|
|
283
|
+
}());
|
|
284
|
+
exports.default = SchemaConvertor;
|
|
285
|
+
//# sourceMappingURL=schemaConvertor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaConvertor.js","sourceRoot":"","sources":["schemaConvertor.ts"],"names":[],"mappings":";;;AAAA,kEAA8C;AAG9C,yDAAkF;AAGlF;IAII,yBAAoB,SAAyB,EAAU,SAAuD,EAAE,aAAsB;QAA/E,0BAAA,EAAA,YAA+B,4CAAwB;QAA1F,cAAS,GAAT,SAAS,CAAgB;QAAU,cAAS,GAAT,SAAS,CAA8C;QAFtG,iBAAY,GAAG,CAAC,CAAC;QAGrB,IAAI,CAAC,EAAE,GAAG,aAAa,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,MAAM,GAAG,CAAC,EAAZ,CAAY,CAAC,CAAC;IACvG,CAAC;IAEO,yCAAe,GAAv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AC,OAAO,CAAC;QACvC,IAAI,CAAC,MAAM,IAAI,CAAC,OAAO,EAAE;YACrB,OAAO;SACV;QACD,IAAI,SAAS,EAAE;YACX,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SAChC;aAAM;YACH,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SAChC;QACD,IAAI,MAAM,EAAE;YACR,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;SAC7C;QACD,IAAI,OAAO,EAAE;YACT,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;SAC9C;QACD,IAAI,CAAC,SAAS,EAAE;YACZ,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;SACjC;IACL,CAAC;IACL,sBAAC;AAAD,CAAC,AApPD,IAoPC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
var url_1 = tslib_1.__importDefault(require("url"));
|
|
5
|
+
var SchemaId = /** @class */ (function () {
|
|
6
|
+
function SchemaId(inputId, parentIds) {
|
|
7
|
+
this.inputId = inputId;
|
|
8
|
+
var absoluteId = inputId;
|
|
9
|
+
if (parentIds) {
|
|
10
|
+
parentIds.forEach(function (parent) {
|
|
11
|
+
if (parent) {
|
|
12
|
+
absoluteId = url_1.default.resolve(parent, absoluteId);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
if (absoluteId.indexOf('#') < 0) {
|
|
17
|
+
absoluteId += '#';
|
|
18
|
+
}
|
|
19
|
+
if (absoluteId.indexOf('://') < 0 && absoluteId[0] !== '/' && absoluteId[0] !== '#') {
|
|
20
|
+
absoluteId = '/' + absoluteId;
|
|
21
|
+
}
|
|
22
|
+
this.absoluteId = absoluteId;
|
|
23
|
+
this.id = url_1.default.parse(absoluteId);
|
|
24
|
+
}
|
|
25
|
+
SchemaId.prototype.getAbsoluteId = function () {
|
|
26
|
+
return this.absoluteId;
|
|
27
|
+
};
|
|
28
|
+
SchemaId.prototype.isEmpty = function () {
|
|
29
|
+
return !!this.absoluteId;
|
|
30
|
+
};
|
|
31
|
+
SchemaId.prototype.isFetchable = function () {
|
|
32
|
+
return /https?\:\/\//.test(this.absoluteId);
|
|
33
|
+
};
|
|
34
|
+
SchemaId.prototype.getFileId = function () {
|
|
35
|
+
return this.absoluteId.replace(/#.*$/, '#');
|
|
36
|
+
};
|
|
37
|
+
SchemaId.prototype.existsJsonPointerHash = function () {
|
|
38
|
+
return this.absoluteId === '#' || /#\//.test(this.absoluteId);
|
|
39
|
+
};
|
|
40
|
+
SchemaId.prototype.getJsonPointerHash = function () {
|
|
41
|
+
var m = /(#\/.*)$/.exec(this.absoluteId);
|
|
42
|
+
if (m == null) {
|
|
43
|
+
return '#';
|
|
44
|
+
}
|
|
45
|
+
return m[1];
|
|
46
|
+
};
|
|
47
|
+
SchemaId.empty = new SchemaId('');
|
|
48
|
+
return SchemaId;
|
|
49
|
+
}());
|
|
50
|
+
exports.default = SchemaId;
|
|
51
|
+
//# sourceMappingURL=schemaId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaId.js","sourceRoot":"","sources":["schemaId.ts"],"names":[],"mappings":";;;AAAA,oDAAsB;AAEtB;IAMI,kBAA4B,OAAe,EAAE,SAAoB;QAArC,YAAO,GAAP,OAAO,CAAQ;QACvC,IAAI,UAAU,GAAG,OAAO,CAAC;QACzB,IAAI,SAAS,EAAE;YACX,SAAS,CAAC,OAAO,CAAC,UAAC,MAAc;gBAC7B,IAAI,MAAM,EAAE;oBACR,UAAU,GAAG,aAAG,CAAC,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;i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AAA,AA/CD,IA+CC;kBA/CoB,QAAQ"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultTypeNameConvertor = function (id) {
|
|
4
|
+
var url = id.id;
|
|
5
|
+
var ids = [];
|
|
6
|
+
if (url.host) {
|
|
7
|
+
ids.push(decodeURIComponent(url.host));
|
|
8
|
+
}
|
|
9
|
+
var addAllParts = function (path) {
|
|
10
|
+
var paths = path.split('/');
|
|
11
|
+
if (paths.length > 1 && paths[0] === '') {
|
|
12
|
+
paths.shift();
|
|
13
|
+
}
|
|
14
|
+
paths.forEach(function (item) {
|
|
15
|
+
ids.push(decodeURIComponent(item));
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
if (url.pathname) {
|
|
19
|
+
addAllParts(url.pathname);
|
|
20
|
+
}
|
|
21
|
+
if (url.hash && url.hash.length > 1) {
|
|
22
|
+
addAllParts(url.hash.substr(1));
|
|
23
|
+
}
|
|
24
|
+
return ids.map(toTypeName);
|
|
25
|
+
};
|
|
26
|
+
function toTypeName(str) {
|
|
27
|
+
if (!str) {
|
|
28
|
+
return str;
|
|
29
|
+
}
|
|
30
|
+
str = str.trim();
|
|
31
|
+
return str.split('$').map(function (s) { return s.replace(/(?:^|[^A-Za-z0-9])([A-Za-z0-9])/g, function (_, m) {
|
|
32
|
+
return m.toUpperCase();
|
|
33
|
+
}); }).join('$');
|
|
34
|
+
}
|
|
35
|
+
function normalizeTypeName(type) {
|
|
36
|
+
type = type.replace(/^\//, '').replace(/[^0-9A-Za-z_$]+/g, '_');
|
|
37
|
+
if (/^\d/.test(type)) {
|
|
38
|
+
type = '$' + type;
|
|
39
|
+
}
|
|
40
|
+
return type;
|
|
41
|
+
}
|
|
42
|
+
exports.normalizeTypeName = normalizeTypeName;
|
|
43
|
+
//# sourceMappingURL=typeNameConvertor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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AC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,OAAO,CAAC,kCAAkC,EAAE,UAAC,CAAC,EAAE,CAAC;QAChF,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;IAC3B,CAAC,CAAC,EAF+B,CAE/B,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClB,CAAC;AAED,SAAgB,iBAAiB,CAAC,IAAY;IAC1C,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC;IAChE,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QAClB,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC;KACrB;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAND,8CAMC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
var debug_1 = tslib_1.__importDefault(require("debug"));
|
|
5
|
+
var debug = debug_1.default('dtsgen');
|
|
6
|
+
function toTSType(type, debugSource) {
|
|
7
|
+
switch (type) {
|
|
8
|
+
case 'integer':
|
|
9
|
+
return 'number';
|
|
10
|
+
case 'any':
|
|
11
|
+
case 'null':
|
|
12
|
+
case 'undefined':
|
|
13
|
+
case 'string':
|
|
14
|
+
case 'number':
|
|
15
|
+
case 'boolean':
|
|
16
|
+
return type;
|
|
17
|
+
case 'object':
|
|
18
|
+
case 'array':
|
|
19
|
+
return undefined;
|
|
20
|
+
default:
|
|
21
|
+
if (debugSource) {
|
|
22
|
+
debug("toTSType: unknown type: " + JSON.stringify(debugSource, null, 2));
|
|
23
|
+
}
|
|
24
|
+
throw new Error('unknown type: ' + type);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.toTSType = toTSType;
|
|
28
|
+
function reduceTypes(types) {
|
|
29
|
+
if (types.length < 2) {
|
|
30
|
+
return types;
|
|
31
|
+
}
|
|
32
|
+
var set = new Set(types);
|
|
33
|
+
if (set.delete('integer')) {
|
|
34
|
+
set.add('number');
|
|
35
|
+
}
|
|
36
|
+
return Array.from(set.values());
|
|
37
|
+
}
|
|
38
|
+
exports.reduceTypes = reduceTypes;
|
|
39
|
+
function mergeSchema(a, b) {
|
|
40
|
+
Object.keys(b).forEach(function (key) {
|
|
41
|
+
var value = b[key];
|
|
42
|
+
if (a[key] != null && typeof value !== typeof a[key]) {
|
|
43
|
+
debug("mergeSchema warning: type is mismatched, key=" + key);
|
|
44
|
+
}
|
|
45
|
+
if (Array.isArray(value)) {
|
|
46
|
+
a[key] = (a[key] || []).concat(value);
|
|
47
|
+
}
|
|
48
|
+
else if (typeof value === 'object') {
|
|
49
|
+
a[key] = Object.assign(a[key] || {}, value);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
a[key] = value;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return a;
|
|
56
|
+
}
|
|
57
|
+
exports.mergeSchema = mergeSchema;
|
|
58
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["utils.ts"],"names":[],"mappings":";;;AAAA,wDAA0B;AAG1B,IAAM,KAAK,GAAG,eAAK,CAAC,QAAQ,CAAC,CAAC;AAE9B,SAAgB,QAAQ,CAAC,IAAY,EAAE,WAAiB;IACpD,QAAQ,IAAI,EAAE;QACV,KAAK,SAAS;YACV,OAAO,QAAQ,CAAC;QACpB,KAAK,KAAK,CAAC;QACX,KAAK,MAAM,CAAC;QACZ,KAAK,WAAW,CAAC;QACjB,KAAK,QAAQ,CAAC;QACd,KAAK,QAAQ,CAAC;QACd,KAAK,SAAS;YACV,OAAO,IAAI,CAAC;QAChB,KAAK,QAAQ,CAAC;QACd,KAAK,OAAO;YACR,OAAO,SAAS,CAAC;QACrB;YACI,I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AE,EAAE,KAAK,CAAC,CAAC;SAC/C;aAAM;YACH,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;SAClB;IACL,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,CAAC;AACb,CAAC;AAfD,kCAeC"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
var typeNameConvertor_1 = require("./typeNameConvertor");
|
|
5
|
+
var defaultOptions = {
|
|
6
|
+
indentChar: ' ',
|
|
7
|
+
indentSize: 4,
|
|
8
|
+
normalizeTypeName: typeNameConvertor_1.normalizeTypeName,
|
|
9
|
+
};
|
|
10
|
+
var WriteProcessor = /** @class */ (function () {
|
|
11
|
+
function WriteProcessor(options) {
|
|
12
|
+
this.indent = 0;
|
|
13
|
+
this.results = '';
|
|
14
|
+
this.alreadyIndentThisLine = false;
|
|
15
|
+
this.options = tslib_1.__assign({}, defaultOptions, options);
|
|
16
|
+
}
|
|
17
|
+
WriteProcessor.prototype.clear = function () {
|
|
18
|
+
this.indent = 0;
|
|
19
|
+
this.results = '';
|
|
20
|
+
this.alreadyIndentThisLine = false;
|
|
21
|
+
};
|
|
22
|
+
WriteProcessor.prototype.output = function (str) {
|
|
23
|
+
this.doIndent();
|
|
24
|
+
this.results += str;
|
|
25
|
+
return this;
|
|
26
|
+
};
|
|
27
|
+
WriteProcessor.prototype.outputType = function (type, primitive) {
|
|
28
|
+
if (primitive === void 0) { primitive = false; }
|
|
29
|
+
type = this.options.normalizeTypeName(type, primitive);
|
|
30
|
+
this.output(type);
|
|
31
|
+
return this;
|
|
32
|
+
};
|
|
33
|
+
WriteProcessor.prototype.outputKey = function (name, optional) {
|
|
34
|
+
if (optional === void 0) { optional = false; }
|
|
35
|
+
if (/[^0-9A-Za-z_$]/.test(name) || /^\d/.test(name)) {
|
|
36
|
+
this.output("\"" + name + "\"");
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.output(name);
|
|
40
|
+
}
|
|
41
|
+
if (optional) {
|
|
42
|
+
this.output('?');
|
|
43
|
+
}
|
|
44
|
+
return this;
|
|
45
|
+
};
|
|
46
|
+
WriteProcessor.prototype.outputLine = function (str) {
|
|
47
|
+
this.doIndent();
|
|
48
|
+
if (str) {
|
|
49
|
+
this.output(str);
|
|
50
|
+
}
|
|
51
|
+
this.output('\n');
|
|
52
|
+
this.alreadyIndentThisLine = false;
|
|
53
|
+
return this;
|
|
54
|
+
};
|
|
55
|
+
WriteProcessor.prototype.protectComment = function (str) {
|
|
56
|
+
return str.replace(/\*\//g, '*\u200B/'); // Unicode [ZERO WIDTH SPACE]
|
|
57
|
+
};
|
|
58
|
+
WriteProcessor.prototype.outputJSDoc = function () {
|
|
59
|
+
var _this = this;
|
|
60
|
+
var comments = [];
|
|
61
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
62
|
+
comments[_i] = arguments[_i];
|
|
63
|
+
}
|
|
64
|
+
var e_1, _a;
|
|
65
|
+
var lines = [];
|
|
66
|
+
comments
|
|
67
|
+
.filter(function (comment) { return comment != null; })
|
|
68
|
+
.map(function (comment) { return comment.toString().split('\n').map(function (line) { return _this.protectComment(line); }); })
|
|
69
|
+
.forEach(function (ls) {
|
|
70
|
+
lines = lines.concat(ls);
|
|
71
|
+
});
|
|
72
|
+
if (lines.length > 0) {
|
|
73
|
+
this.outputLine('/**');
|
|
74
|
+
try {
|
|
75
|
+
for (var lines_1 = tslib_1.__values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
76
|
+
var line = lines_1_1.value;
|
|
77
|
+
this.output(' * ').outputLine(line);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
81
|
+
finally {
|
|
82
|
+
try {
|
|
83
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
84
|
+
}
|
|
85
|
+
finally { if (e_1) throw e_1.error; }
|
|
86
|
+
}
|
|
87
|
+
this.outputLine(' */');
|
|
88
|
+
}
|
|
89
|
+
return this;
|
|
90
|
+
};
|
|
91
|
+
WriteProcessor.prototype.doIndent = function () {
|
|
92
|
+
if (!this.alreadyIndentThisLine) {
|
|
93
|
+
var indent = this.getIndent();
|
|
94
|
+
this.results += indent;
|
|
95
|
+
this.alreadyIndentThisLine = true;
|
|
96
|
+
}
|
|
97
|
+
return this;
|
|
98
|
+
};
|
|
99
|
+
Object.defineProperty(WriteProcessor.prototype, "indentLevel", {
|
|
100
|
+
get: function () {
|
|
101
|
+
return this.indent;
|
|
102
|
+
},
|
|
103
|
+
enumerable: true,
|
|
104
|
+
configurable: true
|
|
105
|
+
});
|
|
106
|
+
WriteProcessor.prototype.increaseIndent = function () {
|
|
107
|
+
this.indent++;
|
|
108
|
+
return this;
|
|
109
|
+
};
|
|
110
|
+
WriteProcessor.prototype.decreaseIndent = function () {
|
|
111
|
+
this.indent--;
|
|
112
|
+
return this;
|
|
113
|
+
};
|
|
114
|
+
WriteProcessor.prototype.getIndent = function () {
|
|
115
|
+
return this.repeatString(this.indent * this.options.indentSize, this.options.indentChar);
|
|
116
|
+
};
|
|
117
|
+
WriteProcessor.prototype.repeatString = function (n, s) {
|
|
118
|
+
var result = '';
|
|
119
|
+
for (var i = 0; i < n; i++) {
|
|
120
|
+
result += s;
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
};
|
|
124
|
+
WriteProcessor.prototype.toDefinition = function () {
|
|
125
|
+
return this.results;
|
|
126
|
+
};
|
|
127
|
+
return WriteProcessor;
|
|
128
|
+
}());
|
|
129
|
+
exports.default = WriteProcessor;
|
|
130
|
+
//# sourceMappingURL=writeProcessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writeProcessor.js","sourceRoot":"","sources":["writeProcessor.ts"],"names":[],"mappings":";;;AAAA,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