codegen-openapi-ts 1.0.0 → 1.0.2
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/dist/index.d.ts +157 -0
- package/dist/index.js +1 -1
- package/package.json +3 -2
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
declare enum HttpClient {
|
|
2
|
+
FETCH = "fetch",
|
|
3
|
+
XHR = "xhr",
|
|
4
|
+
NODE = "node",
|
|
5
|
+
AXIOS = "axios"
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare enum Indent {
|
|
9
|
+
SPACE_4 = "4",
|
|
10
|
+
SPACE_2 = "2",
|
|
11
|
+
TAB = "tab"
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type Options = {
|
|
15
|
+
input: string | Record<string, any>;
|
|
16
|
+
output: string;
|
|
17
|
+
httpClient?: HttpClient;
|
|
18
|
+
clientName?: string;
|
|
19
|
+
useOptions?: boolean;
|
|
20
|
+
useUnionTypes?: boolean;
|
|
21
|
+
exportCore?: boolean;
|
|
22
|
+
exportServices?: boolean;
|
|
23
|
+
exportModels?: boolean;
|
|
24
|
+
exportSchemas?: boolean;
|
|
25
|
+
indent?: Indent;
|
|
26
|
+
postfixServices?: string;
|
|
27
|
+
postfixModels?: string;
|
|
28
|
+
request?: string;
|
|
29
|
+
write?: boolean;
|
|
30
|
+
selectedOnly?: boolean;
|
|
31
|
+
appendTemplate?: ReturnType<typeof defineConfig>['appendTemplate'];
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Generate the OpenAPI client. This method will read the OpenAPI specification and based on the
|
|
35
|
+
* given language it will generate the client, including the typed models, validation schemas,
|
|
36
|
+
* service layer, etc.
|
|
37
|
+
* @param input The relative location of the OpenAPI spec
|
|
38
|
+
* @param output The relative location of the output directory
|
|
39
|
+
* @param httpClient The selected httpClient (fetch, xhr, node or axios)
|
|
40
|
+
* @param clientName Custom client class name
|
|
41
|
+
* @param useOptions Use options or arguments functions
|
|
42
|
+
* @param useUnionTypes Use union types instead of enums
|
|
43
|
+
* @param exportCore Generate core client classes
|
|
44
|
+
* @param exportServices Generate services
|
|
45
|
+
* @param exportModels Generate models
|
|
46
|
+
* @param exportSchemas Generate schemas
|
|
47
|
+
* @param indent Indentation options (4, 2 or tab)
|
|
48
|
+
* @param postfixServices Service name postfix
|
|
49
|
+
* @param postfixModels Model name postfix
|
|
50
|
+
* @param request Path to custom request file
|
|
51
|
+
* @param write Write the files to disk (true or false)
|
|
52
|
+
*/
|
|
53
|
+
declare const generate: ({ input, output, httpClient, clientName, useOptions, useUnionTypes, exportCore, exportServices, exportModels, exportSchemas, indent, postfixServices, postfixModels, request, write, selectedOnly, appendTemplate, }: Options) => Promise<void>;
|
|
54
|
+
declare const _default: {
|
|
55
|
+
HttpClient: typeof HttpClient;
|
|
56
|
+
generate: ({ input, output, httpClient, clientName, useOptions, useUnionTypes, exportCore, exportServices, exportModels, exportSchemas, indent, postfixServices, postfixModels, request, write, selectedOnly, appendTemplate, }: Options) => Promise<void>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
declare function convertAndGenerate({ from, source }: {
|
|
60
|
+
from: string;
|
|
61
|
+
source: string;
|
|
62
|
+
}, { input, output, useOptions, useUnionTypes }: Options, urlMethodMapping?: ServiceConfigWithMappings['urlMethodMapping'], selectedOnly?: ServiceConfigWithMappings['selectedOnly'], modelNameMapping?: BaseServiceConfig['modelNameMapping'], appendTemplate?: ReturnType<typeof defineConfig>['appendTemplate'], proxyConfig?: BaseServiceConfig['proxyConfig']): Promise<void>;
|
|
63
|
+
type BaseServiceConfig = {
|
|
64
|
+
/**
|
|
65
|
+
* API Docs request url for the json response
|
|
66
|
+
*/
|
|
67
|
+
source: string;
|
|
68
|
+
/**
|
|
69
|
+
* Specify the API specs response format version
|
|
70
|
+
*/
|
|
71
|
+
from: 'swagger_1' | 'swagger_2' | 'openapi_3' | 'api_blueprint' | 'io_docs' | 'google' | 'raml' | 'wadl';
|
|
72
|
+
/**
|
|
73
|
+
* Specify the folder for the codegen output
|
|
74
|
+
*/
|
|
75
|
+
output: string;
|
|
76
|
+
/**
|
|
77
|
+
* Create a function for proxying the request
|
|
78
|
+
* @example
|
|
79
|
+
* {
|
|
80
|
+
* // ... other config
|
|
81
|
+
* proxyConfig: (path) => {
|
|
82
|
+
* return path.replace('/api/', '/be/')
|
|
83
|
+
* }
|
|
84
|
+
* }
|
|
85
|
+
* @param {string} path
|
|
86
|
+
*/
|
|
87
|
+
proxyConfig?: (path: string) => string;
|
|
88
|
+
/**
|
|
89
|
+
* Can be used to replace long model names specified on the schema.
|
|
90
|
+
* Please use the api-schema.json generated on root project folder
|
|
91
|
+
* to debug the desired results. Also note that the original schema name
|
|
92
|
+
* with dot (.) will be generated as underscore (_). Example:
|
|
93
|
+
* some.long.name will be generated as some_long_name,
|
|
94
|
+
* if this modelNameMapping supplied
|
|
95
|
+
* @example
|
|
96
|
+
* {
|
|
97
|
+
* // ... other config
|
|
98
|
+
* modelNameMapping: (json) => {
|
|
99
|
+
* // remember to use global flag to all regexp used here
|
|
100
|
+
* return config.replace(new RegExp('some.long.name', g), 'shortname')
|
|
101
|
+
* }
|
|
102
|
+
* }
|
|
103
|
+
*
|
|
104
|
+
* @param {string} json - stringified json schema
|
|
105
|
+
*/
|
|
106
|
+
modelNameMapping?: (json: string) => string;
|
|
107
|
+
};
|
|
108
|
+
type ServiceConfigDefault = BaseServiceConfig & {
|
|
109
|
+
urlMethodMapping: undefined;
|
|
110
|
+
selectedOnly: undefined;
|
|
111
|
+
};
|
|
112
|
+
declare type ServiceConfigWithMappings = BaseServiceConfig & {
|
|
113
|
+
/**
|
|
114
|
+
* Custom spec paths mapping. You can configure to rename the method name
|
|
115
|
+
* or customise the proxyUrl for the specific API
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* {
|
|
119
|
+
* // ... other config
|
|
120
|
+
* urlMethodMapping: [
|
|
121
|
+
* { originalUrl: '/pokemon-list', method: 'get', methodName: 'GetPokemonList' },
|
|
122
|
+
* { originalUrl: '/pokemon-detail/{id}', method: 'get', methodName: 'GetPokemonList', proxyUrl: '/proxy/pokemon-detail/{id}' }
|
|
123
|
+
* ]
|
|
124
|
+
* }
|
|
125
|
+
*
|
|
126
|
+
*/
|
|
127
|
+
urlMethodMapping: {
|
|
128
|
+
originalUrl: string;
|
|
129
|
+
method: 'get' | 'post' | 'put' | 'delete';
|
|
130
|
+
methodName: string;
|
|
131
|
+
proxyUrl?: string;
|
|
132
|
+
}[];
|
|
133
|
+
/**
|
|
134
|
+
* Flag to only generate listed specs based on urlMethodMapping.
|
|
135
|
+
* The codegen will still generate all the models listed on the api specs
|
|
136
|
+
*/
|
|
137
|
+
selectedOnly: boolean;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Type helper to make it easier to use codegen.config.js
|
|
141
|
+
*/
|
|
142
|
+
declare function defineConfig(config: {
|
|
143
|
+
/**
|
|
144
|
+
* Custom api templates append on top of service files
|
|
145
|
+
*/
|
|
146
|
+
appendTemplate?: string;
|
|
147
|
+
/**
|
|
148
|
+
* List config for every services
|
|
149
|
+
*/
|
|
150
|
+
services: (ServiceConfigDefault | ServiceConfigWithMappings)[];
|
|
151
|
+
}): {
|
|
152
|
+
appendTemplate?: string | undefined;
|
|
153
|
+
services: (ServiceConfigDefault | ServiceConfigWithMappings)[];
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export { HttpClient, Indent, convertAndGenerate, _default as default, defineConfig, generate };
|
|
157
|
+
export type { BaseServiceConfig, Options, ServiceConfigDefault, ServiceConfigWithMappings };
|