openapi-codegen-typescript
Version:
OpenApi codegen for generating types an mocks from swagger json file
53 lines (52 loc) • 2.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var types_1 = require("../types");
exports.getResultStringType = function (_a) {
var type = _a.type, items = _a.items, oneOf = _a.oneOf, xDictionaryKey = _a.xDictionaryKey, additionalProperties = _a.additionalProperties, $ref = _a.$ref;
var isStringType = type === types_1.DataTypes.String;
var isNumberType = type === types_1.DataTypes.Integer || type === types_1.DataTypes.Number;
var isBooleanType = type === types_1.DataTypes.Boolean;
var hasItems = type === types_1.DataTypes.Array && !!items;
var isItemWithRef = hasItems && !!items[types_1.SwaggerProps.$ref];
var isItemWithoutRef = hasItems && !items[types_1.SwaggerProps.$ref];
var isOneOf = !!oneOf && Array.isArray(oneOf) && !!oneOf[0][types_1.SwaggerProps.$ref];
var isRef = !!$ref;
var hasUndefinedTypeRefAndOneOf = !type && !$ref && !oneOf;
var hasDictionaryKeyRef = !!xDictionaryKey && !!xDictionaryKey[types_1.SwaggerProps.$ref];
var hasAddtionalPropertiesRef = !!additionalProperties && !!additionalProperties[types_1.SwaggerProps.$ref];
var isDictionaryKey = hasDictionaryKeyRef && hasAddtionalPropertiesRef;
var isAdditionalPropertiesType = !!additionalProperties && !!additionalProperties.type;
if (isStringType) {
return 'String';
}
else if (isNumberType) {
return 'Number';
}
else if (isBooleanType) {
return 'Boolean';
}
else if (isItemWithRef) {
return 'ItemWithRef';
}
else if (isItemWithoutRef) {
return 'ItemWithoutRef';
}
else if (isOneOf) {
return 'OneOf';
}
else if (isRef) {
return 'Ref';
}
else if (hasUndefinedTypeRefAndOneOf) {
return 'UndefinedTypeRefAndOneOf';
}
else if (isDictionaryKey) {
return 'DictionaryKey';
}
else if (isAdditionalPropertiesType) {
return 'AdditionalPropertiesType';
}
else {
return 'Invalid';
}
};