openapi-codegen-typescript
Version:
OpenApi codegen for generating types an mocks from swagger json file
48 lines (47 loc) • 2.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var types_1 = require("../types");
var getDescription_1 = require("./getDescription");
var getDictionaryValueResultString_1 = require("./getDictionaryValueResultString");
var parseRefType_1 = require("./parseRefType");
exports.getResultStringForAdditionalPropertiesType = function (_a) {
var additionalProperties = _a.additionalProperties, xDictionaryKey = _a.xDictionaryKey, description = _a.description, propertyName = _a.propertyName;
var res;
switch (additionalProperties.type) {
case types_1.DataTypes.Boolean:
res = types_1.DataTypes.Boolean;
break;
case types_1.DataTypes.Integer:
res = types_1.DataTypes.Number;
break;
case types_1.DataTypes.Number:
res = types_1.DataTypes.Number;
break;
case types_1.DataTypes.String:
res = types_1.DataTypes.String;
break;
case types_1.DataTypes.Array:
if (additionalProperties.items && additionalProperties.items[types_1.SwaggerProps.$ref]) {
res = parseRefType_1.parseRefType(additionalProperties.items[types_1.SwaggerProps.$ref].split('/')) + "[]";
}
else {
res = "\"// Error: The additionalProperties items or the items ref is missing\"";
}
break;
default:
res = "\"// Error: " + additionalProperties.type + " is not supported\"";
break;
}
if (xDictionaryKey && !!xDictionaryKey[types_1.SwaggerProps.$ref]) {
var dictionaryRef = parseRefType_1.parseRefType(xDictionaryKey[types_1.SwaggerProps.$ref].split('/'));
return getDictionaryValueResultString_1.getDictionaryValueResultString({
description: description,
dictionaryRef: dictionaryRef,
propertyName: propertyName,
value: res,
});
}
else {
return getDescription_1.getDescription({ description: description }) + "\t" + propertyName + ": {\n\t[key: string]: " + res + ";\n};\n";
}
};