codegen-openapi-ts 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +216 -274
- package/bin/cli.js +35 -35
- package/bin/index.js +49 -49
- package/dist/index.d.ts +72 -0
- package/dist/index.js +1 -1
- package/package.json +113 -112
- package/types/helper.d.ts +58 -58
- package/types/index.d.ts +22 -22
package/bin/index.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
const path = require('path');
|
|
6
|
-
const program = require('commander');
|
|
7
|
-
const esmConfig = require('esm-config');
|
|
8
|
-
const pkg = require('../package.json');
|
|
9
|
-
const OpenAPI = require(path.resolve(__dirname, '../dist/index.js'));
|
|
10
|
-
|
|
11
|
-
const appRoot = process.cwd().split('/node_modules')[0]
|
|
12
|
-
|
|
13
|
-
const params = program
|
|
14
|
-
.name('codegen-openapi-ts')
|
|
15
|
-
.usage('[options]')
|
|
16
|
-
.version(pkg.version)
|
|
17
|
-
.option('--config <value>', 'Path to config file', 'codegen.config.js')
|
|
18
|
-
.parse(process.argv)
|
|
19
|
-
.opts();
|
|
20
|
-
|
|
21
|
-
async function generateOnConfig () {
|
|
22
|
-
try {
|
|
23
|
-
const configFile = await esmConfig(path.join(appRoot, params.config))
|
|
24
|
-
|
|
25
|
-
for (let i = 0; i < configFile.length; i++) {
|
|
26
|
-
console.log('Generating ' + configFile[i].source)
|
|
27
|
-
await OpenAPI.convertAndGenerate(
|
|
28
|
-
{
|
|
29
|
-
from: configFile[i].from,
|
|
30
|
-
to: 'openapi_3',
|
|
31
|
-
source: configFile[i].source
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
input: 'api-schema.json',
|
|
35
|
-
output: configFile[i].output || 'output',
|
|
36
|
-
useOptions: true,
|
|
37
|
-
useUnionTypes: true
|
|
38
|
-
},
|
|
39
|
-
configFile[i].urlMethodMapping || [],
|
|
40
|
-
configFile[i].selectedOnly || false,
|
|
41
|
-
configFile[i].modelNameMapping || []
|
|
42
|
-
)
|
|
43
|
-
}
|
|
44
|
-
} catch (err) {
|
|
45
|
-
console.log(err)
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
generateOnConfig()
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const program = require('commander');
|
|
7
|
+
const esmConfig = require('esm-config');
|
|
8
|
+
const pkg = require('../package.json');
|
|
9
|
+
const OpenAPI = require(path.resolve(__dirname, '../dist/index.js'));
|
|
10
|
+
|
|
11
|
+
const appRoot = process.cwd().split('/node_modules')[0]
|
|
12
|
+
|
|
13
|
+
const params = program
|
|
14
|
+
.name('codegen-openapi-ts')
|
|
15
|
+
.usage('[options]')
|
|
16
|
+
.version(pkg.version)
|
|
17
|
+
.option('--config <value>', 'Path to config file', 'codegen.config.js')
|
|
18
|
+
.parse(process.argv)
|
|
19
|
+
.opts();
|
|
20
|
+
|
|
21
|
+
async function generateOnConfig () {
|
|
22
|
+
try {
|
|
23
|
+
const configFile = await esmConfig(path.join(appRoot, params.config))
|
|
24
|
+
|
|
25
|
+
for (let i = 0; i < configFile.length; i++) {
|
|
26
|
+
console.log('Generating ' + configFile[i].source)
|
|
27
|
+
await OpenAPI.convertAndGenerate(
|
|
28
|
+
{
|
|
29
|
+
from: configFile[i].from,
|
|
30
|
+
to: 'openapi_3',
|
|
31
|
+
source: configFile[i].source
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
input: 'api-schema.json',
|
|
35
|
+
output: configFile[i].output || 'output',
|
|
36
|
+
useOptions: true,
|
|
37
|
+
useUnionTypes: true
|
|
38
|
+
},
|
|
39
|
+
configFile[i].urlMethodMapping || [],
|
|
40
|
+
configFile[i].selectedOnly || false,
|
|
41
|
+
configFile[i].modelNameMapping || []
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
} catch (err) {
|
|
45
|
+
console.log(err)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
generateOnConfig()
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ConverterInput } from 'api-spec-converter';
|
|
2
|
+
import { HttpClient } from './HttpClient';
|
|
3
|
+
export { HttpClient } from './HttpClient';
|
|
4
|
+
export declare type Options = {
|
|
5
|
+
input: string | Record<string, any>;
|
|
6
|
+
output: string;
|
|
7
|
+
httpClient?: HttpClient;
|
|
8
|
+
useOptions?: boolean;
|
|
9
|
+
useUnionTypes?: boolean;
|
|
10
|
+
exportCore?: boolean;
|
|
11
|
+
exportServices?: boolean;
|
|
12
|
+
exportModels?: boolean;
|
|
13
|
+
exportSchemas?: boolean;
|
|
14
|
+
postfix?: string;
|
|
15
|
+
request?: string;
|
|
16
|
+
write?: boolean;
|
|
17
|
+
selectedOnly?: boolean;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Generate the OpenAPI client. This method will read the OpenAPI specification and based on the
|
|
21
|
+
* given language it will generate the client, including the typed models, validation schemas,
|
|
22
|
+
* service layer, etc.
|
|
23
|
+
* @param input The relative location of the OpenAPI spec
|
|
24
|
+
* @param output The relative location of the output directory
|
|
25
|
+
* @param httpClient The selected httpClient (fetch, xhr, node or axios)
|
|
26
|
+
* @param useUnionTypes Use union types instead of enums
|
|
27
|
+
* @param exportCore: Generate core client classes
|
|
28
|
+
* @param exportServices: Generate services
|
|
29
|
+
* @param exportModels: Generate models
|
|
30
|
+
* @param exportSchemas: Generate schemas
|
|
31
|
+
* @param postfix: Service name postfix
|
|
32
|
+
* @param request: Path to custom request file
|
|
33
|
+
* @param write Write the files to disk (true or false)
|
|
34
|
+
*/
|
|
35
|
+
export declare function generate({ input, output, httpClient, useOptions, useUnionTypes, exportCore, exportServices, exportModels, exportSchemas, postfix, request, write, selectedOnly }: Options): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Generate the OpenAPI client with options to convert swagger to openapi etc.
|
|
38
|
+
* @param converterInput.from The schema specification for the response (swagger_1, swagger_2, openapi_3)
|
|
39
|
+
* @param converterInput.to The schema specification for the output (openapi_3)
|
|
40
|
+
* @param converterInput.source The relative location of the OpenAPI spec
|
|
41
|
+
* @param options.httpClient The selected httpClient (fetch, xhr, node or axios)
|
|
42
|
+
* @param options.useUnionTypes Use union types instead of enums
|
|
43
|
+
* @param options.exportCore: Generate core client classes
|
|
44
|
+
* @param options.exportServices: Generate services
|
|
45
|
+
* @param options.exportModels: Generate models
|
|
46
|
+
* @param options.exportSchemas: Generate schemas
|
|
47
|
+
* @param options.postfix: Service name postfix
|
|
48
|
+
* @param options.request: Path to custom request file
|
|
49
|
+
* @param options.write Write the files to disk (true or false)
|
|
50
|
+
*/
|
|
51
|
+
export declare function convertAndGenerate({ from, to, source }: ConverterInput, { input, output, useOptions, useUnionTypes }: Options, urlMethodMapping?: BaseConfigWithMappings['urlMethodMapping'], selectedOnly?: BaseConfigWithMappings['selectedOnly'], modelNameMapping?: BaseConfig['modelNameMapping']): Promise<void>;
|
|
52
|
+
export declare type BaseConfig = {
|
|
53
|
+
source: string;
|
|
54
|
+
from: 'swagger_1' | 'swagger_2' | 'openapi_3' | 'api_blueprint' | 'io_docs' | 'google' | 'raml' | 'wadl';
|
|
55
|
+
output: string;
|
|
56
|
+
modelNameMapping?: [string, string][];
|
|
57
|
+
};
|
|
58
|
+
export declare type BaseConfigDefault = BaseConfig & {
|
|
59
|
+
urlMethodMapping: undefined;
|
|
60
|
+
selectedOnly: undefined;
|
|
61
|
+
};
|
|
62
|
+
export declare type BaseConfigWithMappings = BaseConfig & {
|
|
63
|
+
urlMethodMapping: [
|
|
64
|
+
string,
|
|
65
|
+
string,
|
|
66
|
+
'get' | 'post' | 'put' | 'delete',
|
|
67
|
+
string,
|
|
68
|
+
string?
|
|
69
|
+
][];
|
|
70
|
+
selectedOnly: boolean;
|
|
71
|
+
};
|
|
72
|
+
export declare function defineConfig(config: (BaseConfigDefault | BaseConfigWithMappings)[]): (BaseConfigWithMappings | BaseConfigDefault)[];
|