api-typescript-generator
Advanced tools
Comparing version 2.1.5 to 2.1.6
@@ -91,2 +91,5 @@ "use strict"; | ||
exports.defaultModelsRelativeDirPath = 'models'; | ||
function generateRegisterValidationSchemasFunctionName(scope) { | ||
return (0, string_utils_1.applyEntityNameCase)(`register ${scope} validation schemas`, 'camelCase'); | ||
} | ||
function generateModels({ extractedTags, validationContext, modelsConfig: { filenameFormat, relativeDirPath = exports.defaultModelsRelativeDirPath, defaultScope = 'common', generateName, generateJsDoc } = {}, commonValidationSchemaStorage, binaryTypes, jsDocRenderConfig, commentsConfig }) { | ||
@@ -174,2 +177,3 @@ const files = []; | ||
for (const [scope, fileSchemaInfos] of Object.entries(schemasByScopes)) { | ||
const modelRegisterValidationSchemaImports = {}; | ||
const filename = path_1.default.join('.', relativeDirPath, (0, string_utils_1.formatFilename)(scope, Object.assign(Object.assign({}, filenameFormat), { extension: '.ts' }))); | ||
@@ -182,3 +186,3 @@ const dependencyImports = {}; | ||
if (validationContext) { | ||
registerValidationSchemasImportName = (0, string_utils_1.applyEntityNameCase)(`register ${scope} validation schemas`, 'camelCase'); | ||
registerValidationSchemasImportName = generateRegisterValidationSchemasFunctionName(scope); | ||
} | ||
@@ -196,2 +200,10 @@ for (const { dependencies, modelName, schemaName, schema } of fileSchemaInfos) { | ||
}); | ||
if (validationContext) { | ||
const registerFunctionName = generateRegisterValidationSchemasFunctionName(depInfo.scope); | ||
(0, dependencies_1.addDependencyImport)(dependencyImports, depPath, depInfo.modelName, { | ||
kind: 'value', | ||
entity: { name: registerFunctionName } | ||
}); | ||
modelRegisterValidationSchemaImports[registerFunctionName] = true; | ||
} | ||
} | ||
@@ -224,6 +236,8 @@ exports.push((0, dependencies_1.extendDependenciesAndGetResult)(generateTypeExport({ | ||
const otherStatements = []; | ||
if (commonValidationSchemaStorage && | ||
registerValidationSchemasImportName && | ||
validationContext && | ||
validationStatements.length > 0) { | ||
if (Object.keys(modelRegisterValidationSchemaImports).length > 0 && validationContext) { | ||
validationStatements.push((0, types_1.expressionStatement)((0, types_1.callExpression)((0, types_1.memberExpression)((0, types_1.identifier)(validationContext.validationSchemaStorageImportName), (0, types_1.identifier)('registerOnce')), [ | ||
(0, types_1.arrayExpression)(Object.keys(modelRegisterValidationSchemaImports).map((registerCallbackName) => (0, types_1.identifier)(registerCallbackName))) | ||
]))); | ||
} | ||
if (commonValidationSchemaStorage && registerValidationSchemasImportName && validationContext) { | ||
(0, dependencies_1.addDependencyImport)(dependencyImports, (0, paths_1.getRelativeImportPath)(importPath, commonValidationSchemaStorage.importPath), commonValidationSchemaStorage.className, { | ||
@@ -230,0 +244,0 @@ kind: 'type', |
{ | ||
"name": "api-typescript-generator", | ||
"version": "2.1.5", | ||
"version": "2.1.6", | ||
"description": "Generates OpenAPI TypeScript client. Extremely fast and flexible.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
import path from 'path'; | ||
import { | ||
arrayExpression, | ||
blockStatement, | ||
@@ -150,2 +151,6 @@ callExpression, | ||
function generateRegisterValidationSchemasFunctionName(scope: string) { | ||
return applyEntityNameCase(`register ${scope} validation schemas`, 'camelCase'); | ||
} | ||
export function generateModels({ | ||
@@ -275,2 +280,3 @@ extractedTags, | ||
for (const [scope, fileSchemaInfos] of Object.entries(schemasByScopes)) { | ||
const modelRegisterValidationSchemaImports: Record<string, true> = {}; | ||
const filename = path.join('.', relativeDirPath, formatFilename(scope, {...filenameFormat, extension: '.ts'})); | ||
@@ -283,6 +289,3 @@ const dependencyImports: DependencyImports = {}; | ||
if (validationContext) { | ||
registerValidationSchemasImportName = applyEntityNameCase( | ||
`register ${scope} validation schemas`, | ||
'camelCase' | ||
); | ||
registerValidationSchemasImportName = generateRegisterValidationSchemasFunctionName(scope); | ||
} | ||
@@ -303,2 +306,10 @@ for (const {dependencies, modelName, schemaName, schema} of fileSchemaInfos) { | ||
}); | ||
if (validationContext) { | ||
const registerFunctionName = generateRegisterValidationSchemasFunctionName(depInfo.scope); | ||
addDependencyImport(dependencyImports, depPath, depInfo.modelName, { | ||
kind: 'value', | ||
entity: {name: registerFunctionName} | ||
}); | ||
modelRegisterValidationSchemaImports[registerFunctionName] = true; | ||
} | ||
} | ||
@@ -358,8 +369,22 @@ exports.push( | ||
const otherStatements: Statement[] = []; | ||
if ( | ||
commonValidationSchemaStorage && | ||
registerValidationSchemasImportName && | ||
validationContext && | ||
validationStatements.length > 0 | ||
) { | ||
if (Object.keys(modelRegisterValidationSchemaImports).length > 0 && validationContext) { | ||
validationStatements.push( | ||
expressionStatement( | ||
callExpression( | ||
memberExpression( | ||
identifier(validationContext.validationSchemaStorageImportName), | ||
identifier('registerOnce') | ||
), | ||
[ | ||
arrayExpression( | ||
Object.keys(modelRegisterValidationSchemaImports).map((registerCallbackName) => | ||
identifier(registerCallbackName) | ||
) | ||
) | ||
] | ||
) | ||
) | ||
); | ||
} | ||
if (commonValidationSchemaStorage && registerValidationSchemasImportName && validationContext) { | ||
addDependencyImport( | ||
@@ -366,0 +391,0 @@ dependencyImports, |
671933
12782