@openapi-qraft/openapi-typescript-plugin 1.0.1
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/CHANGELOG.md +21 -0
- package/dist/generateSchemaTypes.d.ts +12 -0
- package/dist/generateSchemaTypes.d.ts.map +1 -0
- package/dist/generateSchemaTypes.js +37 -0
- package/dist/generateSchemaTypes.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/createOpenapiTypesImportPath.d.ts +12 -0
- package/dist/lib/createOpenapiTypesImportPath.d.ts.map +1 -0
- package/dist/lib/createOpenapiTypesImportPath.js +28 -0
- package/dist/lib/createOpenapiTypesImportPath.js.map +1 -0
- package/dist/plugin.d.ts +4 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +75 -0
- package/dist/plugin.js.map +1 -0
- package/package.json +50 -0
- package/src/__snapshots__/no-extra-options.ts.snapshot.ts +577 -0
- package/src/__snapshots__/with-extra-options.ts.snapshot.ts +259 -0
- package/src/generateSchemaTypes.ts +77 -0
- package/src/index.ts +3 -0
- package/src/lib/createOpenapiTypesImportPath.ts +33 -0
- package/src/plugin.ts +140 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was auto-generated by @openapi-qraft/cli.
|
|
3
|
+
* Do not make direct changes to the file.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface paths {
|
|
7
|
+
"/files": {
|
|
8
|
+
parameters: {
|
|
9
|
+
query?: never;
|
|
10
|
+
header?: never;
|
|
11
|
+
path?: never;
|
|
12
|
+
cookie?: never;
|
|
13
|
+
};
|
|
14
|
+
/** Get a files by ID */
|
|
15
|
+
get: operations["get_files"];
|
|
16
|
+
put?: never;
|
|
17
|
+
/** Upload a files by ID */
|
|
18
|
+
post: operations["post_files"];
|
|
19
|
+
delete?: never;
|
|
20
|
+
options?: never;
|
|
21
|
+
head?: never;
|
|
22
|
+
patch?: never;
|
|
23
|
+
trace?: never;
|
|
24
|
+
};
|
|
25
|
+
"/files/list": {
|
|
26
|
+
parameters: {
|
|
27
|
+
query?: never;
|
|
28
|
+
header?: never;
|
|
29
|
+
path?: never;
|
|
30
|
+
cookie?: never;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Get a file list
|
|
34
|
+
* @deprecated
|
|
35
|
+
*/
|
|
36
|
+
get: operations["get_file_list"];
|
|
37
|
+
put?: never;
|
|
38
|
+
post?: never;
|
|
39
|
+
delete?: never;
|
|
40
|
+
options?: never;
|
|
41
|
+
head?: never;
|
|
42
|
+
patch?: never;
|
|
43
|
+
trace?: never;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export type webhooks = Record<string, never>;
|
|
47
|
+
export interface components {
|
|
48
|
+
schemas: {
|
|
49
|
+
EntityOnboardingDocuments: {
|
|
50
|
+
verification_document_front: string;
|
|
51
|
+
verification_document_back?: string;
|
|
52
|
+
};
|
|
53
|
+
ErrorSchema: {
|
|
54
|
+
message: string;
|
|
55
|
+
};
|
|
56
|
+
ErrorSchemaResponse: {
|
|
57
|
+
error: components["schemas"]["ErrorSchema"];
|
|
58
|
+
};
|
|
59
|
+
HTTPValidationError: {
|
|
60
|
+
detail?: components["schemas"]["ValidationError"][];
|
|
61
|
+
};
|
|
62
|
+
ValidationError: {
|
|
63
|
+
loc: (string | number)[];
|
|
64
|
+
msg: string;
|
|
65
|
+
type: string;
|
|
66
|
+
};
|
|
67
|
+
ApprovalPolicyUpdate: {
|
|
68
|
+
/** @description The name of the approval policy. */
|
|
69
|
+
name?: string;
|
|
70
|
+
/** @description A brief description of the approval policy. */
|
|
71
|
+
description?: string;
|
|
72
|
+
/** @description A list of JSON objects that represents the approval policy script. The script contains the logic that determines whether an action should be sent to approval. This field is required, and it should contain at least one script object. */
|
|
73
|
+
script?: (boolean | number | string | unknown[] | Record<string, never>)[];
|
|
74
|
+
/**
|
|
75
|
+
* @description A JSON object that represents the trigger for the approval policy. The trigger specifies the event that will trigger the policy to be evaluated.
|
|
76
|
+
* @example {amount >= 1000}
|
|
77
|
+
*/
|
|
78
|
+
trigger?: boolean | number | string | unknown[] | Record<string, never>;
|
|
79
|
+
/** @description A string that represents the current status of the approval policy. */
|
|
80
|
+
status?: components["schemas"]["ApprovalPolicyStatus"];
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* @description An enumeration.
|
|
84
|
+
* @enum {string}
|
|
85
|
+
*/
|
|
86
|
+
ApprovalPolicyStatus: "active" | "deleted" | "pending";
|
|
87
|
+
ApprovalPolicyResource: {
|
|
88
|
+
/** @description The name of the approval policy. */
|
|
89
|
+
name: string;
|
|
90
|
+
/** @description A brief description of the approval policy. */
|
|
91
|
+
description: string;
|
|
92
|
+
/** Format: uuid */
|
|
93
|
+
id: string;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* @description An enumeration.
|
|
97
|
+
* @enum {string}
|
|
98
|
+
*/
|
|
99
|
+
OrderEnum: "asc" | "desc";
|
|
100
|
+
FilesResponse: {
|
|
101
|
+
data: components["schemas"]["FileResponse"][];
|
|
102
|
+
};
|
|
103
|
+
FileResponse: {
|
|
104
|
+
/** Format: uuid */
|
|
105
|
+
id: string;
|
|
106
|
+
file_type: string;
|
|
107
|
+
name: string;
|
|
108
|
+
url: string;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
responses: never;
|
|
112
|
+
parameters: never;
|
|
113
|
+
requestBodies: never;
|
|
114
|
+
headers: never;
|
|
115
|
+
pathItems: never;
|
|
116
|
+
}
|
|
117
|
+
export type $defs = Record<string, never>;
|
|
118
|
+
export interface operations {
|
|
119
|
+
get_files: {
|
|
120
|
+
parameters: {
|
|
121
|
+
query: {
|
|
122
|
+
id__in: string[];
|
|
123
|
+
/** @description Page number */
|
|
124
|
+
page?: string;
|
|
125
|
+
};
|
|
126
|
+
header: {
|
|
127
|
+
/** @example 2023-06-04 */
|
|
128
|
+
"x-monite-version": string;
|
|
129
|
+
};
|
|
130
|
+
path?: never;
|
|
131
|
+
cookie?: never;
|
|
132
|
+
};
|
|
133
|
+
requestBody?: never;
|
|
134
|
+
responses: {
|
|
135
|
+
/** @description Successful Response */
|
|
136
|
+
200: {
|
|
137
|
+
headers: {
|
|
138
|
+
[name: string]: unknown;
|
|
139
|
+
};
|
|
140
|
+
content: {
|
|
141
|
+
"application/json": {
|
|
142
|
+
header?: {
|
|
143
|
+
/** Format: date */
|
|
144
|
+
"x-monite-version"?: string;
|
|
145
|
+
};
|
|
146
|
+
query?: {
|
|
147
|
+
id__in?: string[];
|
|
148
|
+
/** @description Page number */
|
|
149
|
+
page?: string;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
/** @description Method Not Allowed */
|
|
155
|
+
405: {
|
|
156
|
+
headers: {
|
|
157
|
+
[name: string]: unknown;
|
|
158
|
+
};
|
|
159
|
+
content: {
|
|
160
|
+
"application/json": components["schemas"]["ErrorSchemaResponse"];
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
/** @description Validation Error */
|
|
164
|
+
422: {
|
|
165
|
+
headers: {
|
|
166
|
+
[name: string]: unknown;
|
|
167
|
+
};
|
|
168
|
+
content: {
|
|
169
|
+
"application/json": components["schemas"]["HTTPValidationError"];
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
/** @description Internal Server Error */
|
|
173
|
+
default: {
|
|
174
|
+
headers: {
|
|
175
|
+
[name: string]: unknown;
|
|
176
|
+
};
|
|
177
|
+
content: {
|
|
178
|
+
"application/json": components["schemas"]["ErrorSchemaResponse"];
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
post_files: {
|
|
184
|
+
parameters: {
|
|
185
|
+
query?: never;
|
|
186
|
+
header?: never;
|
|
187
|
+
path?: never;
|
|
188
|
+
cookie?: never;
|
|
189
|
+
};
|
|
190
|
+
requestBody?: {
|
|
191
|
+
content: {
|
|
192
|
+
"multipart/form-data": {
|
|
193
|
+
/** Format: binary */
|
|
194
|
+
file?: string;
|
|
195
|
+
file_description?: string;
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
responses: {
|
|
200
|
+
/** @description Successful Response */
|
|
201
|
+
200: {
|
|
202
|
+
headers: {
|
|
203
|
+
[name: string]: unknown;
|
|
204
|
+
};
|
|
205
|
+
content: {
|
|
206
|
+
"application/json": {
|
|
207
|
+
body?: {
|
|
208
|
+
file?: string;
|
|
209
|
+
file_description?: string;
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
/** @description Internal Server Error */
|
|
215
|
+
default: {
|
|
216
|
+
headers: {
|
|
217
|
+
[name: string]: unknown;
|
|
218
|
+
};
|
|
219
|
+
content: {
|
|
220
|
+
"application/json": components["schemas"]["ErrorSchemaResponse"];
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
get_file_list: {
|
|
226
|
+
parameters: {
|
|
227
|
+
query?: {
|
|
228
|
+
id__in?: string[];
|
|
229
|
+
};
|
|
230
|
+
header?: {
|
|
231
|
+
/** @example 2023-06-04 */
|
|
232
|
+
"x-monite-version"?: string;
|
|
233
|
+
};
|
|
234
|
+
path?: never;
|
|
235
|
+
cookie?: never;
|
|
236
|
+
};
|
|
237
|
+
requestBody?: never;
|
|
238
|
+
responses: {
|
|
239
|
+
/** @description Successful Response */
|
|
240
|
+
200: {
|
|
241
|
+
headers: {
|
|
242
|
+
[name: string]: unknown;
|
|
243
|
+
};
|
|
244
|
+
content: {
|
|
245
|
+
"application/json": components["schemas"]["FilesResponse"];
|
|
246
|
+
};
|
|
247
|
+
};
|
|
248
|
+
/** @description Internal Server Error */
|
|
249
|
+
default: {
|
|
250
|
+
headers: {
|
|
251
|
+
[name: string]: unknown;
|
|
252
|
+
};
|
|
253
|
+
content: {
|
|
254
|
+
"application/json": components["schemas"]["ErrorSchemaResponse"];
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { createConfig } from '@redocly/openapi-core';
|
|
2
|
+
|
|
3
|
+
import type { Readable } from 'node:stream';
|
|
4
|
+
import openapiTS, {
|
|
5
|
+
astToString,
|
|
6
|
+
type OpenAPI3,
|
|
7
|
+
type OpenAPITSOptions,
|
|
8
|
+
SchemaObject,
|
|
9
|
+
} from 'openapi-typescript';
|
|
10
|
+
import ts from 'typescript';
|
|
11
|
+
|
|
12
|
+
export async function generateSchemaTypes(
|
|
13
|
+
schema: string | URL | OpenAPI3 | Readable | Buffer,
|
|
14
|
+
{
|
|
15
|
+
silent,
|
|
16
|
+
args,
|
|
17
|
+
}: {
|
|
18
|
+
silent: boolean;
|
|
19
|
+
args: Pick<
|
|
20
|
+
OpenAPITSOptions,
|
|
21
|
+
| 'additionalProperties'
|
|
22
|
+
| 'alphabetize'
|
|
23
|
+
| 'arrayLength'
|
|
24
|
+
| 'defaultNonNullable'
|
|
25
|
+
| 'emptyObjectsUnknown'
|
|
26
|
+
| 'enum'
|
|
27
|
+
| 'excludeDeprecated'
|
|
28
|
+
| 'exportType'
|
|
29
|
+
| 'immutable'
|
|
30
|
+
| 'pathParamsAsTypes'
|
|
31
|
+
| 'propertiesRequiredByDefault'
|
|
32
|
+
> & {
|
|
33
|
+
blobFromBinary?: boolean;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
) {
|
|
37
|
+
return astToString(
|
|
38
|
+
await openapiTS(schema, {
|
|
39
|
+
transform: args.blobFromBinary ? transformFormatBinary : undefined,
|
|
40
|
+
additionalProperties: args.additionalProperties,
|
|
41
|
+
alphabetize: args.alphabetize,
|
|
42
|
+
arrayLength: args.arrayLength,
|
|
43
|
+
// contentNever: args.contentNever, // todo::add `contentNever` in new version
|
|
44
|
+
defaultNonNullable: args.defaultNonNullable,
|
|
45
|
+
emptyObjectsUnknown: args.emptyObjectsUnknown,
|
|
46
|
+
enum: args.enum,
|
|
47
|
+
excludeDeprecated: args.excludeDeprecated,
|
|
48
|
+
exportType: args.exportType,
|
|
49
|
+
immutable: args.immutable,
|
|
50
|
+
pathParamsAsTypes: args.pathParamsAsTypes,
|
|
51
|
+
redocly: await createConfig({}, { extends: ['minimal'] }),
|
|
52
|
+
propertiesRequiredByDefault: args.propertiesRequiredByDefault,
|
|
53
|
+
silent,
|
|
54
|
+
})
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function transformFormatBinary(schemaObject: SchemaObject) {
|
|
59
|
+
if (schemaObject.format !== 'binary') return;
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
schema: schemaObject.nullable
|
|
63
|
+
? ts.factory.createUnionTypeNode([
|
|
64
|
+
ts.factory.createTypeReferenceNode(
|
|
65
|
+
ts.factory.createIdentifier('Blob'),
|
|
66
|
+
undefined
|
|
67
|
+
),
|
|
68
|
+
ts.factory.createLiteralTypeNode(ts.factory.createNull()),
|
|
69
|
+
])
|
|
70
|
+
: ts.factory.createTypeReferenceNode(
|
|
71
|
+
ts.factory.createIdentifier('Blob'),
|
|
72
|
+
undefined
|
|
73
|
+
),
|
|
74
|
+
// questionToken will be inferred by `openapiTS`, if true, it will force `?` for parameter
|
|
75
|
+
questionToken: false,
|
|
76
|
+
};
|
|
77
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create the import path for the OpenAPI types file.
|
|
3
|
+
* @param openapiTypesFileName The file name of the OpenAPI types file. Eg: `schema.d.ts`
|
|
4
|
+
* @param explicitImportExtensions Whether to include explicit `.js` extensions in the import path.
|
|
5
|
+
*/
|
|
6
|
+
export function createOpenapiTypesImportPath(
|
|
7
|
+
openapiTypesFileName: string,
|
|
8
|
+
explicitImportExtensions: boolean
|
|
9
|
+
) {
|
|
10
|
+
return explicitImportExtensions
|
|
11
|
+
? `../${getTypeScriptFileBaseName(openapiTypesFileName)}.js`
|
|
12
|
+
: `../${openapiTypesFileName}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Get the base name of the TypeScript file without the extension.
|
|
17
|
+
* Removes `.d.ts` or `.ts` from the file name.
|
|
18
|
+
*/
|
|
19
|
+
function getTypeScriptFileBaseName(openapiTypesFileName: string) {
|
|
20
|
+
return openapiTypesFileName.replace(getTsExtensionRegexp(), '');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Check if the file name is a valid TypeScript file name.
|
|
25
|
+
* Eg: `schema.d.ts`, `schema.ts`
|
|
26
|
+
*/
|
|
27
|
+
export function isValidTypeScriptFileName(fileName: string) {
|
|
28
|
+
return getTsExtensionRegexp().test(fileName);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function getTsExtensionRegexp() {
|
|
32
|
+
return /\.(d\.)?ts$/;
|
|
33
|
+
}
|
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { fileHeader } from '@openapi-qraft/plugin/lib/fileHeader';
|
|
2
|
+
import { formatFileHeader } from '@openapi-qraft/plugin/lib/formatFileHeader';
|
|
3
|
+
import { QraftCommandPlugin } from '@openapi-qraft/plugin/lib/QraftCommandPlugin';
|
|
4
|
+
|
|
5
|
+
import { CommanderError } from 'commander';
|
|
6
|
+
|
|
7
|
+
import { generateSchemaTypes } from './generateSchemaTypes.js';
|
|
8
|
+
import {
|
|
9
|
+
createOpenapiTypesImportPath,
|
|
10
|
+
isValidTypeScriptFileName,
|
|
11
|
+
} from './lib/createOpenapiTypesImportPath.js';
|
|
12
|
+
|
|
13
|
+
export const plugin: QraftCommandPlugin = {
|
|
14
|
+
setupCommand(command) {
|
|
15
|
+
command
|
|
16
|
+
.description(
|
|
17
|
+
'Generate TypeScript types from OpenAPI 3.x Document. Based on "openapi-typescript" (https://github.com/drwpow/openapi-typescript/)'
|
|
18
|
+
)
|
|
19
|
+
.option(
|
|
20
|
+
'--openapi-types-file-name <path>',
|
|
21
|
+
'OpenAPI Schema types file name, eg: "schema.d.ts"',
|
|
22
|
+
openapiTypesFileNameOptionParser,
|
|
23
|
+
'schema.ts'
|
|
24
|
+
)
|
|
25
|
+
.option('--enum', 'Export true TS enums instead of unions')
|
|
26
|
+
.option(
|
|
27
|
+
'-t, --export-type',
|
|
28
|
+
'Export top-level `type` instead of `interface`'
|
|
29
|
+
)
|
|
30
|
+
.option('--immutable', 'Generate readonly types')
|
|
31
|
+
.option(
|
|
32
|
+
'--additional-properties',
|
|
33
|
+
'Treat schema objects as if `additionalProperties: true` is set'
|
|
34
|
+
)
|
|
35
|
+
.option(
|
|
36
|
+
'--empty-objects-unknown',
|
|
37
|
+
'Generate `unknown` instead of `Record<string, never>` for empty objects'
|
|
38
|
+
)
|
|
39
|
+
.option(
|
|
40
|
+
'--default-non-nullable',
|
|
41
|
+
'Set to `false` to ignore default values when generating non-nullable types'
|
|
42
|
+
)
|
|
43
|
+
.option(
|
|
44
|
+
'--properties-required-by-default',
|
|
45
|
+
'Treat schema objects as if `required` is set to all properties by default'
|
|
46
|
+
)
|
|
47
|
+
.option(
|
|
48
|
+
'--array-length',
|
|
49
|
+
'Generate tuples using array minItems / maxItems'
|
|
50
|
+
)
|
|
51
|
+
.option(
|
|
52
|
+
'--path-params-as-types',
|
|
53
|
+
'Convert paths to template literal types'
|
|
54
|
+
)
|
|
55
|
+
.option('--alphabetize', 'Sort object keys alphabetically')
|
|
56
|
+
.option('--exclude-deprecated', 'Exclude deprecated types')
|
|
57
|
+
.option(
|
|
58
|
+
'--no-blob-from-binary',
|
|
59
|
+
'If this option is enabled, binary format fields will not be converted to Blob types, preserving the native representation'
|
|
60
|
+
)
|
|
61
|
+
.action(async ({ output, args, spinner, schema }, resolve) => {
|
|
62
|
+
spinner.text = 'Generating OpenAPI Document Types';
|
|
63
|
+
|
|
64
|
+
const code = await generateSchemaTypes(schema, {
|
|
65
|
+
args,
|
|
66
|
+
silent: true,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
spinner.succeed('OpenAPI Document types generated');
|
|
70
|
+
|
|
71
|
+
resolve([
|
|
72
|
+
{
|
|
73
|
+
file: new URL(args.openapiTypesFileName, output.dir),
|
|
74
|
+
code: formatFileHeader(args.fileHeader ?? fileHeader) + code,
|
|
75
|
+
},
|
|
76
|
+
]);
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
postSetupCommand(command, plugins) {
|
|
80
|
+
if (!plugins.includes('tanstack-query-react')) return;
|
|
81
|
+
|
|
82
|
+
// Makes `--openapi-types-import-path` option to be optional
|
|
83
|
+
command.options
|
|
84
|
+
.find((option) => option.attributeName() === 'openapiTypesImportPath')
|
|
85
|
+
?.makeOptionMandatory(false);
|
|
86
|
+
|
|
87
|
+
// Highlight the `--export-openapi-types` option default value
|
|
88
|
+
command.options
|
|
89
|
+
.find((option) => {
|
|
90
|
+
return option.attributeName() === 'exportOpenapiTypes';
|
|
91
|
+
})
|
|
92
|
+
?.default(true);
|
|
93
|
+
|
|
94
|
+
command.hook('preAction', (thisCommand) => {
|
|
95
|
+
// Do not override if a custom value already exists
|
|
96
|
+
if (!command.getOptionValue('openapiTypesImportPath')) {
|
|
97
|
+
thisCommand.setOptionValue(
|
|
98
|
+
'openapiTypesImportPath',
|
|
99
|
+
createOpenapiTypesImportPath(
|
|
100
|
+
thisCommand.getOptionValue('openapiTypesFileName'),
|
|
101
|
+
thisCommand.getOptionValue('explicitImportExtensions')
|
|
102
|
+
)
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// If the option is not set, set it to true
|
|
107
|
+
if (command.getOptionValue('exportOpenapiTypes') === undefined) {
|
|
108
|
+
thisCommand.setOptionValue('exportOpenapiTypes', true);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export function openapiTypesFileNameOptionParser(value: string) {
|
|
115
|
+
if (!isValidTypeScriptFileName(value)) {
|
|
116
|
+
throw new CommanderError(
|
|
117
|
+
1,
|
|
118
|
+
'ERR_INVALID_SCHEMA_FILE_NAME',
|
|
119
|
+
'OpenAPI Schema types file name must end with ".ts" or ".d.ts"'
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (value.includes('/') || value.includes('\\')) {
|
|
124
|
+
throw new CommanderError(
|
|
125
|
+
1,
|
|
126
|
+
'ERR_INVALID_SCHEMA_FILE_NAME',
|
|
127
|
+
'OpenAPI Schema types file name must not include path'
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (value.startsWith('.')) {
|
|
132
|
+
throw new CommanderError(
|
|
133
|
+
1,
|
|
134
|
+
'ERR_INVALID_SCHEMA_FILE_NAME',
|
|
135
|
+
'OpenAPI Schema types file name must not start with "."'
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return value;
|
|
140
|
+
}
|