@vkontakte/api-schema-typescript-generator
Version:
VK API TypeScript generator
42 lines (41 loc) • 1.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizeMethodInfo = void 0;
const constants_1 = require("../constants");
const helpers_1 = require("../helpers");
const types_1 = require("../types");
/**
* Patches for method definition
*/
function normalizeMethodInfo(method) {
const parameterRefs = {};
method.parameters?.forEach((parameter) => {
// For method params "boolean" type means 1 or 0
// Real "false" boolean value will be detected by API as true
if (parameter.type === 'boolean') {
// @ts-expect-error
delete parameter.type;
parameter.$ref = constants_1.baseBoolIntRef;
}
// For parameters of the "array" type, VK API still accepts only a comma-separated string
// This may change in the future when the VK API starts accepting a json body
if (parameter.type === 'array') {
parameter.type = 'string';
}
if (!parameter.description) {
parameter.description = '';
}
if (parameter.items && parameter.items.$ref) {
const ref = parameter.items?.$ref;
parameterRefs[ref] = types_1.RefsDictionaryType.Generate;
parameter.description +=
constants_1.newLineChar.repeat(2) +
[`@see ${(0, helpers_1.getInterfaceName)((0, helpers_1.getObjectNameByRef)(ref))} (${ref})`].join(constants_1.newLineChar);
}
});
return {
method,
parameterRefs,
};
}
exports.normalizeMethodInfo = normalizeMethodInfo;