UNPKG

json-schema-typescript-generator

Version:
30 lines 1.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.basicTypeGenerator = void 0; const PRIMITIVE_TYPES = new Map(); PRIMITIVE_TYPES.set('null', 'null'); PRIMITIVE_TYPES.set('boolean', 'boolean'); PRIMITIVE_TYPES.set('integer', 'number'); PRIMITIVE_TYPES.set('number', 'number'); PRIMITIVE_TYPES.set('string', 'string'); const basicTypeGenerator = (locatedSchema, _gatheredInfo, _inputInfo) => { const schemaTypes = locatedSchema.schema.type; if (!schemaTypes || schemaTypes.size === 0) { return; } const tsTypesSet = new Set(); Array.from(PRIMITIVE_TYPES.entries()) .filter(([schemaType, _]) => schemaTypes.has(schemaType)) .map(([_, tsType]) => tsType) .forEach((tsType) => tsTypesSet.add(tsType)); const tsTypes = Array.from(tsTypesSet); if (tsTypes.length === 0) { return; } if (tsTypes.length === 1) { return tsTypes[0]; } return `(${tsTypes.join(' | ')})`; }; exports.basicTypeGenerator = basicTypeGenerator; //# sourceMappingURL=basic-type-generator.js.map