@openapi-qraft/openapi-typescript-plugin 1.2.12 → 1.2.13
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 +7 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +8 -7
- package/dist/plugin.js.map +1 -1
- package/package.json +4 -3
- package/src/plugin.ts +8 -7
package/CHANGELOG.md
CHANGED
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;AASlF,eAAO,MAAM,MAAM,EAAE,kBA2IpB,CAAC;AAEF,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,MAAM,UA0B7D"}
|
package/dist/plugin.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { fileHeader } from '@openapi-qraft/plugin/lib/fileHeader';
|
|
2
2
|
import { formatFileHeader } from '@openapi-qraft/plugin/lib/formatFileHeader';
|
|
3
|
+
import c from 'ansi-colors';
|
|
3
4
|
import { CommanderError } from 'commander';
|
|
4
5
|
import { generateSchemaTypes } from './generateSchemaTypes.js';
|
|
5
6
|
import { createOpenapiTypesImportPath, isValidTypeScriptFileName, } from './lib/createOpenapiTypesImportPath.js';
|
|
6
7
|
export const plugin = {
|
|
7
8
|
setupCommand(command) {
|
|
8
9
|
command
|
|
9
|
-
.description('Generate
|
|
10
|
-
.option('--openapi-types-file-name <path>', 'OpenAPI Schema types file name,
|
|
10
|
+
.description('Generate a type-safe TanStack Query client for React from an OpenAPI Document.')
|
|
11
|
+
.option('--openapi-types-file-name <path>', 'OpenAPI Schema types file name, e.g.: "schema.d.ts"', openapiTypesFileNameOptionParser, 'schema.ts')
|
|
11
12
|
.option('--enum', 'Export true TS enums instead of unions')
|
|
12
13
|
.option('--enum-values', 'Export enum values as arrays.')
|
|
13
14
|
.option('--dedupe-enums', 'Dedupe enum types when `--enum` is set')
|
|
@@ -24,12 +25,12 @@ export const plugin = {
|
|
|
24
25
|
.option('--no-blob-from-binary', 'If this option is enabled, binary format fields will not be converted to Blob types, preserving the native representation')
|
|
25
26
|
.option('--explicit-component-exports', 'Enabling this option will export API components as separate type aliases, alongside `components` interface')
|
|
26
27
|
.action(async ({ output, args, spinner, schema }, resolve) => {
|
|
27
|
-
spinner.text = 'Generating OpenAPI Document Types';
|
|
28
|
+
spinner.text = 'Generating OpenAPI Document Types...';
|
|
28
29
|
const code = await generateSchemaTypes(schema, {
|
|
29
30
|
args,
|
|
30
31
|
silent: true,
|
|
31
32
|
});
|
|
32
|
-
spinner.succeed('OpenAPI Document types generated');
|
|
33
|
+
spinner.succeed(c.green('OpenAPI Document types generated'));
|
|
33
34
|
resolve([
|
|
34
35
|
{
|
|
35
36
|
file: new URL(args.openapiTypesFileName, output.dir),
|
|
@@ -41,7 +42,7 @@ export const plugin = {
|
|
|
41
42
|
postSetupCommand(command, plugins) {
|
|
42
43
|
if (!plugins.includes('tanstack-query-react'))
|
|
43
44
|
return;
|
|
44
|
-
// Makes `--openapi-types-import-path` option
|
|
45
|
+
// Makes the `--openapi-types-import-path` option optional
|
|
45
46
|
command.options
|
|
46
47
|
.find((option) => option.attributeName() === 'openapiTypesImportPath')
|
|
47
48
|
?.makeOptionMandatory(false);
|
|
@@ -62,14 +63,14 @@ export const plugin = {
|
|
|
62
63
|
thisCommand.setOptionValue('openapiTypesImportPath', createOpenapiTypesImportPath(openapiTypesFileName, thisCommand.getOptionValue('explicitImportExtensions')));
|
|
63
64
|
}
|
|
64
65
|
const openapiTypesImportPath = thisCommand.getOptionValue('openapiTypesImportPath');
|
|
65
|
-
// Validate
|
|
66
|
+
// Validate whether `--openapi-types-file-name` has the correct file extension
|
|
66
67
|
if (thisCommand.getOptionValue('explicitImportExtensions') &&
|
|
67
68
|
thisCommand
|
|
68
69
|
.getOptionValue('openapiTypesFileName')
|
|
69
70
|
?.endsWith?.('.d.ts') &&
|
|
70
71
|
openapiTypesImportPath &&
|
|
71
72
|
!openapiTypesImportPath?.endsWith?.('.d.ts')) {
|
|
72
|
-
throw new CommanderError(1, 'ERR_INVALID_OPENAPI_TYPES_FILE_NAME', "When '--explicit-import-extensions' is set, the '--openapi-types-file-name' must end with '.ts'
|
|
73
|
+
throw new CommanderError(1, 'ERR_INVALID_OPENAPI_TYPES_FILE_NAME', "When the '--explicit-import-extensions' option is set, either the '--openapi-types-file-name' must end with '.ts' or you must explicitly set '--openapi-types-import-path' to include '.d.ts'");
|
|
73
74
|
}
|
|
74
75
|
// If the option is not set, set it to true
|
|
75
76
|
if (command.getOptionValue('exportOpenapiTypes') === undefined) {
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAE9E,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EACL,4BAA4B,EAC5B,yBAAyB,GAC1B,MAAM,uCAAuC,CAAC;AAE/C,MAAM,CAAC,MAAM,MAAM,GAAuB;IACxC,YAAY,CAAC,OAAO;QAClB,OAAO;aACJ,WAAW,CACV,
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAClE,OAAO,EAA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,CACtB,CAAC,EACD,8BAA8B,EAC9B,sDAAsD,CACvD,CAAC;IACJ,CAAC;IAED,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,cAAc,CACtB,CAAC,EACD,8BAA8B,EAC9B,wDAAwD,CACzD,CAAC;IACJ,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openapi-qraft/openapi-typescript-plugin",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc --project tsconfig.build.json",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@openapi-qraft/plugin": "^2.
|
|
37
|
+
"@openapi-qraft/plugin": "^2.4.0",
|
|
38
38
|
"openapi-typescript": "^7.4.0",
|
|
39
39
|
"typescript": "^5.6.2"
|
|
40
40
|
},
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@redocly/openapi-core": "^1.16.0",
|
|
52
|
+
"ansi-colors": "^4.1.3",
|
|
52
53
|
"commander": "^11.1.0"
|
|
53
54
|
},
|
|
54
55
|
"peerDependenciesMeta": {
|
|
@@ -69,6 +70,6 @@
|
|
|
69
70
|
"repository": {
|
|
70
71
|
"type": "git",
|
|
71
72
|
"url": "git+https://github.com/OpenAPI-Qraft/openapi-qraft.git",
|
|
72
|
-
"directory": "packages/
|
|
73
|
+
"directory": "packages/openapi-typescript-plugin"
|
|
73
74
|
}
|
|
74
75
|
}
|
package/src/plugin.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { fileHeader } from '@openapi-qraft/plugin/lib/fileHeader';
|
|
2
2
|
import { formatFileHeader } from '@openapi-qraft/plugin/lib/formatFileHeader';
|
|
3
3
|
import { QraftCommandPlugin } from '@openapi-qraft/plugin/lib/QraftCommandPlugin';
|
|
4
|
+
import c from 'ansi-colors';
|
|
4
5
|
import { CommanderError } from 'commander';
|
|
5
6
|
import { generateSchemaTypes } from './generateSchemaTypes.js';
|
|
6
7
|
import {
|
|
@@ -12,11 +13,11 @@ export const plugin: QraftCommandPlugin = {
|
|
|
12
13
|
setupCommand(command) {
|
|
13
14
|
command
|
|
14
15
|
.description(
|
|
15
|
-
'Generate
|
|
16
|
+
'Generate a type-safe TanStack Query client for React from an OpenAPI Document.'
|
|
16
17
|
)
|
|
17
18
|
.option(
|
|
18
19
|
'--openapi-types-file-name <path>',
|
|
19
|
-
'OpenAPI Schema types file name,
|
|
20
|
+
'OpenAPI Schema types file name, e.g.: "schema.d.ts"',
|
|
20
21
|
openapiTypesFileNameOptionParser,
|
|
21
22
|
'schema.ts'
|
|
22
23
|
)
|
|
@@ -63,14 +64,14 @@ export const plugin: QraftCommandPlugin = {
|
|
|
63
64
|
'Enabling this option will export API components as separate type aliases, alongside `components` interface'
|
|
64
65
|
)
|
|
65
66
|
.action(async ({ output, args, spinner, schema }, resolve) => {
|
|
66
|
-
spinner.text = 'Generating OpenAPI Document Types';
|
|
67
|
+
spinner.text = 'Generating OpenAPI Document Types...';
|
|
67
68
|
|
|
68
69
|
const code = await generateSchemaTypes(schema, {
|
|
69
70
|
args,
|
|
70
71
|
silent: true,
|
|
71
72
|
});
|
|
72
73
|
|
|
73
|
-
spinner.succeed('OpenAPI Document types generated');
|
|
74
|
+
spinner.succeed(c.green('OpenAPI Document types generated'));
|
|
74
75
|
|
|
75
76
|
resolve([
|
|
76
77
|
{
|
|
@@ -83,7 +84,7 @@ export const plugin: QraftCommandPlugin = {
|
|
|
83
84
|
postSetupCommand(command, plugins) {
|
|
84
85
|
if (!plugins.includes('tanstack-query-react')) return;
|
|
85
86
|
|
|
86
|
-
// Makes `--openapi-types-import-path` option
|
|
87
|
+
// Makes the `--openapi-types-import-path` option optional
|
|
87
88
|
command.options
|
|
88
89
|
.find((option) => option.attributeName() === 'openapiTypesImportPath')
|
|
89
90
|
?.makeOptionMandatory(false);
|
|
@@ -125,7 +126,7 @@ export const plugin: QraftCommandPlugin = {
|
|
|
125
126
|
'openapiTypesImportPath'
|
|
126
127
|
);
|
|
127
128
|
|
|
128
|
-
// Validate
|
|
129
|
+
// Validate whether `--openapi-types-file-name` has the correct file extension
|
|
129
130
|
if (
|
|
130
131
|
thisCommand.getOptionValue('explicitImportExtensions') &&
|
|
131
132
|
thisCommand
|
|
@@ -137,7 +138,7 @@ export const plugin: QraftCommandPlugin = {
|
|
|
137
138
|
throw new CommanderError(
|
|
138
139
|
1,
|
|
139
140
|
'ERR_INVALID_OPENAPI_TYPES_FILE_NAME',
|
|
140
|
-
"When '--explicit-import-extensions' is set, the '--openapi-types-file-name' must end with '.ts'
|
|
141
|
+
"When the '--explicit-import-extensions' option is set, either the '--openapi-types-file-name' must end with '.ts' or you must explicitly set '--openapi-types-import-path' to include '.d.ts'"
|
|
141
142
|
);
|
|
142
143
|
}
|
|
143
144
|
|