mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
- Also checking if we can compile, looking good
This commit is contained in:
parent
05d5a10599
commit
ea6a46a4c3
17
src/index.ts
17
src/index.ts
@ -6,6 +6,7 @@ import { getOpenApiSpec } from './utils/getOpenApiSpec';
|
||||
import { writeClient } from './utils/writeClient';
|
||||
import * as os from 'os';
|
||||
import * as chalk from 'chalk';
|
||||
import * as ts from 'typescript';
|
||||
import { getOpenApiVersion, OpenApiVersion } from './utils/getOpenApiVersion';
|
||||
|
||||
export enum Language {
|
||||
@ -65,3 +66,19 @@ export function generate(input: string, output: string, language: Language = Lan
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
export function compile(dir: string): void {
|
||||
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();
|
||||
}
|
||||
|
||||
@ -7,9 +7,9 @@ import { Result } from './Result';
|
||||
import { isSuccess } from './isSuccess';
|
||||
|
||||
/**
|
||||
* Request content using the new legacy XMLHttpRequest API. This method is usefull
|
||||
* Request content using the new legacy XMLHttpRequest API. This method is useful
|
||||
* when we want to request UTF-16 content, since it natively supports loading UTF-16.
|
||||
* We could do the same with the Fetch API, but then we will need to conver the
|
||||
* We could do the same with the Fetch API, but then we will need to convert the
|
||||
* content using JavaScript... And that is very very slow.
|
||||
* @param url The url to request.
|
||||
* @param request The request object, containing method, headers, body, etc.
|
||||
|
||||
@ -11,34 +11,44 @@ OpenAPI.generate(
|
||||
OpenAPI.HttpClient.FETCH,
|
||||
);
|
||||
|
||||
// OpenAPI.generate(
|
||||
// './test/mock/v2/test-addon.json',
|
||||
// './test/tmp/v2/ts/test-addon',
|
||||
// OpenAPI.Language.TYPESCRIPT,
|
||||
// OpenAPI.HttpClient.FETCH,
|
||||
// );
|
||||
//
|
||||
// OpenAPI.generate(
|
||||
// './test/mock/v2/test-docs.json',
|
||||
// './test/tmp/v2/ts/test-docs',
|
||||
// OpenAPI.Language.TYPESCRIPT,
|
||||
// OpenAPI.HttpClient.FETCH,
|
||||
// );
|
||||
//
|
||||
OpenAPI.generate(
|
||||
'./test/mock/v2/test-addon.json',
|
||||
'./test/tmp/v2/ts/test-addon',
|
||||
OpenAPI.Language.TYPESCRIPT,
|
||||
OpenAPI.HttpClient.FETCH,
|
||||
);
|
||||
|
||||
OpenAPI.generate(
|
||||
'./test/mock/v2/test-docs.json',
|
||||
'./test/tmp/v2/ts/test-docs',
|
||||
OpenAPI.Language.TYPESCRIPT,
|
||||
OpenAPI.HttpClient.FETCH,
|
||||
);
|
||||
|
||||
OpenAPI.generate(
|
||||
'./test/mock/v2/test-sites.json',
|
||||
'./test/tmp/v2/ts/test-sites',
|
||||
OpenAPI.Language.TYPESCRIPT,
|
||||
OpenAPI.HttpClient.FETCH,
|
||||
);
|
||||
//
|
||||
// OpenAPI.generate(
|
||||
// './test/mock/v2/test-petstore.yaml',
|
||||
// './test/tmp/v2/ts/test-petstore-yaml',
|
||||
// OpenAPI.Language.TYPESCRIPT,
|
||||
// OpenAPI.HttpClient.FETCH,
|
||||
// );
|
||||
//
|
||||
|
||||
OpenAPI.generate(
|
||||
'./test/mock/v2/test-petstore.yaml',
|
||||
'./test/tmp/v2/ts/test-petstore-yaml',
|
||||
OpenAPI.Language.TYPESCRIPT,
|
||||
OpenAPI.HttpClient.FETCH,
|
||||
);
|
||||
|
||||
OpenAPI.compile('./test/tmp/v2/ts/spec');
|
||||
|
||||
OpenAPI.compile('./test/tmp/v2/ts/test-addon');
|
||||
|
||||
OpenAPI.compile('./test/tmp/v2/ts/test-docs');
|
||||
|
||||
OpenAPI.compile('./test/tmp/v2/ts/test-sites');
|
||||
|
||||
OpenAPI.compile('./test/tmp/v2/ts/test-petstore-yaml');
|
||||
|
||||
// OpenAPI.generate(
|
||||
// './test/mock/v3/test-petstore.json',
|
||||
// './test/tmp/v3/test-petstore-json',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user