@vulcan-sql/build
Version:
VulcanSQL package for building projects
31 lines • 1.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GenerateDataType = void 0;
const tslib_1 = require("tslib");
const core_1 = require("@vulcan-sql/core");
const middleware_1 = require("./middleware");
const generateResponsePropertyType = (property) => {
if (!property.type) {
property.type = core_1.FieldDataType.STRING;
}
else if (Array.isArray(property.type)) {
(property.type || []).forEach((property) => generateResponsePropertyType(property));
}
};
// Fallback to string when type is not defined.
// TODO: Guess the type by validators.
class GenerateDataType extends middleware_1.SchemaParserMiddleware {
handle(schemas, next) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield next();
(schemas.request || []).forEach((request) => {
if (!request.type) {
request.type = core_1.FieldDataType.STRING;
}
});
(schemas.response || []).forEach((property) => generateResponsePropertyType(property));
});
}
}
exports.GenerateDataType = GenerateDataType;
//# sourceMappingURL=generateDataType.js.map