ts-json-schema-generator
Version:
Generate JSON schema from your Typescript sources
35 lines • 1.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CircularReferenceTypeFormatter = void 0;
const uniqueArray_js_1 = require("./Utils/uniqueArray.js");
class CircularReferenceTypeFormatter {
childTypeFormatter;
definition = new Map();
children = new Map();
constructor(childTypeFormatter) {
this.childTypeFormatter = childTypeFormatter;
}
supportsType(type) {
return this.childTypeFormatter.supportsType(type);
}
getDefinition(type) {
if (this.definition.has(type)) {
return this.definition.get(type);
}
const definition = {};
this.definition.set(type, definition);
Object.assign(definition, this.childTypeFormatter.getDefinition(type));
return definition;
}
getChildren(type) {
if (this.children.has(type)) {
return this.children.get(type);
}
const children = [];
this.children.set(type, children);
children.push(...this.childTypeFormatter.getChildren(type));
return (0, uniqueArray_js_1.uniqueArray)(children);
}
}
exports.CircularReferenceTypeFormatter = CircularReferenceTypeFormatter;
//# sourceMappingURL=CircularReferenceTypeFormatter.js.map