mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
const path = require('path');
|
|
const ts = require('typescript');
|
|
const OpenAPI = require('../dist');
|
|
|
|
function compile(dir) {
|
|
const config = {
|
|
compilerOptions: {
|
|
target: 'esnext',
|
|
module: 'commonjs',
|
|
moduleResolution: 'node',
|
|
},
|
|
include: ['./index.ts'],
|
|
};
|
|
const configFile = ts.parseConfigFileTextToJson('tsconfig.json', JSON.stringify(config));
|
|
const configFileResult = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.resolve(process.cwd(), dir), undefined, 'tsconfig.json');
|
|
const compilerHost = ts.createCompilerHost(configFileResult.options);
|
|
const compiler = ts.createProgram(configFileResult.fileNames, configFileResult.options, compilerHost);
|
|
compiler.emit();
|
|
}
|
|
|
|
console.time('generate');
|
|
|
|
OpenAPI.generate({
|
|
input: './test/mock/v2/spec.json',
|
|
output: './test/result/v2/',
|
|
httpClient: OpenAPI.HttpClient.FETCH,
|
|
useOptions: true,
|
|
useUnionTypes: true,
|
|
exportSchemas: true,
|
|
exportServices: true,
|
|
});
|
|
|
|
OpenAPI.generate({
|
|
input: './test/mock/v3/spec.json',
|
|
output: './test/result/v3/',
|
|
httpClient: OpenAPI.HttpClient.FETCH,
|
|
useOptions: true,
|
|
useUnionTypes: true,
|
|
exportSchemas: true,
|
|
exportServices: true,
|
|
});
|
|
|
|
console.timeEnd('generate');
|
|
|
|
compile('./test/result/v2/');
|
|
compile('./test/result/v3/');
|