UNPKG

@protocolnebula/ts-openapi-generator

Version:

Build API and models from Swagger/OpenAPI to use in any project type

58 lines 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getApiDefaultModelName = exports.sortApi = exports.sortDependences = exports.getFixedTypeName = void 0; const case_1 = require("case"); const config_model_1 = require("../models/config.model"); const entities_store_1 = require("../stores/entities.store"); function getFixedTypeName(type) { const typesMapped = config_model_1.config.templateConfig.typesMapped; let newType = typesMapped[type]; if (newType !== undefined) { if (newType !== type) { console.debug('Type', type, 'changed to', newType); } return typesMapped[type]; } if (type.indexOf('#/') === 0) { if (entities_store_1.Store.models.getByUri(type)) { newType = type.substring(type.lastIndexOf('/') + 1); } else { newType = typesMapped.default; console.error(`ERROR: Type ${type}, not defined. ${newType} will be used.`); } } else { newType = typesMapped.default; console.warn(`WARNING: Type ${type}, not defined. ${newType} will be used.`); } return newType; } exports.getFixedTypeName = getFixedTypeName; function sortDependences(models) { return models.sort((a, b) => { let sort = 0; if (a.fileName > b.fileName) sort = 1; if (a.fileName < b.fileName) sort = -1; // console.debug ('Sorting:', a.name, 'vs', b.name, sort); return sort; }); } exports.sortDependences = sortDependences; function sortApi(apis) { return apis.sort((a, b) => { if (a.operationId > b.operationId) return 1; if (a.operationId < b.operationId) return -1; return 0; }); } exports.sortApi = sortApi; function getApiDefaultModelName(api, modelFor = 'request') { return (0, case_1.capital)(`${api.verb.toLowerCase()} ${api.name} ${modelFor}`, '', true); } exports.getApiDefaultModelName = getApiDefaultModelName; //# sourceMappingURL=models.util.js.map