UNPKG

openapi-codegen-typescript

Version:

OpenApi codegen for generating types an mocks from swagger json file

19 lines (18 loc) 662 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Converts object: {type: ... , enum: ['one', 'two', 'three']} * to "export type ${name} = 'one' | 'two' | 'three';" */ exports.parseEnum = function (_a) { var schema = _a.schema, schemaKey = _a.schemaKey; var description = schema.description; var result = (description ? "/**\n * " + description + "\n */\n" : '') + "export type " + schemaKey + " = "; var enums = schema.enum; var len = enums.length; for (var i = 0; i < len; i++) { result += "'" + enums[i] + "'" + (i !== len - 1 ? ' | ' : ';'); } result += '\n'; return result; };