UNPKG

openapi-codegen-typescript

Version:

OpenApi codegen for generating types an mocks from swagger json file

75 lines (74 loc) 4.37 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); var shared_1 = require("../shared"); var types_1 = require("../types"); var getResultStringForAdditionalPropertiesType_1 = require("./getResultStringForAdditionalPropertiesType"); var getResultStringForArrayType_1 = require("./getResultStringForArrayType"); var getResultStringForArrayWithoutItemRef_1 = require("./getResultStringForArrayWithoutItemRef"); var getResultStringForBooleanType_1 = require("./getResultStringForBooleanType"); var getResultStringForDictionaryKey_1 = require("./getResultStringForDictionaryKey"); var getResultStringForExportInterface_1 = require("./getResultStringForExportInterface"); var getResultStringForInvalidSchemaProperties_1 = require("./getResultStringForInvalidSchemaProperties"); var getResultStringForNumberType_1 = require("./getResultStringForNumberType"); var getResultStringForStringType_1 = require("./getResultStringForStringType"); var getResultStringForUndefinedTypeRefAndOneOf_1 = require("./getResultStringForUndefinedTypeRefAndOneOf"); var getResultStringType_1 = require("./getResultStringType"); var getStandardString_1 = require("./getStandardString"); exports.convertToTypesFromSchemaProperties = function (_a) { var schema = _a.schema, schemaKey = _a.schemaKey, interfaces = _a.interfaces; var result = getResultStringForExportInterface_1.getResultStringForExportInterface({ schemaKey: schemaKey, schema: schema, interfaces: interfaces }); if (schema.properties) { shared_1.getSchemaProperties(schema.properties).map(function (props) { var resultStringType = getResultStringType_1.getResultStringType(props); switch (resultStringType) { case 'String': result += getResultStringForStringType_1.getResultStringForStringType(props); break; case 'Number': result += getResultStringForNumberType_1.getResultStringForNumberType(props); break; case 'Boolean': result += getResultStringForBooleanType_1.getResultStringForBooleanType(props); break; case 'ItemWithRef': result += getResultStringForArrayType_1.getResultStringForArrayType(__assign(__assign({}, props), { refType: props.items[types_1.SwaggerProps.$ref].split('/') })); break; case 'ItemWithoutRef': result += getResultStringForArrayWithoutItemRef_1.getResultStringForArrayWithoutItemRef(props); break; case 'OneOf': result += getStandardString_1.getStandardString(__assign(__assign({}, props), { refType: props.oneOf[0][types_1.SwaggerProps.$ref].split('/'), isArray: false })); break; case 'Ref': result += getStandardString_1.getStandardString(__assign(__assign({}, props), { refType: props.$ref.split('/'), isArray: false })); break; case 'UndefinedTypeRefAndOneOf': result += getResultStringForUndefinedTypeRefAndOneOf_1.getResultStringForUndefinedTypeRefAndOneOf(props); break; case 'DictionaryKey': result += getResultStringForDictionaryKey_1.getResultStringForDictionaryKey(props); break; case 'AdditionalPropertiesType': result += getResultStringForAdditionalPropertiesType_1.getResultStringForAdditionalPropertiesType(props); break; case 'Invalid': default: result += getResultStringForInvalidSchemaProperties_1.getResultStringForInvalidSchemaProperties(__assign(__assign({}, props), { errorMessage: 'Invalid schema properties' })); break; } }); } result += '}\n'; return result; };