api-typescript-generator
Advanced tools
@@ -62,3 +62,3 @@ [api-typescript-generator](../../README.md) / [Modules](../modules.md) / [openapi-client](../modules/openapi_client.md) / OpenApiClientGeneratorConfigClient | ||
• `Optional` **exportModels**: ``"all"`` \| ``"none"`` \| \{ `models`: `string`[] } | ||
• `Optional` **exportModels**: ``"all"`` \| ``"none"`` \| \{ `models`: `string`[] } \| \{ `schemas`: `string`[] } | ||
@@ -65,0 +65,0 @@ Whether to export models from the client file. |
@@ -24,2 +24,18 @@ "use strict"; | ||
const defaultServerUrl = 'http://example.com'; | ||
function calculateModelNamesToExport(exportModels = 'none', modelImportInfos) { | ||
if (exportModels === 'none') { | ||
return new Set(); | ||
} | ||
if (exportModels === 'all') { | ||
return new Set(modelImportInfos.map(({ modelName }) => modelName)); | ||
} | ||
if ('models' in exportModels) { | ||
return new Set(exportModels.models); | ||
} | ||
if ('schemas' in exportModels) { | ||
const schemaNamesSet = new Set(exportModels.schemas); | ||
return new Set(modelImportInfos.filter(({ schemaName }) => schemaNamesSet.has(schemaName)).map(({ modelName }) => modelName)); | ||
} | ||
throw new Error('Invalid exportModels configuration.'); | ||
} | ||
function generateClient(_a) { | ||
@@ -109,14 +125,12 @@ var _b, _c, _d; | ||
exportTypes.exportKind = 'type'; | ||
if (exportModels && exportModels !== 'none') { | ||
const modelsToExport = new Set(exportModels === 'all' ? modelImportInfos.map(({ modelName }) => modelName) : exportModels.models); | ||
for (const { modelName, importPath } of modelImportInfos) { | ||
if (!modelsToExport.has(modelName)) { | ||
continue; | ||
} | ||
(0, dependencies_1.addDependencyImport)(dependencyImports, (0, paths_1.getRelativeImportPath)(clientImportPath, importPath), modelName, { | ||
kind: 'type', | ||
entity: { name: modelName } | ||
}); | ||
exportTypes.specifiers.push((0, types_1.exportSpecifier)((0, types_1.identifier)(modelName), (0, types_1.identifier)(modelName))); | ||
const modelNamesToExport = calculateModelNamesToExport(exportModels, modelImportInfos); | ||
for (const { modelName, importPath } of modelImportInfos) { | ||
if (!modelNamesToExport.has(modelName)) { | ||
continue; | ||
} | ||
(0, dependencies_1.addDependencyImport)(dependencyImports, (0, paths_1.getRelativeImportPath)(clientImportPath, importPath), modelName, { | ||
kind: 'type', | ||
entity: { name: modelName } | ||
}); | ||
exportTypes.specifiers.push((0, types_1.exportSpecifier)((0, types_1.identifier)(modelName), (0, types_1.identifier)(modelName))); | ||
} | ||
@@ -123,0 +137,0 @@ const exports = (0, types_1.exportNamedDeclaration)(null, []); |
@@ -8,2 +8,3 @@ import { JsDocRenderConfig } from '../../utils/jsdoc'; | ||
modelName: string; | ||
schemaName: string; | ||
importPath: string; | ||
@@ -10,0 +11,0 @@ registerValidationSchemasImportName?: string; |
@@ -227,2 +227,3 @@ "use strict"; | ||
modelName, | ||
schemaName, | ||
importPath, | ||
@@ -229,0 +230,0 @@ registerValidationSchemasImportName |
@@ -153,2 +153,4 @@ import { ValidationProvider } from './common/validation-providers/validation-provider'; | ||
models: string[]; | ||
} | { | ||
schemas: string[]; | ||
}; | ||
@@ -155,0 +157,0 @@ exportErrorClass?: boolean; |
{ | ||
"name": "api-typescript-generator", | ||
"version": "2.4.21", | ||
"version": "2.4.22", | ||
"description": "Generates OpenAPI TypeScript client. Extremely fast and flexible.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
463835
0.14%6654
0.27%